def dijkstra_path(G, source, target, get_weight):
"""Returns the shortest path from source to target in a weighted graph G"""
(length, path) = single_source_dijkstra(G, source, target, get_weight)
try:
return path[target]
except KeyError:
raise nx.NetworkXNoPath(
"node %s not reachable from %s" % (source, target))
评论列表
文章目录