NetworkX

Previous topic

networkx.shortest_path_length

Next topic

networkx.single_source_shortest_path_length

networkx.single_source_shortest_path

single_source_shortest_path(G, source, cutoff=None)

Return list of nodes in a shortest path between source and all other nodes reachable from source.

There may be more than one shortest path between the source and target nodes - this routine returns only one.

Returns a dictionary of shortest path lengths keyed by target.

Parameters:

G : NetworkX graph

source : node label

starting node for path

cutoff : integer, optional

depth to stop the search - only paths of length <= cutoff are returned.

See also

shortest_path

Examples

>>> G=nx.path_graph(5)
>>> path=nx.single_source_shortest_path(G,0)
>>> path[4]
[0, 1, 2, 3, 4]