A Test for Tractability Peter Jeavons1 , David Cohen1 and Marc Gyssens2 1
Department of Computer Science, Royal Holloway, University of London, UK e-mail:
[email protected] 2 Department WNI, University of Limburg, B-3590 Diepenbeek, Belgium e-mail:
[email protected] Abstract. Many combinatorial search problems can be expressed as `constraint satisfaction problems', and this class of problems is known to be NP-complete in general. In this paper we investigate restricted classes of constraints which give rise to tractable problems. We show that any set of constraints must satisfy a certain type of algebraic closure condition in order to avoid NP-completeness. We also describe a simple test which can be applied to establish whether a given set of constraints satis es a condition of this kind. The test involves solving a particular constraint satisfaction problem, which we call an `indicator problem'. Keywords: Constraint satisfaction problem, complexity, NP-completeness, indicator problem
1 Introduction Solving a constraint satisfaction problem is known to be an NP-complete problem in general [13] even when the constraints are restricted to binary constraints. However, many of the problems which arise in practice have special properties which allow them to be solved eciently. The question of identifying restrictions to the general problem which are sucient to ensure tractability is important from both a practical and a theoretical viewpoint, and has been extensively studied. Such restrictions may either involve the structure of the constraints, in other words, which variables may be constrained by which other variables, or they may involve the nature of the constraints, in other words, which combinations of values may be allowed for variables which are mutually constrained. Examples of the rst approach may be found in [4, 5, 7, 14, 15] and examples of the second approach may be found in [2, 9, 10, 11, 14, 18, 19]. In this paper we take the second approach, and investigate those classes of constraints which ensure tractability in whatever way they are combined. A number of distinct classes of constraints with this property have previously been identi ed and shown to be maximal [2, 10, 9]. It is currently unknown whether there are any further tractable constraint classes still to be identi ed. In [9] we showed that all known examples of such classes are characterized by a simple algebraic closure condition. This naturally raised the question of whether all possible tractable classes satisfy such a closure condition. In this paper we answer this question by proving that any class of constraints which does
not give rise to NP-complete problems must indeed satisfy such a closure condition, and hence this property is a necessary condition for a class of constraints to be tractable (assuming that P is not equal to NP). Furthermore, we describe a simple test to establish whether a given set of constraints satis es this necessary algebraic condition. The test involves calculating the solutions to a xed constraint satisfaction problem involving constraints from the given set. The paper is organised as follows. In Section 2 we give the basic de nitions, and describe a general form of algebraic closure condition for a set of relations. In Section 3 we show that this condition is necessary for tractability, and in Section 4 we describe a test for this condition. Finally we summarise the results presented and draw some conclusions.
2 De nitions 2.1 The constraint satisfaction problem Notation 1 For any set D, and any natural number n, we denote the set of all n-tuples of elements of D by Dn . For any tuple t 2 Dn , and any i in the range 1 to n, we denote the value in the ith coordinate position of t by t[i]. The tuple t will be written in the form ht[1]; t[2]; : ::; t[n]i. A subset of Dn is called an n-ary relation over D. We now de ne the ( nite) constraint satisfaction problem which has been widely studied in the Arti cial Intelligence community [13, 14, 12] De nition2. An instance of a constraint satisfaction problem consists of { a nite set of variables, V ; { a nite domain of values, D; { a set of constraints fC1; C2; : : :; Cqg. Each constraint Ci is a pair (Si ; Ri), where Si is a list of variables of length mi , called the constraint scope, and Ri is an mi -ary relation over D, called the constraint relation. The tuples of Ri indicate the allowed combinations of simultaneous values for the variables in Si . The length of the tuples in the constraint relation of a given constraint will be called the arity of that constraint. In particular, unary constraints specify the allowed values for a single variable, and binary constraints specify the allowed combinations of values for a pair of variables. A solution to a constraint satisfaction problem is a function from the variables to the domain such that the image of each constraint scope is an element of the corresponding constraint relation. Deciding whether or not a given problem instance has a solution is NPcomplete in general [13] even when the constraints are restricted to binary constraints. In this paper we shall consider how restricting the allowed constraint relations to some xed subset of all the possible relations aects the complexity of this decision problem. We therefore make the following de nition.
De nition3. For any set of relations, ? , CSP(? ) is de ned to be the class of
decision problems with INSTANCE: A constraint satisfaction problem P in which all constraint relations are elements of ? . QUESTION: Does P have a solution? If there exists an algorithm which solves every problem in CSP(? ) in polynomial time, then we shall say that ? is a tractable set of relations. Example 1. The binary inequality relation over a set D, denoted =D , is de ned as =D = fhd1; d2i 2 D2 j d1 6= d2g: Note that CSP(f=D g) corresponds precisely to the Graph jDj-Colorability problem [6]. This problem is tractable when jDj 2 and NP-complete when jDj 3. 6
6
6
Example 2. We now describe four relations which will be used as examples of constraint relations throughout the paper. Each of these relations is a set of tuples of elements from the domain D = f0; 1; 2g, as de ned below:
R1 = f h0; 0i; R2 = f h0; 1; 2i; h1; 2i; h1; 2; 0i; h0; 1i; h2; 0; 1i g h2; 1i g R3 = f h0; 1i; R4 = f h0; 1i; h0; 2i; h0; 2i; h1; 0i; h1; 0i; h1; 1i; h1; 2i; h1; 2i; h2; 0i; h2; 0i; h2; 1i g h2; 1i; h2; 2i g CSP(fR1; R2; R3; R4g) contains all constraint satisfaction problems in which the constraint relations are all equal to one of R1; R2; R3 or R4. Note that R4 = =D , so by Example 1, CSP(? ) is NP-complete for any subset, ? , of the set fR1; R2; R3; R4g containing the relation R4. The complexity of CSP(? ) for subsets of fR1; R2; R3; R4g which do not contain R4 will be determined using the techniques developed later in this paper. 6
2.2 Operations on relations
In Section 3 we shall examine conditions on a set of relations ? which allow known NP-complete problems to be reduced to CSP(? ). The reductions will be described using standard operations from relational algebra [1], which are described in this section. De nition4. We de ne the following operations on relations. { Let R1 be an n-ary relation over a domain D and let R2 be an m-ary relation over D. The Cartesian product R1 R2 is de ned to be the (n + m)-ary relation R1 R2 = fht[1]; t[2];: ::; t[n + m]i j (ht[1]; t[2]; :: :; t[n]i 2 R1 ) ^ (ht[n + 1]; t[n + 2]; : : :; t[n + m]i 2 R2 )g: { Let R be an n-ary relation over a domain D. Let 1 i; j n. The equality selection i=j (R) is de ned to be the n-ary relation i=j (R) = ft 2 R j t[i] = t[j ]g: { Let R be an n-ary relation over a domain D. Let i1; : : :; ik be a subsequence of 1; : : :; n. The projection i1;:::;ik (R) is de ned to be the k-ary relation i1 ;:::;ik (R) = fht[i1]; : : :; t[ik ]i j t 2 Rg: It is well-known that the combined eect of two constraints in a constraint satisfaction problem may be obtained by performing a relational join operation [1] on the two constraint relations [7]. The next result is a simple consequence of the de nition of the relational join operation. Lemma 5. The join of relations R1 and R2 can be calculated by performing a sequence of Cartesian product, equality selection and projection operations on R1 and R2. In view of this result, it will be convenient to use the following notation. Notation 6 The set of all relations which may be obtained from a given set of relations, ? , using some sequence of Cartesian product, equality selection, and projection operations will be denoted ? + .
2.3 Operations on tuples
We will show in Section 3 that any tractable set of relations over a set D must satisfy certain algebraic conditions. In order to describe these conditions we need to consider arbitrary operations on D, in other words, arbitrary functions from Dk to D, for arbitrary values of k. Any such operation on D may be extended to an operation on tuples over D by applying the operation in each coordinate position separately (i.e., pointwise). Hence, any operation de ned on the domain of a relation may be used to de ne an operation on the tuples in that relation, as follows:
De nition7. Let R be an n-ary relation over a domain D, and let : Dk ! D
be a k-ary operation on D. For any collection of k tuples, t1 ; t2; : : :; tk 2 R, (not necessarily all distinct) the n-tuple (t1 ; t2; : : :; tk ) is de ned as follows:
(t1 ; t2; : : :; tk ) = h (t1 [1]; t2[1]; : : :; tk [1]); (t1[2]; t2[2]; : : :; tk [2]); : : :; (t1 [n]; t2[n]; : : :; tk[n])i: Using this de nition, we now de ne the following closure property of relations. De nition8. Let R be a relation over a domain D, and let : Dk ! D be a k-ary operation on D. R is said to be closed under if, for all t1; t2 ; : : :; tk 2 R (not necessarily all distinct),
(t1 ; t2; : : :; tk ) 2 R: Example 3. Let 4 denote the ternary operation which returns the rst repeated value of its three arguments, or the rst value if they are all distinct. The relation R2 de ned in Example 2 is closed under 4, since applying the 4 operation to any 3 elements of R2 yields an element of R2. For example, 4(h0; 1; 0i; h1; 2; 0i; h1; 2; 0i) = h1; 2; 0i 2 R2: The relation R1 de ned in Example 2 is not closed under 4, since applying the 4 operation to the last 3 elements of R1 yields a tuple which is not an element of R1: 4(h1; 2i; h0; 1i; h2; 1i) = h1; 1i 62 R1: For any set of relations ? , and any operation , if every R 2 ? is closed under
, then we shall say that ? is closed under . The next lemma indicates that the property of being closed under some operation is preserved by each of the operations on relations described in Section 2.2. Lemma 9. Let R1 and R2 be relations which are closed under , for some operation . The following relations are also closed under : 1. the Cartesian product, R1 R2; 2. any projection of R1 or R2; 3. any equality selection from R1 or R2. Proof. Follows immediately from the de nitions. We shall be particularly interested in operations that depend on more than one argument. We therefore make the following de nition: De nition10. An operation : Dk ! D is called essentially unary if there exists some non-constant unary operation f : D ! D and some i in the range 1 to k, such that (d1 ; d2; : : :; dk ) = f (di ) for all d1; d2; : : :; dk. Note that constant functions are excluded from this de nition, and so are not essentially unary.
3 Closure and Tractability In this Section we will show that any set of relations which is only closed under essentially unary operations will give rise to a class of problems which is NPcomplete. Assuming that P is not equal to NP, this implies that any tractable set of relations must be closed under some operation which is not essentially unary. In other words, this algebraic property is a necessary condition for tractability.
Theorem 11. For any nite set of relations, ? , over a nite set D, either 1. CSP(? ) is NP-complete; or 2. ? is closed under some operation which is not essentially unary. Proof. When jDj 2, then we may assume without loss of generality that D f0; 1g, where 0 corresponds to the Boolean value False and 1 corresponds the Boolean value True. It follows that the class of problems CSP(? ) corresponds to the Generalised Satisfiability problem over the set of logical relations ? , as de ned in [16] (see also [6]). It was established in [16] that this problem is NP-complete unless one of the following conditions holds:
1. Every relation in ? contains the tuple (0; 0; : : :; 0); 2. Every relation in ? contains the tuple (1; 1; : : :; 1); 3. Every relation in ? is de nable by a formula in conjunctive normal form in which each conjunct has at most one negated variable. 4. Every relation in ? is de nable by a formula in conjunctive normal form in which each conjunct has at most one unnegated variable. 5. Every relation in ? is de nable by a formula in conjunctive normal form in which each conjunct contains at most 2 literals. 6. Every relation in ? is the set of solutions of a system of linear equations over the nite eld GF(2). It is straightforward to show that in each of these cases ? is closed under some operation which is not essentially unary (see [8] for details). Hence the result holds when jDj = 2. For larger values of jDj we proceed by induction. Assume that jDj 3 and the result holds for all smaller values of jDj. Let m = jDj(jDj ? 1) and let n = jDjm . Let M be an m by n matrix over D in which the columns consist of all possible m-tuples over D (in some order). Let R0 be the relation consisting of all the tuples occuring as rows of M . The only condition we place on the choice of order for the columns of M is that 1;2(R0) = =D , where =D is the binary inequality relation over D, as de ned in Example 1. We now construct a relation R^0 which is the `closest approximation' to R0 that we can obtain from the relations in ? using the Cartesian product, equality selection and projection operations: 6
\ R^0 = fR 2 (? [ D1 )+ j R0 Rg:
6
Since this is a nite intersection, and intersection is a special case of join we have from Lemma 5 that R^0 2 (? [ D1 )+ . In other words, the relation R^0 may be obtained as a derived constraint relation in some problem belonging to CSP(? ). There are now two cases to consider: 1. If there exists some tuple t0 2 R^0 with t0[1] = t0 [2], then we will construct, using t0, an appropriate operation under which ? is closed. De ne the function : Dm ! D by setting (d1; d2; : : :; dm ) = t0 [j ] where j is the unique column of M corresponding to the m-tuple hd1 ; d2; : : :; dm i. We will show that ? is closed under . Choose any R 2 ? , and let p be the arity of R. We are required to show that R is closed under . Consider any sequence t1 ; t2 : : :; tm of tuples of R (not necessarily distinct), and for i = 1; 2; : : :; p, let ci be the m-tuple ht1 [i]; t2[i]; : : :; tm [i]i. For each pair of indices, i; j , such that ci = cj , apply the equality selection i=j to R, to obtain a new relation R0. Now choose a maximal set of indices, I = fi1 ; i2; : : :; is g, such that the corresponding ci are all distinct, and construct the relation R00 = I (R0) Dn?jI j . Finally, permute the coordinate positions of R00 (by a sequence of Cartesian product, equality selection, and projection operations), such that R00 R0 (this is always possible, by the construction of R0 and R00). Since R00 2 (? [ D1 )+ , we know that t0 is a tuple of R00, by the de nition of R^0. Hence the appropriate projection of t0 is an element of R, and R is closed under . If is essentially unary, then let f : D ! D be the corresponding unary operation, and set f (D) = ff (d) j d 2 Dg; f (? ) = ffhf (d1); f (d2 ); : : :; f (dr )i j hd1 ; d2; : : :; dr i 2 C g j C 2 ? g: By the choice of t0, f cannot be injective, so jf (D)j < jDj. By the inductive hypothesis, we know that either CSP(f (? )) is NP-complete (in which case CSP(? ) must also be NP-complete) or else f (? ) is closed under some operation which is not essentially unary (in which case ? is closed under the operation f , which is also not essentially unary). Hence, the result follows by induction in this case. 2. Alternatively, if R^0 contains no tuple t such that t[1] = t[2], then 1;2(R^0 ) = =D , so =D 2 (? [ D1 )+. But this implies that CSP(f=D g) is reducible to CSP(? ), since every occurence of the constraint relation =D may be replaced with an equivalent collection of constraints with relations chosen from ? . However, it was pointed out in Example 1 that CSP(f=D g) corresponds to the Graph jDj-Colorability problem [6], which is NP-complete when jDj 3. Hence, this implies that CSP(? ) is NP-complete, and the result holds in this case also. 6
6
6
6
6
We may sharpen this result a little further by bounding the possible arity of the closure operations on ? which we need to consider, as the next result shows. Theorem 12. For any set of relations ? over a nite set D, if ? is closed under some operation which is not essentially unary, then it is also closed under some operation ^ of arity at most maxf3; jDjg, which is not essentially unary. Proof. (This proof is adapted from the proof of Lemma 1.14 in [17]). Let ? be a set of relations which is closed under some operation which is not essentially unary. Let ^ be an operation of the smallest possible arity, such that ? is closed under ^ and ^ is not essentially unary, and let k be the arity of ^ . If k 3, then the result holds, so we only need to consider the case when k 4. Now consider the operations which are obtained from ^ by identifying two arguments. Since ? is closed under these operations, and they have a lower arity than ^ , they must all be essentially unary, by the choice of ^ . Hence, if we identify the rst two arguments we have
^ (xz 1}|; x1{; x3; x4; : : :; xk) = f12(xi ) for some non-constant unary operation f12 and some i 2 f1; 2; : : :; kg. Similarly, if we identify the third and fourth arguments we have
^ (x1; x2; xz 3}|; x3{; x5; : : :; xk ) = f34 (xj ) for some non-constant unary operation f34 and some j 2 f1; 2; : : :; kg. This means that
^ (xz 1}|; x1{; zx3}|; x3{; x5; : : :; xk) = f12(xi ) = f34(xj ) for all possible choices of x1; x3; x5; x6; : : :; xk , which implies that either i 62 f1; 2g or j 62 f3; 4g. It follows from this that we can permute the order of the arguments of ^ to obtain a function which satis es the identity (x1 ; z}|{ x; x; x4; : : :; xk ) = f (x1 ) for some non-constant unary operation f . In particular, we have (x1; y; y; : : :; y) = f (x1 ). Now, for all distinct pairs of indices i; j in f2; 3 : : :; kg, we know that the k ? 1-ary function (x1; x2; : : :; xi?1; x; xi+1; : : :; xj ?1; x; xj +1; : : :; xk ) is an essentially unary function, and since we have just shown that for one particular choice of x2; x3; : : :; xk it equals f (x1 ), we know that it must equal f (x1 ) in all cases. Similarly, (using the fact that k 4), for all indices i 2 f2; 3; : : :; kg, we can establish that (x; x2; : : :; xi?1; x; xi+1; : : :; xk ) = f (x): Now, if k > jDj then there are more arguments than values, so at least one argument value must be repeated somewhere, and in that case we would have (x1 ; x2; : : :; xk) = f (x1 ). Since is just ^ with the order of the arguments permuted, we have contradicted the fact that ^ is not essentially unary. This means that we must have k jDj, and the result follows.
4 A Test for Tractability Let ? be a set of relations over a set D. Note that the operations under which ? is closed are simply mappings from Dk to D, for some k, which satisfy certain constraints, as described in De nition 8. In this Section we show that it is possible to identify these operations by solving a single constraint satisfaction problem. In fact, we shall show that these closure operations are precisely the solutions to a constraint satisfaction problem of the following form. De nition13. Let ? be a set of relations over a nite domain D. For any natural number m > 0, the indicator problem for ? of order m is de ned to be the constraint satisfaction problem IP (?; m) with { Set of variables Dm ; { Domain of values D; { Set of constraints fC1; C2; : : :; Cq g, such that for each R 2 ? , and for each sequence t1 ; t2; : : :; tm of tuples from R, there is a constraint Ci = (Si ; R) with Si = (v1 ; v2; : : :; vn) where n is the arity of R and vj = ht1[j ]; t2[j ]; : : :; tm [j ]i. Example 4. Consider the relation R1 over D = f0; 1; 2g, de ned in Example 2. The indicator problem for fR1g of order 1, IP (fR1g; 1), has 3 variables and 4 constraints. The set of variables is
fh0i; h1i; h2ig; and the set of constraints is
f ((h0i; h0i); R1); ((h0i; h1i); R1); ((h1i; h2i); R1); ((h2i; h1i); R1) g: The indicator problem for fR1g of order 2, IP (fR1g; 2), has 9 variables and
16 constraints. The set of variables is
fh0; 0i; h0; 1i; h0; 2i; h1; 0i; h1; 1i; h1; 2i; h2; 0i; h2; 1i; h2; 2ig; and the set of constraints is f ((h0; 0i; h0; 0i); R1); ((h0; 0i; h0; 1i); R1); ((h0; 0i; h1; 0i); R1); ((h0; 0i; h1; 1i); R1); ((h0; 1i; h0; 2i); R1); ((h0; 1i; h1; 2i); R1); ((h0; 2i; h0; 1i); R1); ((h0; 2i; h1; 1i); R1); ((h1; 0i; h2; 0i); R1); ((h1; 0i; h2; 1i); R1); ((h1; 1i; h2; 2i); R1); ((h1; 2i; h2; 1i); R1); ((h2; 0i; h1; 0i); R1); ((h2; 0i; h1; 1i); R1); ((h2; 1i; h1; 2i); R1); ((h2; 2i; h1; 1i); R1) g:
Example 5. Consider the relation R2 over D = f0; 1; 2g, de ned in Example 2. The indicator problem for fR2g of order 1, IP (fR2g; 1), has 3 variables and 3 constraints. The set of variables is
fh0i; h1i; h2ig; and the set of constraints is
f ((h0i; h1i; h2i); R2); ((h1i; h2i; h0i); R2); ((h2i; h0i; h1i); R2) g: The indicator problem for fR2g of order 2, IP (fR2g; 2), has 9 variables and 9
constraints. The set of variables is fh0; 0i; h0; 1i; h0; 2i; h1; 0i; h1; 1i; h1; 2i; h2; 0i; h2; 1i; h2; 2ig; and the set of constraints is f ((h0; 0i; h1; 1i; h2; 2i); R2); ((h0; 1i; h1; 2i; h2; 0i); R2); ((h0; 2i; h1; 0i; h2; 1i); R2); ((h1; 0i; h2; 1i; h0; 2i); R2); ((h1; 1i; h2; 2i; h0; 0i); R2); ((h1; 2i; h2; 0i; h0; 1i); R2); ((h2; 0i; h0; 1i; h1; 2i); R2); ((h2; 1i; h0; 2i; h1; 0i); R2); ((h2; 2i; h0; 0i; h1; 1i); R2) g:
Example 6. Consider the relations R1 and R2 over D = f0; 1; 2g, de ned in Example 2. The indicator problem for fR1; R2g of order 1, IP (fR1; R2g; 1), has 3 variables and 7 constraints. The set of variables is fh0i; h1i; h2ig; and the set of constraints is equal to the union of the set of constraints of IP (fR1g; 1), as de ned in Example 4, and the set of constraints of IP (fR2g; 1), as de ned in Example 5. The indicator problem for fR1; R2g of order 2, IP (fR1; R2g; 2), has 9 variables and 25 constraints. The set of variables is
fh0; 0i; h0; 1i; h0; 2i; h1; 0i; h1; 1i; h1; 2i; h2; 0i; h2; 1i; h2; 2ig; and the set of constraints is equal to the union of the set of constraints of
IP (fR1g; 2), as de ned in Example 4, and the set of constraints of IP (fR2g; 2), as de ned in Example 5.
Solutions to the indicator problem for ? of order m are functions from Dm to D, or in other words, m-ary operations on D. We now show that they are precisely the m-ary operations under which ? is closed.
Theorem14. For any set of relations ? over domain D, the set of solutions to IP (?; m) is equal to the set of m-ary operations under which ? is closed. Proof. By De nition 8, we know that ? is closed under the m-ary operation
if and only if satis es the condition (t1 ; t2; : : :; tm ) 2 R for each possible choice of R 2 ? and t1 ; t2; : : :; tm 2 R (not necessarily all distinct). But this is equivalent to saying that satis es all the constraints in IP (?; m), so the result follows. Example 7. Consider the relation R1 over D = f0; 1; 2g, de ned in Example 2. The indicator problem for fR1g of order 1, de ned in Example 4, has 2 solutions, which may be expressed in tabular form as follows:
Variables
h0i h1i h2i
Solution 1 0 0 0 Solution 2 0 1 2
One of these solutions is a constant operation, so CSP(fR1 g) is tractable, by Proposition 9 of [9]. In fact, any problem in CSP(fR1g) has the solution which assigns the value 0 to each variable, so this class of problems is trivial. The indicator problem for fR1g of order 2, de ned in Example 4, has 4 solutions, which may be expressed in tabular form as follows: Variables
Solution 1 Solution 2 Solution 3 Solution 4
0 0i h0 1i h0 2i h1 0i h1 1i h1 2i h2 0i h2 1i h2 2i
h
;
0 0 0 0
;
0 1 0 0
;
0 2 0 0
;
0 0 1 0
;
0 1 1 1
;
0 2 1 0
;
0 0 2 0
;
0 1 2 0
;
0 2 2 2
The rst of these solutions is a constant operation, and the second and third are essentially unary operations. However, the fourth solution shown in the table is more interesting. It is easily checked that this operation is an associative, commutative, idempotent (ACI) binary operation, so we have a second proof that CSP(fR1g) is tractable, by Theorem 16 of [9]. Furthermore, this result shows that R1 may be combined with any other relations (of any arity) which are also closed under this ACI operation to obtain larger tractable problem classes. Example 8. Consider the relation R2 over D = f0; 1; 2g, de ned in Example 2. The indicator problem for fR2g of order 1, de ned in Example 5, has 3 solutions, which may be expressed in tabular form as follows:
Variables
h0i h1i h2i
Solution 1 0 1 2 Solution 2 1 2 0 Solution 3 2 0 1
The indicator problem for fR2g of order 3, has a very large number of solutions, including the operation 4, de ned in Example 3. Hence, we know that CSP(? ) is tractable by Theorem 13 of [9]. Furthermore, R2 may be combined with any other relations which are also closed under this operation to obtain larger tractable problem classes. In order to draw conclusions about the tractability of a set of constraints we need to be able to distinguish closure operations which are essentially unary from those which are not. By De nition 10, this means checking whether there exists some coordinate position which has the property that when the input value in that position is constant, then the value of the operation remains constant. This checking may be carried out in mjDjm steps. Alternatively, the next result shows that the number of solutions to certain indicator problems provides a sucient condition for establishing NP-completeness, without needing to examine the individual solutions in detail.
Corollary 15. Let ? be a set of relations over domain D, let S1 be the set of non-constant solutions to IP (?; 1), and let Sm be the set of solutions to IP (?; m), where m = maxf3; jDjg. If jSm j mjS1 j, then CSP(? ) is NP-complete. Proof. By Theorem 11 and Theorem 12, we know that either CSP(? ) is NPcomplete, or ? is closed under some operation with arity at most m which is not essentially unary. By Theorem 14, Sm is the set of all m-ary operations under which ? is closed. By De nition 10, the number of these which are essentially unary is equal to the number of non-constant unary operations under which ? is closed, multiplied by m. By Theorem 14, this number is mjS1 j. Hence, jSm j mjS1 j in all cases. In the limiting case, when jSm j = mjS1 j, we know that every element of Sm is essentially unary, so ? is not closed under any m-ary operation which is not essentially unary. It follows that ? is not closed under any operation of arity lower than m which is not essentially unary, so CSP(? ) must be NP-complete.
When jDj = 2, the converse result also holds [8]. Hence solving the indicator problems of order 1 and order 3 provides a simple and complete test for tractability of any set of relations over a domain with 2 elements. This answers a question posed by Schaefer in 1978 [16] concerning the existence of an ecient test for tractability in the Generalised Satisfiability problem. Note that carrying out the test requires nding the number of solutions to a constraint satisfaction problem with just 8 Boolean variables.
For larger domains, Corollary 15 establishes NP-completeness for many sets of constraints without the need for individually constructed reduction arguments, as the following examples illustrate. Example 9. Consider the relations R1 and R2 over D = f0; 1; 2g, de ned in Example 2. The indicator problem for fR1; R2g of order 1, de ned in Example 6, has 1 solution, corresponding to the identity operation. The indicator problem for fR1; R2g of order 3, has 3 solutions (which are all essentially unary). Hence CSP(fR1 ; R2g) is NP-complete, by Corollary 15. Example 10. Consider the relations R1 ; R2; R3 and R4 over D = f0; 1; 2g, de ned in Example 2. By counting the solutions to the indicator problems of order 1 and order 3 for each relation and each pair of distinct relations in this set, we are able to complete the analysis of the complexity of CSP(? ) for each possible subset ? of these relations.
Relations # Solutions # Solutions Complexity ? IP (?; 1) IP (?; 3) of CSP(? ) (non-constant) fR1g 1 12 Trivial (Example 7) fR2g 3 9 Polynomial (Example 8) fR3g 10 30 Trivial fR4g 6 18 NP-complete (Example 1) fR1; R2g 1 3 NP-complete (Corollary 15) fR1; R3g 1 3 NP-complete (Corollary 15) fR1; R4g 1 3 NP-complete (Example 1) fR2; R3g 1 3 NP-complete (Corollary 15) fR2; R4g 1 3 NP-complete (Example 1) fR3; R4g 2 6 NP-complete (Example 1) For all larger sets of relations ? fR1; R2; R3; R4g, we have that ? contains at least one of the pairs of relations shown in the table, and so CSP(? ) is NPcomplete. How practical is the test proposed here in general? For any set of relations ?P over domain D, the indicator problem of order m has jDjm variables and m R2? jRj constraints. Hence, for small values of jDj the size of the relevant indicator problems is very small, and the solutions may be found easily. This remains true even when the arity of the relations in ? is large. As the domain size increases, the size of the indicator problems increases rapidly, and it becomes impractical to compute all solutions. On the other hand, for cases of interest, it may be possible to establish from known properties of
the constraints that the relevant indicator problems will have particular types of solution, without carrying out a complete solution algorithm. This question is currently being investigated.
5 Conclusion In this paper we have shown how the algebraic properties of relations may be used to distinguish between sets of relations which give rise to tractable constraint satisfaction problems and those which give rise to NP-complete classes of problems. In particular, we have established that any set of relations which does not give rise to an NP-complete class of constraint satisfaction problems must be closed under some operation which is not essentially unary. Furthermore, we have proposed a method for determining the operations under which a set of relations is closed by solving a particular form of constraint satisfaction problem, which we have called an indicator problem. For problems where the domain contains just two elements these results provide a necessary and sucient condition for tractability (assuming that P is not equal to NP), and an ecient test to distinguish the tractable sets of relations. For problems with larger domains the closure condition we have described is a necessary condition for tractability. The converse of this condition provides a sucient condition for NP-completeness, which we have shown is widely applicable and easy to test. We are now investigating the application of these results to particular problem types, such as temporal problems involving subsets of the interval algebra. We are also attempting to determine how the presence of particular algebraic closure properties in the constraints may be used to derive appropriate ecient algorithms for tractable problem classes.
References 1. Codd, E.F., \A Relational Model of Data for Large Shared Databanks", Communications of the ACM 13 (1970), pp. 377{387. 2. Cooper, M.C., Cohen, D.A., Jeavons, P.G., \Characterizing tractable constraints", Arti cial Intelligence 65 , (1994), pp. 347{361. 3. Dechter, R., & Pearl, J., \Structure identi cation in relational data", Arti cial Intelligence 58 (1992) pp. 237{270. 4. Dechter, R. & Pearl J. \Network-based heuristics for constraint-satisfaction problems", Arti cial Intelligence 34 (1988), pp. 1{38. 5. Freuder, E.C., \A sucient condition for backtrack-bounded search", Journal of the ACM 32 (1985) pp. 755{761. 6. Garey, M.R., & Johnson, D.S., Computers and intractability: a guide to NPcompleteness, Freeman, San Francisco, California, (1979). 7. Gyssens, M., Jeavons, P., Cohen, D., \Decomposing constraint satisfaction problems using database techniques", Arti cial Intelligence 66 , (1994), pp. 57{89.
8. Jeavons, P.G., \An algebraic characterization of tractable constraints", Technical Report CSD-TR-95-05, Royal Holloway, University of London (1995). 9. Jeavons, P., Cohen D., Gyssens, M., \A unifying framework for tractable constraints", In Proceedings 1st International Conference on Principles and Practice of Constraint Programming|CP '95 (Cassis, France, September 1995), Lecture Notes in Computer Science , 976, Springer-Verlag, Berlin/New York, 1995, pp. 276{291. 10. Jeavons, P.G., & Cooper, M.C., \Tractable constraints on ordered domains", Arti cial Intelligence 79 (1996), pp. 327{339. 11. Kirousis, L., \Fast parallel constraint satisfaction", Arti cial Intelligence 64 , (1993), pp. 147{160.. 12. Ladkin, P.B., & Maddux, R.D., \On binary constraint problems", Journal of the ACM 41 (1994), pp. 435{469. 13. Mackworth, A.K. \Consistency in networks of relations", Arti cial Intelligence 8 (1977) pp. 99{118. 14. Montanari, U., \Networks of constraints: fundamental properties and applications to picture processing", Information Sciences 7 (1974), pp. 95{132. 15. Montanari, U., & Rossi, F., \Constraint relaxation may be perfect", Arti cial Intelligence 48 (1991), pp. 143{170. 16. Schaefer, T.J., \The complexity of satis ability problems", Proc 10th ACM Symposium on Theory of Computing (STOC) , (1978) pp. 216{226. 17. Szendrei, A., Clones in Universal Algebra, Seminaires de Mathematiques Superieures 99, University of Montreal, (1986). 18. van Beek, P., \On the Minimality and Decomposability of Row-Convex Constraint Networks", Proceedings of the Tenth National Conference on Arti cial Intelligence, AAAI-92, MIT Press, (1992) pp. 447{452. 19. Van Hentenryck, P., Deville, Y., Teng, C-M., \A generic arc-consistency algorithm and its specializations", Arti cial Intelligence 57 (1992), pp. 291{321.
This article was processed using the LaTEX macro package with LLNCS style