label_biconnected_components

label_biconnected_components#

graph_tool.structure.label_biconnected_components(g, eprop=None, vprop=None)[git][source]#

Label the edges of biconnected components, and the vertices which are articulation points.

An edge property map with the component labels is returned, together with a boolean vertex map marking the articulation points, and a histogram of component labels.

Parameters:
gGraph

Graph to be used.

epropEdgePropertyMap (optional, default: None)

Edge property to label the biconnected components.

vpropVertexPropertyMap (optional, default: None)

Vertex property to mark the articulation points. If none is supplied, one is created.

Returns:
bicompEdgePropertyMap

Edge property map with the biconnected component labels.

articulationVertexPropertyMap

Boolean vertex property map which has value 1 for each vertex which is an articulation point, and zero otherwise.

histnumpy.ndarray

Histogram of biconnected component labels.

See also

label_components

Connected components

find_bridges

Bridges of a graph

chain_decomposition

Chain decomposition of a graph

Notes

A connected graph is biconnected if the removal of any single vertex (and all edges incident on that vertex) can not disconnect the graph. More generally, the biconnected components of a graph are the maximal subsets of vertices such that the removal of a vertex from a particular component will not disconnect the component. Unlike connected components, vertices may belong to multiple biconnected components: those vertices that belong to more than one biconnected component are called “articulation points” or, equivalently, “cut vertices”. Articulation points are vertices whose removal would increase the number of connected components in the graph. Thus, a graph without articulation points is biconnected. Vertices can be present in multiple biconnected components, but each edge can only be contained in a single biconnected component.

The algorithm runs in \(O(V + E)\) time.

Examples

>>> g = gt.random_graph(100, lambda: poisson(2), directed=False)
>>> comp, art, hist = gt.label_biconnected_components(g)
>>> print(comp.a)
[31 31 31  0 31 31 31 31 31 15 27 31 28 31 31 14 31 31 31 31  3 31 31 31
 32 31 31 19 16 29 20 31 31 31 31 31 31 31 31 31 31 31 31 10 24 31  4  8
 22 31 31 31 31  2 31 31 31 31 31 18 31 31 31 31 31 11 21 23  1 31 31 30
  7 31 31 31 25 31 31 31 31 31 31  6 26 17 31 31 31 13 31 31 31 12  9 31
 31 31 31  5 31 31 31]
>>> print(art.a)
[1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 0 0 0
 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 0
 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0]
>>> print(hist)
[ 1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
  1  1  1  1  1  1  1 71  1]

The largest biconnected component and the articulation points can be shown in a drawing of the graph:

>>> pos = gt.sfdp_layout(g)
>>> vcolor = g.new_vp("string", vals=np.where(art.a, "#9bbedc",
...                                           "#cccccc"))
>>> big = comp.a == hist.argmax()
>>> ecolor = g.new_ep("string", vals=np.where(big, "#e41a1c", "#999999"))
>>> ewidth = g.new_ep("double", vals=np.where(big, 2, 1))
>>> gt.graph_draw(g, pos, vertex_fill_color=vcolor, edge_color=ecolor,
...               edge_pen_width=ewidth,
...               output="label_biconnected_components-random.pdf")
<...>
../_images/label_biconnected_components-random.png

Biconnected components of a sparse random graph. The edges of the largest biconnected component are shown in red, and the articulation points in blue.#