graph_tool.topology.random_shortest_path#
- graph_tool.topology.random_shortest_path(g, source, target, dist_map=None, pred_map=None, all_preds_map=None, epsilon=1e-08, nsamples=1, iterator=False, **kwargs)[source]#
Return a random shortest path from source to target, uniformly sampled from all paths of equal length.
- Parameters:
- g
Graph Graph to be used.
- source
Vertex Source vertex of the search.
- target
Vertex Target vertex of the search.
- dist_map
VertexPropertyMap(optional, default:None) Vertex property map with the distances from
sourceto all other vertices.- pred_map
VertexPropertyMap(optional, default:None) Vertex property map with the predecessors in the search tree. If this is provided, the shortest paths are not computed, and are obtained directly from this map.
- all_preds_map
VertexPropertyMap(optional, default:None) Vector-valued vertex property map with all possible predecessors in the search tree. If this is provided, the shortest paths are obtained directly from this map.
- epsilon
float(optional, default:1e-8) Maximum relative difference between distances to be considered “equal”, in case floating-point weights are used.
- nsamples
int(optional, default:1) Number of paths to sample.
- iterator
bool(optional, default:False) If
True, an iterator is returned.- **kwargsKeyword parameter list
The remaining parameters will be passed to
shortest_path().
- g
- Returns:
- path
numpy.ndarray, or list ofnumpy.ndarrayor iterator overnumpy.ndarray Sequence of vertices from source to target in the shortest path. If
nsamples > 1a list (or iterator) over paths is returned.
- path
Notes
The paths are computed in the same manner as in
shortest_path(), which is used internally.If both
dist_mapandpred_mapare provided, theshortest_path()is not called.Examples
>>> g = gt.collection.data["pgp-strong-2009"] >>> path = gt.random_shortest_path(g, 92, 45) >>> print(path) [ 92 89 94 5877 5879 34 45]