def get_stats_and_update_occupancy(CG, sorted_nodes, tfile) :
"""
Update the occupancy in the Graph and the total simulation time
"""
# http://www.regular-expressions.info/floatingpoint.html
reg_flt = re.compile('[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?.')
lastlines = s.check_output(['tail', '-2', tfile]).strip().split("\n")
if not reg_flt.match(lastlines[0]):
raise ValueError('Cannot parse simulation output', tfile)
else :
time = float(lastlines[0].split()[0])
iterations = int(lastlines[-1].split()[-1])
tot_occ =sum(map(float, lastlines[0].split()[1:]))
for e, occu in enumerate(lastlines[0].split()[1:]) :
ss = sorted_nodes[e][0]
CG.node[ss]['occupancy'] = float(occu)/tot_occ
return time, iterations
评论列表
文章目录