chain_decomposition#
- graph_tool.structure.chain_decomposition(g, root=None)[git][source]#
Return the chain decomposition of a graph.
- Parameters:
- Returns:
- chains
listofnumpy.ndarray The vertices of every chain, in order; a chain that is a cycle repeats its first vertex at the end.
- chains
See also
find_bridgesBridges of a graph
label_biconnected_componentsBiconnected components and articulation points
Notes
After a depth-first search, for every vertex in the order of discovery and every back edge leaving it, a chain starts with the back edge and follows the tree edges upwards until it reaches a vertex already on a chain [schmidt-simple-2013]. The chains cover all edges that are not bridges; the graph is 2-edge-connected if they cover all edges, and 2-vertex-connected if, in addition, only the first chain is a cycle. The time is \(O(V + E)\).
References
[schmidt-simple-2013]Jens M. Schmidt, “A simple test on 2-vertex- and 2-edge-connectivity”, Information Processing Letters 113, 241-244 (2013), DOI: 10.1016/j.ipl.2013.01.016 [sci-hub, @tor]
Examples
>>> g = gt.Graph([(0, 1), (1, 2), (2, 0), (2, 3), (3, 4), (4, 2)], ... directed=False) >>> print(gt.chain_decomposition(g)) [array([0, 2, 1, 0], dtype=uint64), array([2, 4, 3, 2], dtype=uint64)]
The chains of a \(3\times 4\) lattice can be shown in a drawing:
>>> g = gt.lattice([3, 4]) >>> chains = gt.chain_decomposition(g) >>> palette = ["#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", ... "#a65628"] >>> ecolor = g.new_ep("string") >>> for c, color in zip(chains, palette): ... for u, v in zip(c[:-1], c[1:]): ... ecolor[g.edge(u, v)] = color >>> pos = g.new_vp("vector<double>", ... vals=[(i % 3, i // 3) for i in range(12)]) >>> gt.graph_draw(g, pos, vertex_fill_color="#cccccc", edge_color=ecolor, ... vertex_size=30, edge_pen_width=3, ... output="chain_decomposition-lattice.pdf") <...>
Chain decomposition of a \(3\times 4\) lattice, with the edges of every chain shown in a different color (red for the first chain, a cycle).#