def bfs_beam_edges(G, source, value, width=None):
 if (width is None):
  width = len(G)
 def successors(v):
  'Returns a list of the best neighbors of a node.\n\n        `v` is a node in the graph `G`.\n\n        The "best" neighbors are chosen according to the `value`\n        function (higher is better). Only the `width` best neighbors of\n        `v` are returned.\n\n        The list returned by this function is in decreasing value as\n        measured by the `value` function.\n\n        '
  return iter(sorted(G.neighbors(v), key=value, reverse=True)[:width])
 for e in generic_bfs_edges(G, source, successors):
  (yield e)

def bfs_beam_edges ( G , source , value , width = None ) : if ( width is None ) : width = len ( G ) def successors ( v ) : return iter ( sorted ( G . neighbors ( v ) , key = value , reverse = True ) [ : width ] ) for e in generic_bfs_edges ( G , source , successors ) : ( yield e )
iterates over edges in a beam search .