NetworkX

Previous topic

networkx.single_source_shortest_path_length

Next topic

networkx.all_pairs_shortest_path_length

networkx.all_pairs_shortest_path

all_pairs_shortest_path(G, cutoff=None)

Return shortest paths between all nodes.

Returns a dictionary with keys for all reachable node pairs.

Parameters:

G : NetworkX graph

cutoff : integer, optional

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

See also

floyd_warshall

Examples

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