Formally, the Constraint Satisfaction Problem (CSP) is defined as a triple , where
is a set of variables,
is a set of the respective domains,
is a set of constraints,
where each variable can take on values in the nonempty domain , every constraint is a pair where is a tuple of variables of length , called the constraint scope, and is an -ary relation on the corresponding domains, called the constraint relation.
The question is whether there exists a solution to , that is a mapping that assigns a value from to every variable such that for each constraints the image of the constraint scope is a member of the constraint relation.
In this paper we consider only CSP over finite domains. The general CSP is known to be NP-complete [11, 13]; however, certain restrictions on the allowed form of constraints involved may ensure tractability (solvability in polynomial time) [6, 8, 9, 10, 3, 5]. Below we provide a formalization to this idea.
To simplify the presentation we assume that all the domains are subsets of a finite set . By we denote the set of all finitary relations on , that is, subsets of for some . Then all constraint relations can be viewed as relations from .
For a set of relations by we denote the Constraint Satisfaction Problem where all the constraint relations are from . The set is called a constraint language. Another way to formalize the Constraint Satisfaction Problem is via conjunctive formulas. Every -ary relation on can be viewed as a predicate, that is, a mapping . Suppose , then is the following decision problem: given a formula
where for every ; decide whether this formula is satisfiable.
It is well known that many combinatorial problems can be expressed as for some constraint language . Moreover, for some sets the corresponding decision problem can be solved in polynomial time; while for others it is NP-complete. It was conjectured that is either in P, or NP-complete .
An operation is called idempotent if . An operation is called a weak near-unanimity operation (WNU) if
In the paper we present a modification of the algorithm from  that works in polynomial time for infinite constraint languages and therefore prove CSP dichotomy conjecture for infinite constraint languages.
Suppose is a set of relations. Then can be solved in polynomial time if there exists a WNU preserving ; is NP-complete otherwise.
Note that the algorithm presented in  also works for infinite constraint languages.
A set of operations is called a clone if it is closed under composition and contains all projections. For a set of operations by we denote the clone generated by .
An idempotent WNU is called special if , where . It is not hard to show that for any idempotent WNU on a finite set there exists a special WNU (see Lemma 4.7 in ).
A relation is called subdirect if for every the projection of onto the -th coordinate is . For a relation by we denote the projection of onto the coordinates .
Algebras. An algebra is a pair , where is a finite set, called universe, and is a family of operations on , called basic operations of . In the paper we always assume that we have a special WNU preserving all constraint relations. Therefore, every domain can be viewed as an algebra . By we denote the clone generated by all basic operations of .
Congruences. An equivalence relation on the universe of an algebra is called a congruence if it is preserved by every operation of the algebra. A congruence (an equivalence relation) is called proper, if it is not equal to the full relation . We use standard universal algebraic notions of term operation, subalgebra, factor algebra, product of algebras, see . We say that a subalgebra is a subdirect subalgebra of if is a subdirect relation in .
We say that the -th variable of a relation is compatible with an equivalence relation if and implies . We say that a relation is compatible with if every variable of this relation is compatible with .
For a relation by we denote the binary relation defined by
For a constraint , by we denote .
Essential and critical relations. A relation is called essential if it cannot be represented as a conjunction of relations with smaller arities. It is easy to see that any relation can be represented as a conjunction of essential relations. A relation is called critical if it cannot be represented as an intersection of other subalgebras of
and it has no dummy variables.
A tuple is called essential for an -ary relation if and there exist such that for every .
It is not hard to check the following lemma.
Parallelogram property. We say that a relation has the parallelogram property if any permutation of its variables gives a relation satisfying
We say that the -th variable of a relation is rectangular if for every and we have . We say that a relation is rectangular if all of its variables are rectangular. The following facts can be easily seen: if the -th variable of is rectangular then is a congruence; if a relation has the parallelogram property then it is rectangular.
Polynomially complete algebras. An algebra is called polynomially complete (PC) if the clone generated by and all constants on is the clone of all operations on .
Linear algebra. A finite algebra is called linear if it is isomorphic to for prime numbers . It is not hard to show that for every algebra there exists a minimal congruence , called the minimal linear congruence, such that is linear.
Absorption. Let be a subalgebra of . We say that absorbs if there exists such that for any position of . In this case we also say that is an absorbing subuniverse of . If the operation can be chosen binary or ternary then is called a binary or ternary absorbing subuniverse of .
Center. Suppose is a finite algebra with a special WNU operation. is called a center if there exists an algebra with a special WNU operation of the same arity and a subdirect subalgebra of such that there is no binary absorbing subuniverse in and
CSP instance. An instance of the constraint satisfaction problem is called a CSP instance. Sometimes we use the same letter for a CSP instance and for the set of all constraints of this instance. For a variable by we denote the domain of the variable .
We say that is a path in if are in the scope of for every . We say that a path connects and if there exists for every such that , , and the projection of onto contains the tuple .
A CSP instance is called 1-consistent if every constraint of the instance is subdirect. A CSP instance is called cycle-consistent if for every variable and any path starting and ending with in connects and . A CSP instance is called linked if for every variable appearing in and every there exists a path starting and ending with in that connects and .
Suppose . Then we can define a projection of onto , that is a CSP instance where variables are elements of and constraints are projections of the constraints of onto . We say that an instance is fragmented if the set of variables can be divided into 2 nonempty disjoint sets and such that the constraint scope of any constraint of either has variables only from , or only from .
A CSP instance is called irreducible if any instance such that every constraint of is a projection of a constraint from on some set of variables is fragmented, linked, or its solution set is subdirect.
Weaker constraints. We say that a constraint is weaker than a constraint if , , and, additionally, or . Suppose is a constraint and where is a minimal congruence such that . Then is called a congruence-weakened constraint.
Minimal linear reduction. Suppose the domain set of the instance is . The domain set is called a minimal linear reduction if is an equivalence class of the minimal linear congruence of for every . The reduction is called 1-consistent if the instance obtained after the reduction of every domain is 1-consistent.
Crucial instances. Let for every . A constraint of is called crucial in if has no solutions in but the replacement of by all weaker constraints gives an instance with a solution in . A CSP instance is called crucial in if every constraint of is crucial in . To simplify, instead of “crucial in ” we say “crucial”
In this section we present a modified algorithm from . The main problem that does not allow to use the original algorithm for infinite languages is in Steps 3 and 11, where we replace a constraint by all weaker constraints. If is infinite, we do not have a polynomial upper bound on the number of such replacements. To fix this problem, instead of replacing a constraint by all weaker constraints we replace it by all congruence-weakened constraints. Moreover, to restrict the depth of the recursion we additionally transform our instance to ensure that all the constraint relations are essential relations with the parallelogram property.
We start with the new procedures, then we explain auxiliary procedures from , and finish with the modified main part of the algorithm.
We have made only the following modifications of the algorithm.
We added Step 4 to ensure that every relation has the parallelogram property.
We added Step 5 to ensure that is an irreducible congruence for every constraint relation .
Similarly, we replaced Step 11 in  by Steps 13 and 14. In Step 13, instead of replacing a constraint by all weaker constraints we replace it by all congruence-weakened constraints. In Step 14, we try to replace a constraint by all projections onto all variables but one appearing in the constraint.
3.1 New parts
Finding an appropriate projection. Suppose , . Here we explain how to find a minimal subset such that . Note that is always an essential relation.
While do .
If , go to step 2.
Essential Representation. Suppose . An essential representation of is the following formula
where is an essential relation from , , for every and . Below we explain how to find a set , where for every , such that form an essential representation of . To guarantee this property we require that every is essential and for every there exists such that .
Choose a tuple such that for some (we have at most such tuples).
Find a minimal subset such that . Put .
Go to the next tuple in 2).
By recursive call we calculate the essential representation corresponding to .
Remove from all sets that are not maximal in by inclusion.
Note that the obtained essential representation of an essential relation consists of the original relation. Therefore, the above procedure can also be used to check whether a relation is essential.
Providing the Parallelogram Property. In this section we explain how to find the minimal relation having the parallelogram property. We say that tuples form a rectangle if there exists such that , , , . To find the minimal relation with the parallelogram property it is sufficient to close the relation under adding the forth tuple of a rectangle. This can be done in the following way.
For each .
Put , .
If then find the forth tuple of the corresponding rectangle.
If , add to .
By Lemma 4.1, every essential relation has exponentially many tuples, therefore, this procedure works in polynomial time on the size of if is an essential.
3.2 Cycle-consistency, non-linked instances, and irreducibility
Provide cycle-consistency. To provide cycle-consistency it is sufficient to use constraint propagation providing (2,3)-consistency. Formally, it can be done in the following way. First, for every pair of variables we consider the intersections of projections of all constraints onto these variables. The corresponding relation we denote by . For every we replace by where It is not hard to see that this replacement does not change the solution set.
We repeat this procedure while we can change some
. If at some moment we get a relationthat is not subdirect in , then we can either reduce or , or, if is empty, state that there are no solutions. If we cannot change any relation and every is subdirect in , then the original CSP instance is cycle-consistent.
Solve the instance that is not linked. Suppose the instance is not linked and not fragmented, then it can be solved in the following way. We say that an element and an element are linked if there exists a path that connects and . Let be the set of pairs such that , . Then can be divided into the linked components.
It is easy to see that it is sufficient to solve the problem for every linked component and join the results. Precisely, for a linked component by we denote the set of all elements such that is in the component. It is easy to see that for every . Therefore, the reduction to is a CSP instance on smaller domains.
Check irreducibility. For every and every maximal congruence on we do the following.
Choose a constraint having the variable in the scope for some , choose another variable from the scope such that .
Denote the projection of onto by .
Put . If is a proper equivalence relation, then add to .
go to the next , , and in 2.
As a result we get a set and a congruence on for every . Put . It follows from the construction that for every equivalence class of and every there exists a unique equivalence class of such that there can be a solution with and . Thus, for every equivalence class of we have a reduction to the instance on smaller domains. Then for every and we consider the corresponding reduction and check whether there exists a solution with .
Thus, we can check whether the solution set of the projection of the instance onto is subdirect or empty. If it is empty then we state that there are no solutions. If it is not subdirect, then we can reduce the corresponding domain. If it is subdirect, then we go to the next and next maximal congruence on , and repeat the procedure.
3.3 Main part
In this section we provide an algorithm that solves in polynomial time for constraint languages (finite or infinite) that are preserved by an idempotent WNU operation. We know that is also preserved by a special WNU operation . We extend to the set of all relations preserved by . Let the arity of the WNU be equal to . Suppose we have a CSP instance , where is a set of variables, is a set of the respective domains, is a set of constraints.
The algorithm is recursive, the list of all possible recursive calls is given in the end of this subsection. One of the recursive calls is the reduction of a subuniverse to such that either has a solution with , or it has no solutions at all.
Check whether is cycle-consistent. If not then we reduce a domain for some or state that there are no solutions.
Check whether is irreducible. If not then we reduce a domain for some or state that there are no solutions.
Replace every constraint by its essential representation.
By Theorem 4.13, if has no solutions then we cannot get a solution while doing the following step.
Replace every constraint relation by the corresponding constraint relation having the parallelogram property. If one of the obtained constraint relation is not essential, go to Step 3.
By Lemma 4.18, if has no solutions then we cannot get a solution in the following step.
If the congruence is not irreducible for some constraint relation , then replace the constraint by the corresponding congruence-weakened constraints and go to Step 3.
At the moment all constraint relations have the parallelogram property and is an irreducible congruence, therefore for every constraint there exists a unique congruence-weakened constraint.
Replace every constraint of by the corresponding congruence-weakened constraint, then replace every constraint relation by the corresponding constraint relation having the parallelogram property. Recursively calling the algorithm, check that the obtained instance has a solution with for every and . If not, reduce to the projection onto of the solution set of the obtained instance.
If has a binary or ternary absorbing subuniverse for some , then we reduce to .
By Theorem 4.10 we can do the following step.
If there exists a congruence on such that the algebra is polynomially complete, then we reduce to any equivalence class of .
By Theorem 4.5, it remains to consider the case when for every domain there exists a congruence on such that is linear, i.e. it is isomorphic to for prime numbers . Moreover, is proper if .
We denote by . We define a new CSP instance with domains . To every constraint we assign a constraint , where and The constraints of are all constraints that are assigned to the constraints of .
Since every relation on preserved by is known to be a conjunction of linear equations, the instance can be viewed as a system of linear equations in for different .
Our general idea is to add some linear equations to so that for any solution of there exists the corresponding solution of . We start with the empty set of equations , which is a set of constraints on .
Solve the system of linear equations and choose independent variables . If it has no solutions then has no solutions. If it has just one solution, then, recursively calling the algorithm, solve the reduction of to this solution. Either we get a solution of , or has no solutions.
Then there exist and a linear mapping such that any solution of can be obtained as for some .
Note that for any tuple we can check recursively whether has a solution in . To do this, we just need to solve an easier CSP instance (on smaller domains). Similarly, we can check whether has a solution in for every . To do this, we just need to check the existence of a solution in and for any position of .
Check whether has a solution in . If it has then stop the algorithm.
Put . Iteratively remove from all constraints that are weaker than some other constraints of .
In the following two steps we try to weaken the instance so that it still does not have a solution in for some .
For every constraint
Let be obtained from by replacing the constraint by the corresponding congruence-weakened constraints.
Replace every new constraint of by its essential representation and remove from all constraints that are weaker than some other constraints of .
If has no solutions in for some , then put and repeat Step 13.
For every constraint
Let be obtained from by replacing the constraint by its projections onto all variables but one appearing in .
Replace the new constraints by its essential representation and remove from all constraints that are weaker than some other constraints of .
If has no solutions in for some , then put and go to Step 13.
At this moment, the CSP instance has the following property. has no solutions in for some but if we replace any constraint by the corresponding congruence-weakened constraints then we get an instance that has a solution in for every . Unlike the original algorithm, we cannot claim that is crucial in . Nevertheless, Theorem 4.19 proves that we can finish the algorithm in the same way as in the original paper.
In the remaining steps we will find a new linear equation that can be added to . Suppose is an affine subspace of of dimension , thus is the solution set of a linear equation . Then the coefficients can be learned (up to a multiplicative constant) by queries of the form “?” as follows. First, we need at most queries to find a tuple . Then, to find this equation it is sufficient to check for every and every whether the tuple satisfies this equation.
Suppose is not linked. For each from to
Check that for every there exist and a solution of in .
If yes, go to the next .
If no, then find an equation such that for every satisfying there exist and a solution of in .
Add the equation to Eq.
Go to Step 10.
It is not hard to see that satisfies the conditions of Theorem 4.19. Then there exists a constraint in and a relation such that , , and is a congruence. We add a new variable with domain and a variable with the same domain as . Then we replace by and add the constraint . We denote the obtained instance by . Let be the set of all tuples such that has a solution with in . By Theorem 4.14, if we replace the constraint relation in by the minimal relation having the parallelogram property then a minimal linear reduction cannot get a solution after the replacement. Therefore, has no tuple . Similarly, if we replace in by defined by
where , then we get a solution in . Otherwise, Theorem 4.14 implies that the replacement of by the minimal relation having the parallelogram property still does not give a solution in . This contradicts the fact that if we replace any constraint by the corresponding congruence-weakened constraints then we get an instance that has a solution in for every . Thus, we know that the projection of onto the first coordinates is a full relation.
Therefore, is defined by one linear equation. If this equation is for some , then both and have no solutions. Otherwise, we put in this equation and get an equation that describes all such that has a solution in . It remains to find this equation.
Suppose is linked.
Find an equation such that for every satisfying there exists a solution of in .
If the equation was not found then has no solutions.
Add the equation to Eq.
Go to Step 10.
Note that every time we reduce our domains, we get constraint relations that are still from .
We have four types of recursive calls of the algorithm:
we replace every constraint by the corresponding congruence-weakened constraint and solve an easier CSP instance (Step 6).
Lemma 4.3 states that the depth of the recursive calls of type 3 is at most . It is easy to see that the depth of the recursive calls of type 2 and 4 is at most .
4 Correctness of the Algorithm
4.1 The size of an essential relation and depth of the recursion
Suppose is an essential relation preserved by a special WNU of arity Then
By Lemma 2.1, there exists an essential tuple for . For every choose such that
Put for every . Without loss of generality assume that for every and for every . Since preserves , we can show that . Hence, . Consider the projection of onto the last variables, which we denote by . It is not hard to check that and for every .
For any subset put , where if and otherwise. We know that for every . Since is a special WNU, . Then we can check that for any disjoint subsets we have . Thus, contains the tuple for any . Therefore, both and contain at least tuples. ∎
Suppose is an essential relation with the parallelogram property, is an irreducible congruence, , Then for every .
Put Since is an essential relation with the parallelogram property, we have . Since