networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturnsBackRef
all_shortest_paths(G, source, target, weight=None, method='dijkstra')

Notes

There may be many shortest paths between the source and target. If G contains zero-weight cycles, this function will not produce all shortest paths because doing so would produce infinitely many paths of unbounded length -- instead, we only produce the shortest simple paths.

Parameters

G : NetworkX graph
source : node

Starting node for path.

target : node

Ending node for path.

weight : None, string or function, optional (default = None)

If None, every edge has weight/distance/cost 1. If a string, use this edge attribute as the edge weight. Any edge attribute not present defaults to 1. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number.

method : string, optional (default = 'dijkstra')

The algorithm to use to compute the path lengths. Supported options: 'dijkstra', 'bellman-ford'. Other inputs produce a ValueError. If :None:None:`weight` is None, unweighted graph methods are used, and this suggestion is ignored.

Raises

ValueError

If :None:None:`method` is not among the supported options.

NetworkXNoPath

If :None:None:`target` cannot be reached from :None:None:`source`.

Returns

paths : generator of lists

A generator of all paths between source and target.

Compute all shortest simple paths in the graph.

See Also

all_pairs_shortest_path
shortest_path
single_source_shortest_path

Examples

>>> G = nx.Graph()
... nx.add_path(G, [0, 1, 2])
... nx.add_path(G, [0, 10, 2])
... print([p for p in nx.all_shortest_paths(G, source=0, target=2)]) [[0, 1, 2], [0, 10, 2]]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.simple_paths.all_simple_edge_paths networkx.algorithms.shortest_paths.generic.all_shortest_paths networkx.algorithms.simple_paths.all_simple_paths networkx.algorithms.simple_paths.shortest_simple_paths networkx.algorithms.shortest_paths.generic._build_paths_from_predecessors

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/shortest_paths/generic.py#427
type: <class 'function'>
Commit: