chordal_completion

chordal_completion#

graph_tool.structure.chordal_completion(g, order=False)[git][source]#

Return the edges of a minimal chordal completion of a graph.

Parameters:
gGraph

Graph to be used. Edge directions are ignored.

orderbool (optional, default: False)

If True, a perfect elimination ordering of the completed graph is also returned.

Returns:
fillnumpy.ndarray

Array of shape (k, 2) with the endpoints of the edges whose addition makes the graph chordal (see is_chordal()).

ordernumpy.ndarray

The vertices in a perfect elimination ordering of the completed graph. Only returned if order == True.

See also

is_chordal

Test for chordal graphs

treewidth

Upper bound on the treewidth

junction_tree

Junction 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")
<...>
../_images/chordal_completion-cycle.png

Minimal chordal completion of a cycle of six vertices. The edges of the cycle are shown in gray, and those added in red.#