chordal_completion#
- graph_tool.structure.chordal_completion(g, order=False)[git][source]#
Return the edges of a minimal chordal completion of a graph.
- Parameters:
- g
Graph Graph to be used. Edge directions are ignored.
- order
bool(optional, default:False) If
True, a perfect elimination ordering of the completed graph is also returned.
- g
- Returns:
- fill
numpy.ndarray Array of shape
(k, 2)with the endpoints of the edges whose addition makes the graph chordal (seeis_chordal()).- order
numpy.ndarray The vertices in a perfect elimination ordering of the completed graph. Only returned if
order == True.
- fill
See also
is_chordalTest for chordal graphs
treewidthUpper bound on the treewidth
junction_treeJunction tree of a graph
Notes
A chordal completion of a graph \(G = (V, E)\) is a set \(F\) of pairs of non-adjacent vertices such that \((V, E\cup F)\) is chordal. The completion is minimal, i.e. no proper subset of the added edges makes the graph chordal, but it need not have the smallest number of edges, which is an NP-hard problem. It is computed with the MCS-M algorithm [berry-maximum-2004], which numbers the vertices as maximum cardinality search does, but with weights that also count the vertices reachable through paths of unnumbered vertices of smaller weight, which are joined by the added edges. The algorithm runs in time \(O(VE)\).
References
[berry-maximum-2004]Anne Berry, Jean R. S. Blair, Pinar Heggernes and Barry W. Peyton, “Maximum cardinality search for computing minimal triangulations of graphs”, Algorithmica 39, 287-298 (2004), DOI: 10.1007/s00453-004-1084-3 [sci-hub, @tor]
Examples
>>> g = gt.circular_graph(6) >>> print(gt.chordal_completion(g)) [[1 5] [5 2] [2 4]]
The edges added can be shown in a drawing of the completed graph:
>>> fill = gt.chordal_completion(g) >>> g.add_edge_list(fill) >>> a = 2 * np.pi * np.arange(6) / 6 >>> pos = g.new_vp("vector<double>", vals=list(zip(np.cos(a), np.sin(a)))) >>> ecolor = g.new_ep("string", vals=["#999999"] * 6 + ... ["#e41a1c"] * len(fill)) >>> gt.graph_draw(g, pos, vertex_fill_color="#cccccc", edge_color=ecolor, ... vertex_size=30, edge_pen_width=2, ... output="chordal_completion-cycle.pdf") <...>
Minimal chordal completion of a cycle of six vertices. The edges of the cycle are shown in gray, and those added in red.#