def progressive_widening_search(G, source, value, condition, initial_width=1):
 if condition(source):
  return source
 log_m = math.ceil(math.log(len(G), 2))
 for i in range(log_m):
  width = (initial_width * pow(2, i))
  for (u, v) in nx.bfs_beam_edges(G, source, value, width):
   if condition(v):
    return v
 raise nx.NodeNotFound('no node satisfied the termination condition')

def progressive_widening_search ( G , source , value , condition , initial_width = 1 ) : if condition ( source ) : return source log_m = math . ceil ( math . log ( len ( G ) , 2 ) ) for i in range ( log_m ) : width = ( initial_width * pow ( 2 , i ) ) for ( u , v ) in nx . bfs_beam_edges ( G , source , value , width ) : if condition ( v ) : return v raise nx . NodeNotFound ( 'no node satisfied the termination condition' )
progressive widening beam search to find a node .