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.

Parameters:

G : NetworkX graph, weighted

source : node label

starting node for path

target : node label

ending node for path

Returns:

length : number

Shortest path length.

Raises:

NetworkXError :

If no path exists between source and target.

Notes

Edge weight attributes must be numerical.

Examples

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