count_reachable#
- graph_tool.structure.count_reachable(g, mode='out')[git][source]#
Return the number of vertices reachable from every vertex.
- Parameters:
- g
Graph Graph to be used.
- mode
str(optional, default:"out") If
"out", the vertices reachable from every vertex are counted; if"in", those from which every vertex is reachable. Ignored for undirected graphs.
- g
- Returns:
- count
VertexPropertyMap The number of reachable vertices, including the vertex itself.
- count
See also
label_out_componentVertices reachable from a given vertex
transitive_closureTransitive closure of a graph
Notes
The strongly connected components are contracted with Tarjan’s algorithm [tarjan-depth-1972], which numbers them in reverse topological order, and the sets of components reachable from every component are propagated as bitsets in this order, in blocks of target components so that the memory used by the bitsets is bounded by about 128 MB. The blocks, or the words of the bitsets of a single block, are processed in parallel; since the memory bound is shared among the threads, fewer threads are used if the bitsets of every thread would become too short. The time is \(O(V + E + C(C + E_C)/64)\), where \(C\) and \(E_C\) are the numbers of components and of edges between them. For undirected graphs, the sizes of the connected components are returned, in time \(O(V + E)\).
References
[tarjan-depth-1972]Robert Tarjan, “Depth-first search and linear graph algorithms”, SIAM Journal on Computing 1, 146-160 (1972), DOI: 10.1137/0201010 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["celegansneural"] >>> c = gt.count_reachable(g) >>> print(c.a.min(), c.a.max()) 1 268