all_pairs_vertex_connectivity

all_pairs_vertex_connectivity#

graph_tool.flow.all_pairs_vertex_connectivity(g, vs=None, approx=False)[git][source]#

Compute the number of internally vertex-disjoint paths between all pairs of vertices.

Parameters:
gGraph

Graph to be used.

vsiterable of Vertex (optional, default: None)

If given, only the pairs of these vertices are considered.

approxbool (optional, default: False)

If True, a fast lower bound is computed instead of the exact values (see below).

Returns:
kappanumpy.ndarray

Matrix with the number of paths from vs[i] to vs[j] (or between vertices i and j, if vs is not given) at position [i, j], and zeros on the diagonal.

See also

vertex_connectivity

Vertex connectivity

average_vertex_connectivity

Average vertex connectivity

Notes

The maximum number \(\kappa(s,t)\) of paths from \(s\) to \(t\) that share no vertices other than these two is, by Menger’s theorem, the local vertex connectivity of a non-adjacent pair (see vertex_connectivity()); if \(s\) and \(t\) are adjacent, the direct edge counts as one path. It is computed for each pair as a maximum flow with unit capacities, as in vertex_connectivity(), which stops at \(\min(k^{\text{out}}_s, k^{\text{in}}_t)\), and is skipped for vertices in different components, in time \(O(\kappa(s,t)E)\), so that the total is \(O(\bar\kappa V^2 E)\). The pairs are processed in parallel.

If approx == True, the lower bound of White and Newman [white-fast-2001] is used instead, which finds a shortest path between \(s\) and \(t\) with a bidirectional breadth-first search, removes its internal vertices, and repeats until no path remains. Since each search is typically much cheaper than a full breadth-first search, this is much faster than the maximum flow, and often exact, but it may miss paths, since the shortest paths chosen early may block several others. This is offered as an option rather than as a separate function, since it estimates the same quantity with the same interface; the same holds for vertex_connectivity() and average_vertex_connectivity().

Parallel edges and self-loops are ignored.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

References

[white-fast-2001]

Douglas R. White and Mark E. J. Newman, “Fast approximation algorithms for finding node-independent paths in networks”, Santa Fe Institute Working Paper 01-07-035 (2001), DOI: 10.2139/ssrn.1831790 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> kappa = gt.all_pairs_vertex_connectivity(g)
>>> print(kappa[0, :8])
[0 9 8 6 3 3 3 4]
>>> akappa = gt.all_pairs_vertex_connectivity(g, approx=True)
>>> print((akappa != kappa).sum(), kappa.size)
22 1156