treewidth

Contents

treewidth#

graph_tool.structure.treewidth(g, method='min_fill', order=False)[git][source]#

Return an upper bound on the treewidth of an undirected graph.

Parameters:
gGraph

Undirected graph to be used.

methodstr (optional, default: "min_fill")

Elimination heuristic: "min_fill" (minimum fill-in) or "min_degree" (minimum degree).

orderbool (optional, default: False)

If True, the elimination order is also returned.

Returns:
widthint

An upper bound on the treewidth.

ordernumpy.ndarray

The elimination order of the vertices, which defines a tree decomposition of the given width. Only returned if order == True.

See also

junction_tree

Tree decomposition of a graph

chordal_completion

Minimal chordal completion

vertex_ordering

Orderings that reduce the bandwidth

Notes

A tree decomposition of a graph is a tree whose nodes are sets of vertices (bags), such that every vertex belongs to some bag, both endpoints of every edge belong to some bag, and the bags that contain any given vertex form a connected subtree. Its width is the size of its largest bag minus one, and the treewidth of the graph is the smallest width of its tree decompositions.

Computing the treewidth is NP-hard. The heuristics eliminate the vertices one at a time, connecting all the remaining neighbors of the eliminated vertex to each other, and choose the vertex of smallest remaining degree, or the one whose elimination adds the fewest edges [bodlaender-treewidth-2010]. The largest number of remaining neighbors at elimination is the width of the corresponding tree decomposition, and hence an upper bound on the treewidth. The minimum fill-in heuristic usually gives smaller bounds, but is slower.

References

[bodlaender-treewidth-2010]

Hans L. Bodlaender and Arie M. C. A. Koster, “Treewidth computations I. Upper bounds”, Information and Computation 208, 259-275 (2010), DOI: 10.1016/j.ic.2009.03.008 [sci-hub, @tor]

Examples

>>> g = gt.lattice([5, 5])
>>> print(gt.treewidth(g), gt.treewidth(g, "min_degree"))
5 5