NetworkX

Previous topic

networkx.dijkstra_path

Next topic

networkx.single_source_dijkstra_path

networkx.dijkstra_path_length

dijkstra_path_length(G, source, target)

Returns the shortest path length from source to target in a weighted graph G.

Raise an exception if no path exists.

Parameters:

G : NetworkX graph, weighted

source : node label

starting node for path

target : node label

ending node for path

Notes

Edge data must be numerical values for Graph and DiGraphs.

Examples

>>> G=nx.path_graph(5) # a weighted graph by default
>>> print nx.dijkstra_path_length(G,0,4)
4