From: FLAIRS-01 Proceedings. Copyright © 2001, AAAI (www.aaai.org). All rights reserved. Binary Representations Wanlin Pang Institute for Information Technology National Research Council of Canada Ottawa, Ontario, Canada K1A0R6 Email: ’ Wanlin.Pang~nrc.ca Abstract It is well knownthat a non-binaryconstraint satisfaction problem(CSP) can be transformed into an equivalent binary CSPusing the dual graph transformation. It is also knownthat the dual graph transformation is impractical in some cases where the CSPhas a large numberof constraints and/or the constraints have a larger numberof satisfying tuples. However,little work has been done on improving transformation methods. In this paper, we introduce a constraint representative graph called w-graph and present a new transformation methods based on the w-graph. Weshow that the w-graphbased transformation is a generalization of the dual graph tra~asformationand it overcomescertain weaknesses of the dual graph transformation in manycases. Introduction A non-binary constraint satisfaction problem (CSP) can either be solved directly or transformed into a binary one and then solved by using binary CSP techniques. There have been direct solution techniques developed for solving non-binary CSPs effectively (Mackworth 1977; Van Hentenryck 1989; Pang & Goodwin 1996; 1997). A potential advantage of transformation approach is that binary CSP has been extensively studied which has generated great deal of knowledge about the theory and practice of solving it. Recently, Bacchus and van Beek (Bacchus & van Beek 1998) reported their studies on the transformation from non-binary to binary CSPs and showed that for the CSPs with some particular properties, that is, the numberof constraints is low relative to the number of variables and the constraints are restrictive, even the standard dual graph based transformation method could be more efficient than solving a non-binary CSP directly by a search method such as adapted forward checking. Unfortunately, little work has been done on transformation itself. The question of whether there exist other transformation approaches or how to improve existing transformation remains unexplored. This paper addresses this problem. Copyright(~) 2001, AmericanAssociation for Artificial Intelligence (www.aaai.org).All rights reserved. for General CSPs Scott D. Goodwin Department of ComputerScience University of Regina Regina, Saskatchewan, Canada $4S 0A2 Emaih goodwin~cs.uregina.ca We present a new transformation method based on a constraint representative graph called w-graph. An w-graph is a generalization of dual graph in that a dual graph is an w-graph whereas the converse does not necessarily hold. Given a CSP (binary or non-binary), can construct an w-graph that is simpler than the dual graph in terms of cyclicity, width, and numberof nodes. Accordingly, a non-binary CSP can be transformed to an equivalent binary one based on the w-graph, and the binary CSPobtained from the w-graph based transformation is usually simpler than the one obtained from the dual graph based transformation in terms of the number of variables and/or the size of domains. In particular, the number of variables in the binary CSP obtained from the w-graph transformation does not exceed the numberof variables in the original CSP. For the class of CSPs where the number of constraints are small and the constraints are tight, according to (Bacchus & van Beek 1998), the dual graph transformation performs well and thus the w-graph transformation could be better. For CSPs with large number of constraints and large numberof satisfying tuples in the constraints, the w-graph provides us with a tool to exploit the constraint structure and to transform a non-binary CSPto a binary one based on its structure. Preliminaries Wefirst define constraint satisfaction problems (CSPs) and then briefly review related work on binary representations for general CSPs. Constraint Satisfaction Problems A constraint satisfaction problem (CSP) is a structure (X,D, V,S). Here, X = {X1, X~., ..., Xn} is a set of variables that may take on values from a set of domains D = {01, D2, ..., On}, 1and Y = {V1,V2,...,Vm} is a family of ordered subsets of X called constraint schemes. Each Vi = {Xil,Xi2,...,Xir,} is associated with a set of tuples Si C_ Di~ × Di~ x ... x Di,, called constraint instance, and S ={ $1, $2, . . . , Srn } is a family of such constraint instances. Together, an ordered 1Throughoutthis paper, we assume that Vi, j(V~ 6 V Vj E V A i ~ j =~Vi ~ V) A Vj g Vi ). KNOWLEDGE REPRESENTATION355 pair (~, Si) is constraint orrel ation which per mits the variables in r~ to take only value combinations in Si. A solution is an n-tuple from D1 × D~ × ... × Dn such that all the constraints are satisfied. The task of solving a CSPis to find one or all solutions. A binary GSP is a CSP with unary and binary constraints only, that is, every constraint schemecontains at most two variables. A CSPwith constraints not limited to unary and binary is referred to as a general CSP. Example 1 Consider a satisfiability problem, (X1 X2)A(-~X~ v-~X2)A(X~VX4VXr)A(-~X~ VX4V’~Xr)A (-~X~V-~X4VXT)A(~XlV-~X4V-~XT) A(-~X2 V ^ix2 v x4 v x~) ^ (x2 v x4 v-xT)A(X2V-X4 v XT) (~X~v ~X~v X,) ^ (~X2v ~X4v ~X,) A(X3V XT)A(XaV-~X5 VXT)A(XaV-~X. V-~X~) A(-~XaV ~xT)^ (~x3v ~x5v ~x~)A(Xav ~Xs)A (~X3V This problem can be formalized as a 3-ary CSP with 7 variables X = {X1, X2, Xa, X4, Xh, Xs, XT} and every variable has the same domain {0, 1}. The problem has 6 constraints on constraint schemes V1 = {X1, X2}, ~ = {xl, x4,xT}, va= {v2, v3}, v4= {x2, x4,XT}, V5 = {X3, 25, X7}, V6 = {23, X6}, and constraint instances are thosesetsof tuplesas shownin Figure I. For example, thereis a constraint on XI and X2. The permissible value pairs (01) and (10) represent (X1 V X2) A (-~X1 V -~X2). Dual Graph Representation A binary CSPis associated with a simple graph in which nodes represent variables and edges represent binary constraints. A general CSP is associated with a hypergraph in which nodes represent variables and hyperedges represent constraints (see Figure 1). A hypergraph has a dual graph s whose nodes are hyperedges of the hypergraph and with two nodes joined with an edge if these two nodes share commonvariables (see Figure 2). The dual graph representation transforms a general CSP to a binary one in which the variables are the original constraint schemes represented by the nodes of the dual graph (Dechter and Pearl (Dechter & Pearl 1989)). The domains of the new variables are original constraint instances. There is a compatible constraint between two variables if there is an edge between two nodes in the dual graph. Example 2 The CSP in Example 1 is associated with a hypergraph, as in Figure 1, which has a dual graph as shown in Figure 2. In the binary CSPobtained from dual graph transformation, the variable set is original constraint scheme set V = {V~, ~, Va, V4, V~, Vs}. The domains of the new variables and 10 binary constraints are shown in Figure 2. For example, the domain of I/1 is {1, 2} representing tuples (01) and (10)in the original constraints on V~ = {X1, X2}. The domain of 1/4 is {3,4,5} representing tuples (011), (100), and (101)in the original constraints on V4 = {X2, )(4, Xz}. There a constraint on the new variables V1 and V4 because they share a commonvariable X2. The permissible value pair (14), for example, represents that the tuple (01) for {X~, X2}and the tuple (100) for {X2, )(4, are compatible. Figure 1: A general CSPand its hypergraph Since constraints are defined as relations, we use some relational operators, specifically, join and projection. Let Ci = (~, Si) and Cj = (~, Sj) be two constraints, ti E Si and tj E Sj two tuples, and Vh a subset of ~. The join of Ci and Cj is a constraint denoted by Ci t~ Q. The projection of Ci = (V~., Si) on V~ C_ Vi is a constraint denoted by IIv~(Ci). The projection of ti on Vh, denoted by ti[Vh], is a tuple consisting of only the componentsof ti that correspond to variables in Vh. ti and tj are compatible if ti[V/N V~] -- t~[~ fq V~]. If tl and tl are compatible, the join ofti and t~, denoted by ti t~ tj, is a tuple such that (ti t~ tj)[V/] = ti and (t~ ~ t~)[v~]= t~. A constraint (Vh, Sh) in a CSP(X, D, V, S) is redundant if its removal does not change the relation represented by the CSP; that is, there is a set of constraints {(V~,, S~,),..., (Vp,,S~)} such that Vh U~=~V~,and Uv~(~L1s~,) c_ s~. 356 FLAIRS-2001 Figure 2: The dual graph and the binary CSP Join Graph Representation Several researchers (Gyssens 1986; Dechter & Pearl 1989; Jegou 1993b) have noticed that the dual constraint graph obtained from a general CSPcan be simplified by removing rednndant edges resulting in a join graph. An edge in a dual graph is redundant if the variables shared by its two end nodes are also shared by every nodes along an alternative path between the 2Thedual graph is also called inter graph (Jegou 1993a) and line graph (Maier 1983). two end nodes. Since all binary constraints in the new binary CSPare compatible constraints (i.e., the two tupies assigned to the two constrained new variables agree on values for all shared original variables), the constraints associated with the redundant edges are also redundant, and therefore can be removed without affecting solutions to the original CSP. In other words, the join graph representation transforms a general CSP to a binary one in which there is no redundant constraints that are in the binary CSPobtained from dual graph transformation. Example 3 The CSP in Example 1 is transformed to a binary one based on a join graph as shown in Figure 3. Notice that 3 redundant constraints on {V3, V4}, {V4, Vh}, and {Vh, Vs} are removed. 11 2} (t2) {0,],2} c2o, (V~ (1,, / (12) I I(1,4,~ (II) I .... k (oo) I:.’;’;~\02) (3 1) 11,2.3. ,4.6| { .4, (0. 1} :7 - Figure 3: A join graph and the binary CSP A join graph is minimal if it does not contain redundant edges. A minimal join graph can be obtained from the dual graph by removing all redundant edges. Given a hypergraph H = (X, V) and its dual graph I(H) = (V, L), The following algorithm constructs a minimal join graph j(H) = (V, J). The time complexity of the algorithm is O(IYp). min-join-graph(( V, L ) 1. begin 2. for each i from m to 2 do for each j from i - 1 to 1 do 3. 4. if P)~ = ~ NP]" ~ if3k(k < j, Vh C ~nVk) 5. 6. L ~ L - {(P~, ~)}; 7. else if 3k(j < k < i, Vh C ~ n Vk 8. L ~- L - {(V/, 1~)}; 9. return (V, L); 10. end w-Graph Representation Given a general CSP (X, D, V,S) and its associated constraint hypergraph H = (X, V), we can construct dual graph l(H) = (V, whose nod es are hyperedges of H and with two nodes 1~ and Vj joined with an edge (V/,P)) E L if~ NVj ~ 0. jo in gr aph of H i s a partial dual graph, j(H) = (V, g), where J C L and for every pair ~, Vj in V, if I~ N Vj¢ $, then there exists in j(H) a chain ~ -- Vp~, Vp~,..., Vpq = Vj such that V/n ~ C Vp~n Vp~+~for all 1 _< k < q. As a graph representation of CSPs, we observed that a join graph can be further simplified by deleting some nodes resulting in a new representative graph which is called w-graph. In this section, we define the w-graph and show how to transform a general CSP to a binary one based on an w-graph. w-Graph The node set of an w-graph is a special set of nodes of the dual graph called w-cover. An w-cover is a subset of constraint schemes with the property that any constraint scheme not in the w-cover is covered by two constraint schemes in the w-cover. More formally, Definition 1 Given a hypergraph H = (X, V). A subset W C_ V is called an w-cover of X if toW = X and if for any V~ E V- W, there exist Vi, Vj E W such that Vk C_ ~ tO Vj. An w-cover W is minimal/f there is no 1~, Vj, V~ E Wsuch that V~ C_ ~ U ~. For example, given a hypergraph H -- (X, V) in Figure 1, where X = {X1,X2,Xa,X4,Xh,X6,XT) and V - {V1,V2,Va,V4,Vh,Vs}. A subset of V, W1 = {V2,V3,V4,Vh,Vs} is an w-cover, since for V1 {X1,X2} e V- W, there are V2 = {XI,X4, X~}, V4 = {X2, X4, XT} E W1such that V1 C V~ to V4. The subset W2= {V~.,V4,Vh,Vs} is a minimal w-cover. Notice that V itself is a w-coverbut not necessarily a minimal w-cover. For findin~n w-cover we can split__V into two subsets, Wand W, where for every Vk in Wthere is a pair V~ and V~ in Wsuch that V~ C_ ~ to V~, and there are no P~, P~, and V~in Wsuch that V~ C V/to V~. Initially, we move all those V~ from V to W, where there are no V/,~ in V such that V~ C V/to~. Then we repeat the following process until V is empty: first we move all these V~ from V to W, where there are V/,V~ E W such that V~ C ~ U ~; if V is still not empty, then we select V/ and Vj in W U V and V~ from V such that V~ C t~ tO Vj, move~, P~ to Wif they are not in Wyet, and moveV~ to W. This idea is formalized as an algorithm which is given below. Notice that w-cover(V, ~) has a parameter V~ which is a node subset we wish to retain in the w-cover. ~-cowr(V,V’) 1. begin 2. w ~ v’ u { v~l ~V~,l~ e Vs.t. V~_Cpiuv~}; 3. 4. 5. 6. 7. 8. 9. V~V-W; re_peat w~-{v~lv~ev,3v,,~ws.t, v~ c ~ uv~}; V~V-W; ifV ¢~ find V~, l/) e W to V,V~ E V s.t. __w~___w u {t~, ~}; V~_C_¼uV~.; 10. W ~-- WU {Vk}; 11. V +- V - {1~, V), V}}; 12. untilV = ~; 13. return W; 14. end From an w-cover and a hypergraph, we can construct an w-graph. KNOWLEDGE REPRESENTATION357 Definition 2 Let H = (X, V) be a hypergraph and an w-cover. An w-linegraph of H = (X, V) is a graph wl(H) = (W, E), where the node set W is an w-cover and there is an edge joining two nodes Vi and Vj if either ~ N Vj ~ 0 or there is Vk E V - W such that vkc v~urn. Given a w-linegraph wl(H) = (W, E). For each arc (~, Vj) ¯ E, we define the are-covered-set of V~. and ~ withrespectto Was vksa(~,V~)= {V~lVk ¯V W, Vk C ~ U ~}. We define the path-covered-set as vksp(~, I~ ) = { VklVk ¯ vksa(Vp, Vq)} where (Vp, Vq) any edge on any path connecting V/ and Vj. Definition 3 Let wdH) = (W,E) be an w-linegraph of a hypergraph H = (X, V). An w-graph of H is a partial w-linegraph w(H) = (W, F), where F C E that for any (V/,~) ¯ E, (i). ifVifqr~ # 0, then there exists in w(H) a chain I,~ = Wl, W~.... , Wq = such that V~ N V~. C Wk for all 1 < k < q; and (ii). if vks~(~,v~)# ~, thenvkso(~,~) C-vksp(V,, A minimal w-graph is an w-graph win(H) = (W, F,~) where there is no F’ C F,n such that (W, F’) is aa graph. For example, given a hypergraph H = ( X, V) as in Figure 1 and an w-cover W= {V2, V4, V5, Vs}, we can have an w-linegraph and an w-graph as shown in Figure 4 (A) and (B). Notice that an w-linegraph is w-graph but not necessarily a minimal w-graph. (A) Anm-lincgraph (S) An~-graphandthe binaryCSP Figure 4: w-graphs and the binary CSP There are different ways to construct an w-graph for a hypergraph. For example, we can first find an w-cover, then construct a sub join graph induced by the w-cover, and finally construct an w-graph by adding necessary edges representing those constraints not in the w-cover. This is the idea of the algorithm w-graph as shown in the following. Other w-graph algorithms can be found in (Pang 1998). w-graph( ( Y,L), 1. begin 2. (W, Jw) ~ subgraph of (V, L) induced by 3. (W, F) ,--- min-join-graph((W, Jw)); 4. for each Vk ¯ V - W do 5. if/~(V~, I~) ¯ F s.t. Vk C V/U find~,~s.t.VkCViUt~;F~--FU{(Vi,Vj)}; 6. 7. return (W,F); 8. end 3S8 FLAIRS-2001 Since V is an w-cover, a join graph is also an w-graph but not necessarily a minimal w-graph. The w-graph has somenice properties in terms of degree of cyclicity and width that are crucial for characterizing the time complexity of solving a CSP, interested readers are referred to (Pang 1998). For binary representation, present a proposition here without proof. Proposition 1 Given a hypergraph H = (X, V), we can construct an w-graph w(H) = (W,F), such IWI<IXl, in polynomial time. w-Graph Transformation A general CSP is associated with a hypergraph which has an w-graph (including join graph). From a CSP (x, o, v, s) andanw-graph w(n)= (w, F), form a binary CSP (W, ~°, F , R ), w here e ach ~ ¯ is considered a singleton variable that takes on values from a set of domains Sw = {3i1~ ¯ W} C S. F is a set of binary constraint schemes and R is a set of constraint instances. Each edge Fij = {~, ~ } in F is associated with a subset R0 = (IIv,(Sij) = IIv~(Sij)) in R where S0 C_ Si t~ Sj such that IIvh (SO) C_ Sh for all vh¯ vks~(V~ u v~). In other words, the binary constraint posed on V/and requests that the instantiation of variables in r~ and has to satisfy the compatible constraint as well as the original constraints in arc-covered-set vksa(Vi, Vj). Weprove that such a binary CSP is equivalent to the original general CSP; that is, they represent the same relation on X. Proposition 2 If (W, w, F , R ) i s a bi nary CSP convetted from a general CSP (X, D, V, S) and an graph w(H) = (W,F) as described above, then CSPs represent the same relation on X. Proof. Assume W = {V1,V2,...,Vw}. Let an ntuple t a = (~l,Z2,...,zn) be a solution to (X, D, V, we show the instantiation of V1,V2,...,Vw, tb = (ta[V1],ta[V2],...,ta[Vw]), is a solution to (W, to, F ,/{), i.e., for any (¼,V~) ¯ F,(ta[~],ta[~])¯ RO. If v~nv~ ¢: 0, t~[~][¼ n~]= t~[v~nv~]=t,[r6][¼n v~], If vks~(l,~, V~) # O, for any V~ ¯ vksa(Vi, V~), (ta[Vi] t~ ta[~])[Vt ] = ta[Vi U Vj][Vt] = ta[V~] ¯ S~. In both cases, (ta[~],ta[~]) ¯ O. Let tb = (t~,t2,... ,t~) be a solution to (W, ~, F , R), we show that t a = (tz t~ tg. t~ ... t~ t~0) is a solution to (X, D, V, S), i.e., for any V~ ¯ V, ta[V~] ¯ S~. Trivially, ifV~ ¯ W, ta[V~ ] = t~ ¯ S~. If V~ ¢ W, then there are ~, V~ ¯ W such that V~ ¯ ~ O V~. So, t~[v~]= t~[~u V~l[V~] =(t~[v~]~ t~[~l)[V~] = (t~ t~)[v~]¯ &.[] Example 4 Given a CSP as in Example 1, we can construct an w-graph and transform the given CSP to a binary CSP as shown in Figure 4 (B). Here, there are 4 variables {~,V4,V~,Vs}, instead of 10 variables in the dual and join graph representations. Each variable has a domain which is the same as in the join graph representation. There are 3 constraints on {V2, V4},{V4, Vh},{Vh, V6}, which are more restrictive. For example, pair (4, 4) is in the constraint {V2, V4}in the join graph representation but is not in the same constraint in the w-graph representation, because (4, 4) is not allowed by the original constraint vl = {xl, x2}. Conclusion The w-graph is defined as a generalization of the dual graph in that a dual graph (or join graph) is an w-graph but an w-graph is not necessarily a dual graph or join graph. For this reason, the w-graph transformation can be seen as a generalization of the dual graph transformation, and thus preserves the advantages of the dual graph transformation when solving a class of general CSPs where the number of constraints is small and the constraints are tight. For CSPs that have large number of constraints and the constraints have large number of satisfying tuples, the dual graph transformation is inefficient, mainly because the binary CSP obtained from the dual graph has large number of variables and large size domains. As pointed out in Proposition 1, the number of nodes in an w-graph does not exceed the number of variables in the original CSP, and therefore, the numberof variables in the w-graph representation has a upper-bound limit which is independent of the number of original constraints. Usually, the number of satisfying tuples varies from constraint to constraint in a given CSP. The w-cover algorithm given in this paper provides flexibility of choosing those tight constraints to construct an w-graph, and therefore, the w-graph transformation avoids the problem of oversized domains. The w-graph has other nice properties in terms of cyclicity and width, which have been successfully applied to solving general CSPs directly (Pang 1998). future work is to apply the w-graph to characterize the time complexity of solving the binary CSP obtained from the w-graph transformation and to empirically compare the efficiency of w-graph based transformation and w-graph based direct solution approaches. Mackworth, A. 1977. On reading sketch maps. In Proceedings of IJCAL 77, 598-606. Mater, D. 1983. The Theory of Relational Databases. Computer Science Press. Pang, W., and Goodwin, S. D. 1996. A new synthesis algorithm for solving CSPs. In Proceedings of the Pnd International Workshop on Constraint-Based Reasoning, 1-10. Pang, W., and Goodwin, S. D. 1997. Constraintdirected backtracking. In The lOth Australian Joint Conference on AI, 47-56. Pang, W. 1998. Constraint Structure in Constraint Satisfaction Problems. Ph.D. Dissertation, University of Regina, Canada. Van I-Ientenryck, P. 1989. Constraint Satisfaction in Logic Programming. Cambridge, MA: The MIT Press. References Bacchus, F., and van Beck, P. 1998. On the conversion between non-binary and binary CSPs. In Proceedings of AAAI-98, 311-318. Dechter, R., and Pearl, J. 1989. Tree clustering for constraint networks. Artificial Intelligence 38:353-366. Gyssens, M. 1986. On the complexity of join dependencies. ACMTransactions on Database Systems 11(1):81-108. Jegou, P. 1993a. On some partial line graphs of a hypergraph and the associated matroid. Discrete Mathematics 111:333-344. Jegou, P. 1993b. On the consistency of general constraint satisfaction problems. In Proceedings of AAAI93, 114-119. KNOWLEDGE REPRESENTATION369