def astar_path_length(G, source, target, heuristic=None, weight='weight'):
 if ((source not in G) or (target not in G)):
  msg = 'Either source {} or target {} is not in G'
  raise nx.NodeNotFound(msg.format(source, target))
 path = astar_path(G, source, target, heuristic, weight)
 return sum((G[u][v].get(weight, 1) for (u, v) in zip(path[:(-1)], path[1:])))

def astar_path_length ( G , source , target , heuristic = None , weight = 'weight' ) : if ( ( source not in G ) or ( target not in G ) ) : msg = 'Either source {} or target {} is not in G' raise nx . NodeNotFound ( msg . format ( source , target ) ) path = astar_path ( G , source , target , heuristic , weight ) return sum ( ( G [ u ] [ v ] . get ( weight , 1 ) for ( u , v ) in zip ( path [ : ( - 1 ) ] , path [ 1 : ] ) ) )
return the length of the shortest path between source and target using the a* algorithm .