all_paths#
- graph_tool.structure.all_paths(g, source, target, cutoff=None, edges=False, min_length=None)[git][source]#
Return an iterator over all paths from source to target.
- Parameters:
- g
Graph Graph to be used.
- source
Vertex Source vertex of the search.
- target
Vertex Target vertex of the search.
- cutoff
int(optional, default:None) Maximum path length.
- edges
bool(optional, default:False) If
True, the returned iterator is over edge descriptors.- min_length
int(optional, default:None) Minimum path length (number of edges).
- g
- Returns:
See also
k_shortest_pathsThe k shortest simple paths
all_shortest_pathsAll paths of minimum length
all_circuitsAll cycles of a directed graph
Notes
The algorithm uses a depth-first search to find all the paths.
The total number of paths between any two vertices can be quite large, possibly scaling as \(O(V!)\).
Examples
>>> g = gt.collection.data["football"] >>> for path in gt.all_paths(g, 13, 2, cutoff=2): ... print(path) [13 2] [13 15 2] [13 60 2] [13 64 2] [ 13 100 2] [ 13 106 2] >>> for path in gt.all_paths(g, 13, 2, cutoff=2, min_length=2): ... print(path) [13 15 2] [13 60 2] [13 64 2] [ 13 100 2] [ 13 106 2]