A Constraint Model for the Tree Decomposition of a Graph
AA Constraint Model for the Tree Decompositionof a Graph
Benjamin Bumpus − − − , Patrick Prosser − − − ,and James Trimble − − − School of Computing Science, University of Glasgow, Scotland
Abstract.
We present a constraint model for the problem of producinga tree decomposition of a graph. The inputs to the model are a simplegraph G, the number of nodes in the desired tree decomposition and themaximum cardinality of each node in that decomposition. Via a sequenceof decision problems, the model allows us to find the tree width of a graphwhilst delivering a tree decomposition of that width, i.e. a witness.
Keywords:
Tree Decomposition · Tree Width · Constraint Program-ming Model.
A tree decomposition of a graph is a mapping from vertices in a graph to nodes ina tree, where the tree nodes are subsets of the vertices of the graph. The purposeof this is to produce a tree-like strucure of the graph so that, whatever problemthat graph is representing, it can be solved node by node, with a complexitybounded by some function of the size of the nodes. Therefore it is a way ofdecomposing a problem. Finding a tree decomposition with minimum widthhas been the Holy Grail of the fixed parameter tractability research community[2,3,4] and has a long history in Constraint Programming, most notably due toRina Dechter [6,5,7], and more recently by Abseher et al [1].Our goal is to present what we believe to be the first Constraint Programming(CP) model for this problem. Our model takes as input a simple graph G andoutputs a tree decomposition of that graph, T, with a specified width ( w ) and aspecified number of nodes ( m ). If no such tree exists it returns false. In the nextsection we present the definition of tree decomposition and treewidth. We thenpresent our CP model, show it running and conclude. Given a simple graph G = (V,E) it may be decomposed into a tree T, where thetree is composed of m nodes, such that: a r X i v : . [ c s . D M ] A ug B. Bumpus et al.
1. A node N i is an improper subset of the vertices of V.2. The union of all the nodes in the tree is the set of vertices V.3. If edge (u,v) is in E then that pair of vertices will exist together in at leastone of the nodes of T.4. If vertex v is in node N i and the same vertex is in node N k then vertex vmust exist in all nodes in the path from N i to N k . This can also be expressedas: for any three nodes N i , N j and N k , if N j lies on the path from N i to N k then N i ∩ N k ⊆ N j . A third interpretation of this property is that for anyvertex v in V, the set of nodes that contain v induces a single subtree of T.Property (4) is sometimes refered to as the running intersection property . Con-ventionally, nodes of T are said to contain bags where a bag is a set of vertices.To avoid confusion, due to a bag being a synonym for a multi-set, we will saythat a node is a set of vertices.The width of a tree decompostion is the size of the largest node in that decom-position. The treewidth tw(G) is then the minimum width among all possibletree decompositions of G. Conventionally, treewidth is the minimum width mi-nus one. This is because a tree decomposition of a graph G that is itself a treewill have n − We assume that we are given a simple graph G with vertex set V and edge set E.There are n vertices in V and the tree decomposition has exactly m nodes, andeach node has cardinality no greater than w . We start by giving the constrainedvariables of the model, then we give the constraints. ∀ i ∈ [0 ..m − N i ⊆ { , . . . , n − } (1) ∀ i ∈ [0 ..m − parent i ∈ { , . . . , m − } (2) ∀ i ∈ [0 ..m − depth i ∈ { , . . . , m − } (3) ∀ ( u,v ) ∈ E,k ∈ [0 ..m − location u,v,k ∈ { , } (4) ∀ i,j ∈ [0 ..m − ,i Constraints 13 to 15 ensure that property (3) holds, i.e. that every edge is con-tained in at least one node of the tree. Constraint 13 allows us to use only thetop half of the matrix; because edges are undirected location u,v,k is exactly thesame variable as location v,u,k . Constraint 14 states that location u,v,k takes thevalue one if and only if the edge (u,v) is contained in the k th node of the tree,and constraint 15 insists that the edge (u,v) exists in at least one node. ∀ ( u,v ) ∈ E,k ∈ [0 ..m − location v,u,k ≡ location u,v,k (13) ∀ ( u,v ) ∈ E,k ∈ [0 ..m − location u,v,k = 1 ⇐⇒ { u, v } ⊆ N k (14) ∀ ( u,v ) ∈ E m − (cid:88) k =0 location u,v,k ≥ N i and N k that are at the same depth, or node N k is deeper in the tree than N i , then if we relax the property that the tree isrooted, then the parent of N k is on the path from N i to N k , and we insist thatevery vertex that is common to N i and N k , i.e. intersection i,k is subsumed bythe vertices in the parent node of N k , namely N parent k . ∀ i,k ∈ [0 ..m − ,i (cid:54) = j depth i ≤ depth k = ⇒ intersection i,k ⊆ N parent k (16) We have endeavoured to use only constraints that we should expect to see inany Constraint Programming toolkit. This is one of the reasons why we did notuse the tree constraint (such as [8]). In implementing our model, constraint 16required the use of the element constraint, where a constrained integer variableis used as an index into an array of constrained set variables. This is the mostsophisticated constraint in our model.The model was implemented in the choco4 CP toolkit [9]. The decision vari-ables were the parent variables combined with the flattened location variables.This was a convenience so that we could use library variable and value orderingheuristics, rather than have something more complex that allowed us to mixconstrained integer variables with constrained set variables.Simple symmetry breaking was added. The nodes were channelled to bitssets, such that bit set B i,j = 1 ⇐⇒ j ∈ N i . A lexicographical ordering wasthen posted between bit sets such that B i (cid:22) B i +1 . Finding the tree width of a graph is done as a sequence of decision problems.We can start with the number of nodes m in the tree to be equal to 1, and the Constraint Model for Tree Decomposition 5 width w = n . A single node tree is then found trivially. We then increment m and decrement w and repeat the process until w = 2 (in which case G is a tree)or failure is reported, and the previous values of m and w give us an optimal treedecomposition of minimum width w − 1. This process is sound and complete: Proof. Proposition: If T is a tree decomposition of m nodes and width w of graph G , with no duplicate nodes, then m ≤ n − w +1, where n is the number of verticesin G . By way of contradiction, suppose otherwise, then all tree decompositionsof G would require a tree with more than n − w + 1 nodes. But since we donot allow duplicate nodes, every node must contain one “unseen” vertex, hence n ≥ w + m − > w + ( n − w + 1) − n , and that is a contradiction. (cid:3) Fig. 1. Input graph in top right quandrant. Four tree decompositions. From top tobottom, m=3 and w = 6, m = 4 and w = 5, m = 5 and w = 4, m = 6 and w = 3. Lasttree decomposition, directed parent pointers are shown. In Figure 1 we show the results of this process on a graph with 8 vertices and13 edges. We show the tree decompositions for m = 3 and w = 6, and onwardsto the optimal decomposition m = 6 and w = 3. For m = 5 and w = 4 ourmodel required 2.4 seconds of resolution time and 7,388 decisions. For m = 6and w = 3 our model required 1.2 seconds of resolution time and 2,959 decisions.Optimality, the unsatisfiability of m = 7 and w = 2, is proved in 0.2 secondsand 197 decisions. B. Bumpus et al. We do not include detailed experimental comparisons with existing algo-rithms, but we observe that our model is orders of magnitude slower than state-of-the-art methods for tree decomposition. Rather than being of practical use asa solver, we present our model as a way of exploring and explaining tree widthto an interested user, and as a tool that could easily be extended to handleside constraints. It might be likened to an easily assembled and easily adaptedTinkertoy. We present what we believe to be the first CP model for tree decomposition ofa graph, with a process that allows us to determine the tree width of a graph.The model is simple, and we believe it can be readily encoded in most any CPmodelling languages. Our model, in its current form, is too slow to be of praticaluse, but it might have a place as a dynamic tool to help those who “want to getto know about tree width.” Our model is also adaptable. For example, we canfind the path width of a graph via a simple edit: ∀
1. M. Abseher, N. Musliu, and S. Woltran. htd - A free, open-source framework for(customized) tree decompositions and beyond. In Integration of AI and OR Tech-niques in Constraint Programming - 14th International Conference, CPAIOR 2017,Padua, Italy, June 5-8, 2017, Proceedings , pages 376–386, 2017.2. H. L. Bodlaender. A tourist guide through treewidth. Acta Cybern. , 11(1-2):1–21,1993.3. H. L. Bodlaender. A linear-time algorithm for finding tree-decompositions of smalltreewidth. SIAM J. Comput. , 25(6):1305–1317, 1996.4. H. L. Bodlaender, F. V. Fomin, A. M. C. A. Koster, D. Kratsch, and D. M. Thilikos.On exact algorithms for treewidth. ACM Trans. Algorithms , 9(1):12:1–12:23, 2012.5. R. Dechter. Enhancement schemes for constraint processing: Backjumping, learning,and cutset decomposition. Artif. Intell. , 41(3):273–312, 1990.6. R. Dechter and J. Pearl. Tree clustering for constraint networks. Artif. Intell. ,38(3):353–366, 1989.7. V. Gogate and R. Dechter. A complete anytime algorithm for treewidth. In UAI ’04,Proceedings of the 20th Conference in Uncertainty in Artificial Intelligence, Banff,Canada, July 7-11, 2004 , pages 201–208, 2004.8. P. Prosser and C. Unsworth. Rooted tree and spanning tree constraints. In17thECAI Workshop on Modelling and Solving Problems with Constraints