easygraph.functions.basic.predecessor_path_based module#
- easygraph.functions.basic.predecessor_path_based.predecessor(G, source, target=None, cutoff=None, return_seen=None)[source]#
Returns dict of predecessors for the path from source to all nodes in G.
- Parameters:
G (EasyGraph 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.
return_seen (bool, optional (default=None)) – Whether to return a dictionary, keyed by node, of the level (number of hops) to reach the node (as seen during breadth-first-search).
- Returns:
pred – Dictionary, keyed by node, of predecessors in the shortest path.
- Return type:
dictionary
- (pred, seen): tuple of dictionaries
If return_seen argument is set to True, then a tuple of dictionaries is returned. The first element is the dictionary, keyed by node, of predecessors in the shortest path. The second element is the dictionary, keyed by node, of the level (number of hops) to reach the node (as seen during breadth-first-search).
Examples
>>> G = eg.path_graph(4) >>> list(G) [0, 1, 2, 3] >>> eg.predecessor(G, 0) {0: [], 1: [0], 2: [1], 3: [2]} >>> eg.predecessor(G, 0, return_seen=True) ({0: [], 1: [0], 2: [1], 3: [2]}, {0: 0, 1: 1, 2: 2, 3: 3})