find_bridges#
- graph_tool.structure.find_bridges(g)[git][source]#
Return the bridges of a graph.
- Parameters:
- g
Graph Graph to be used. Edge directions are ignored.
- g
- Returns:
- bridges
EdgePropertyMap Boolean edge property map marking the bridges.
- bridges
See also
local_bridgesEdges whose endpoints share no neighbors
chain_decompositionChain decomposition of a graph
label_biconnected_componentsBiconnected components and articulation points
graph_tool.flow.label_bridge_componentsComponents without the bridges
Notes
A bridge is an edge whose removal disconnects its endpoints. Parallel edges are never bridges. The bridges are found with Tarjan’s low-link values in a depth-first search [tarjan-note-1974], in time \(O(V + E)\). Removing them leaves the 2-edge-connected components.
References
[tarjan-note-1974]Robert E. 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"] >>> print(gt.find_bridges(g).a.sum()) 1
The bridge can be highlighted in a drawing of the network:
>>> b = gt.find_bridges(g) >>> ecolor = g.new_ep("string", vals=np.where(b.a, "#e41a1c", "#999999")) >>> ewidth = g.new_ep("double", vals=np.where(b.a, 3, 1)) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color="#cccccc", ... edge_color=ecolor, edge_pen_width=ewidth, ... output="find_bridges-karate.pdf") <...>
Bridge of Zachary’s karate club network, shown in red.#