DrTransformer.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:ribolands 作者: bad-ants-fleet 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号