label_bridge_components

label_bridge_components#

graph_tool.flow.label_bridge_components(g, vprop=None)[git][source]#

Label the bridge components (2-edge-connected components) of the graph.

Parameters:
gGraph

Graph to be used. If it is directed, it is treated as undirected.

vpropVertexPropertyMap (optional, default: None)

Vertex property map of value type int32_t to store the component labels. If not supplied, one is created.

Returns:
compVertexPropertyMap

Vertex property map with the component labels.

histnumpy.ndarray

Histogram of component labels.

See also

label_k_edge_components

K-edge-connected components

graph_tool.structure.find_bridges

Bridges of the graph

graph_tool.structure.label_biconnected_components

Biconnected components

Notes

A bridge is an edge whose removal increases the number of connected components. Removing all bridges leaves the bridge components, which are the 2-edge-connected components, i.e. the maximal sets of vertices connected pairwise by two edge-disjoint paths (see label_k_edge_components()). Unlike the biconnected components (see label_biconnected_components()), they partition the vertices, and an isolated vertex, or one attached only by bridges, forms a component of its own.

The bridges are found with Tarjan’s depth-first search [tarjan-note-1974], which identifies the tree edge into a vertex as a bridge if no edge of its subtree reaches above it, in time \(O(V + E)\). Parallel edges are taken into account (an edge that is repeated is not a bridge), and self-loops are ignored.

References

[tarjan-note-1974]

Robert Endre Tarjan, “A note on finding the bridges of a graph”, Information Processing Letters 2, 160-161 (1974), DOI: 10.1016/0020-0190(74)90003-9 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> comp, hist = gt.label_bridge_components(g)
>>> print(hist)
[33  1]

In the network of social relations between dolphins, the bridges separate the largest bridge component from several smaller ones, which can be highlighted in a drawing:

>>> g = gt.collection.data["dolphins"]
>>> comp, hist = gt.label_bridge_components(g)
>>> big = hist.argmax()
>>> vcolor = g.new_vp("string", vals=np.where(comp.a == big, "#9bbedc",
...                                           "#cccccc"))
>>> cs = gt.edge_endpoint_property(g, comp, "source").a
>>> ct = gt.edge_endpoint_property(g, comp, "target").a
>>> bridge = cs != ct
>>> ecolor = g.new_ep("string", vals=np.where(bridge, "#e41a1c", "#999999"))
>>> ewidth = g.new_ep("double", vals=np.where(bridge, 3, 1))
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor, edge_color=ecolor,
...               edge_pen_width=ewidth,
...               output="label_bridge_components-dolphins.pdf")
<...>
../_images/label_bridge_components-dolphins.png

Bridge components of the network of social relations between dolphins. The vertices of the largest component are shown in blue, those of the other components in gray, and the bridges in red.#