NetworkX

Previous topic

networkx.dijkstra_predecessor_and_distance

Next topic

networkx.floyd_warshall

networkx.predecessor

predecessor(G, source, target=None, cutoff=None, return_seen=None)

Returns dictionary of predecessors for the path from source to all nodes in G.

Parameters:

G : NetworkX graph

source : node label

Starting node for path

target : node label, optional

Ending node for path. If provided only predecessors between source and target are returned

cutoff : integer, optional

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

Examples

>>> G=nx.path_graph(4)
>>> print G.nodes()
[0, 1, 2, 3]
>>> nx.predecessor(G,0)
{0: [], 1: [0], 2: [1], 3: [2]}