Global constraints allow users to specify patterns that commonly occur in problems. One of the oldest and most useful is the All-Different constraint [Lauriere1978, Régin1994]. This ensures that a set of variables are pairwise different. Global constraints can often be decomposed into more primitive constraints. For example, the All-Different constraint can be decomposed into a clique of binary inequalities. However, such decompositions usually do not provide a global view and are thus not able to achieve levels of local consistency, such as bound and domain consistency. Considerable effort has therefore been invested in developing efficient propagation algorithms to reason globally about such constraints. For instance, several different propagation algorithms have been developed for the All-Different constraint [Régin1994, Leconte1996, Puget1998, Mehlhorn and Thiel2000, Lopez-Ortiz et al.2003]. In this paper, we show that several important global constraints including All-Different can be decomposed into simple arithmetic constraints whilst still providing a global view since bound consistency can be achieved.
There are many reasons why such decompositions are interesting. First, it is very surprising that complex propagation algorithms can be simulated by simple decompositions. In many cases, we show that reasoning with the decompositions is of similar complexity to existing monolithic propagation algorithms. Second, these decompositions can be easily added to a new solver. For example, we report experiments here using these decompositions in a state of the art pseudo-Boolean solver. We could just as easily use them in an ILP solver. Third, introduced variables in these decompositions give access to the state of the propagator. Sharing of such variables between decompositions can increase propagation. Fourth, these decomposition provide a fresh perspective to propagating global constraints that may be useful. For instance, our decompositions of the All-Different constraint suggest learning nogoods based on small Hall intervals.
2 Formal Background
A constraint satisfaction problem (CSP) consists of a set of variables, each with a finite domain of values, and a set of constraints specifying allowed combinations of values for some subset of variables. We use capitals for variables and lower case for values. We write for the domain of possible values for , for the smallest value in , for the greatest, and for the interval . A global constraint is one in which the number of variables is a parameter. For instance, the global constraint ensures that for any [Régin1994]. We will assume values range over 1 to .
Constraint solvers typically use backtracking search to explore the space of partial assignments. After each assignment, propagation algorithms prune the search space by enforcing local consistency properties like domain or bound consistency. A constraint is domain consistent (DC) iff when a variable is assigned any of the values in its domain, there exist compatible values in the domains of all the other variables of the constraint. Such an assignment is called a support. A constraint is bound consistent (BC) iff when a variable is assigned the minimum or maximum value in its domain, there exist compatible values between the minimum and maximum domain value for all the other variables. Such an assignment is called a bound support. Finally, between domain and bound consistency is range consistency. A constraint is range consistent (RC) iff when a variable is assigned any value in its domain, there exists a bound support.
Constraint solvers usually enforce local consistency after each assignment down any branch in the search tree. For this reason, it is meaningful to compute the total amortised cost of enforcing a local consistency down an entire branch of the search tree so as to capture the incremental cost of propagation. We will compute complexities in this way.
3 All-Different constraint
The All-Different constraint is one of the most useful global constraints available to the constraint programmer. For instance, it can be used to specify that activities sharing the same resource take place at different times. A central concept in propagating the All-Different constraint is the notion of a Hall interval. This is an interval of domain values which completely contains the domains of variables. is a Hall interval iff . In any bound support, the variables whose domains are contained within the Hall interval consume all the values in the Hall interval, whilst any other variables must find their support outside the Hall interval.
Consider an All-Different constraint over the following variables and values:
is a Hall interval of size 1 as the domain of 1 variable, is completely contained within it. Therefore we can remove from the domains of all the other variables. This leaves with a domain containing values 2,3,4.
is a Hall interval of size 2 as it completely contains the domains of 2 variables, and . We can thus remove from the domains of and . This leaves the following range consistent domains:
Enforcing bound consistency on the same problem does not create holes in domains. That is, it would leave with the values 2,3,4,5.
To identify and prune such Hall intervals from the domains of other variables, Leconte has proposed a RC propagator for the All-Different constraint [Leconte1996] that runs in time. We now propose a simple decomposition of the All-Different constraint which permits us to enforce RC. The decomposition ensures that no interval can contain more variables than its size. We introduce new 0/1 variables, to represent whether takes a value in the interval . For , and , we post the following constraints:
We illustrate this decomposition on our running example.
Consider again the last example (i.e. an All-Different constraint on , , , and ).
We will prove that enforcing DC on the decomposition enforces RC on the original All-Different constraint. We find it surprising that a simple decomposition like this can simulate a complex propagation algorithm like Leconte’s. In addition, the overall complexity of reasoning with the decomposition is similar to Leconte’s propagator.
Proof: [Leconte1996] provides a necessary and sufficient condition for RC of the All-Different constraint: every Hall interval should be removed from the domain of variables whose domains are not fully contained within that Hall interval. Let be a Hall interval. That is, where . Constraint (1) fixes for all . The inequality (2) with and becomes tight fixing for all . Constraint (1) for , , and removes the interval from the domain of as required for RC.
There are constraints (1) that can be woken times down the branch of the search tree. Each propagation requires time. Constraints (1) therefore take down the branch of the search tree to propagate. There are constraints (2) that each take time to propagate down the branch of the search tree for a total of time. The total running time is given by .
Note that if we use a solver in which we can specify that constraints only wake on reaching a particular bound, we can decrease to the number of times constraints (1) are woken, which gives a total complexity in .
What about bound consistency of the All-Different constraint? By using a representation that can only prune bounds [Ohrimenko et al.2007], we can give a decomposition that achieves BC in a similar way. In addition, we can reduce the overall complexity in the case that constraints are woken whenever their bounds change. We introduce new 0/1 variables, , and replace (1) by the following constraints:
Proof: We first observe that BC is equivalent to DC on constraints (2) because are Boolean variables. So, the proof follows that for Theorem 1 except that fixing prunes the bounds of if and only if or , that is, if and only if exactly one bound of the domain of intersects the interval . Only the bounds that do not have a bound support are shrunk. The complexity reduces as (3) appears times and is woken times, whilst (4) appears times and is woken just time.
A special case of All-Different is Permutation when we have the same number of values as variables, and the values are ordered consecutively. A decomposition of Permutation just needs to replace (2) with the following equality where (as before) , and :
Consider a Permutation constraint over the following variables and values:
These domains are range consistent. However, take the interval . By DC on (1), . Now, from (5), we have . Thus . By (1), this sets . On this particular problem instance, DC on constraints (1) and (5) has enforced domain consistency on the original All-Different constraint.
4 Gcc constraint
A generalization of the All-Different constraint is the global cardinality constraint, . This ensures that the value occurs between and times in to . The GCC constraint is useful in resource allocation problems where values represent resources. For instance, in the car sequencing problem (prob001 at CSPLib.org), we can post a GCC constraint to ensure that the correct number of cars of each type is put on the assembly line.
We can decompose GCC in a similar way to All-Different but with an additional integer variables, to represent the number of variables using values in each interval . Clearly, and . We then post the following constraints for , , :
Consider a GCC constraint with the following variables and upper and lower bounds on the occurrences of values:
Enforcing RC removes 1 and 3 from and and leaves the other domains unchanged. We can derive this from our decomposition. From the lower and upper bounds on the number of occurrences of the values, we have except for and we have and . By (6), . From (7), . From we have (i.e., upper bound decreased) because and . Similarly, we derive from that and from that . From the same constraint, we shrink to and to . Finally, shrinks to . By (6), , so by (7), and . By (6), this removes 1 and 3 from . Local reasoning about the decomposition has made the original GCC constraint range consistent.
Proof: We use for the number of variables whose range intersects the set of values, and for the number of variables whose range is a subset of . We first show that if RC fails on the GCC, DC on (6) and BC on (7) and (8) will fail. We derive from [Quimper et al.2005, Lemmas 1 and 2] that RC fails on a GCC if and only if there exists a set of values such that or such that . Suppose first a set such that . The fact that domains are considered as intervals implies that either includes more variable domains than the sum of the upper bounds (like ), or the union of the that are included in lets a hole of unused values in , which implies that there exists an interval such that . So, in any case, there exists an interval in with . By (6) we have whereas the greatest value in the domain of was set to . So BC will fail on . Suppose now that a set is such that . The total number of values taken by variables being equal to , the number of variables with not intersecting is greater than , that is, . Thanks to (7), we know that for any , . So, . The initial domains of variables also tell us that for every in , . Thus, . Successively applying BC on , then on , and so on until will successively increase the minimum of these variables and will lead to a failure on .
We now show that when DC on (6) and BC on (7) and (8) do not fail, it prunes all values that are pruned when enforcing RC on the GCC constraint. Consider a value for some such that does not have any bound support. We derive from [Quimper et al.2005, Lemmas 1 and 6] that a value for a variable does not have a bound support on GCC if and only if there exists a set of values such that either (i) , and is not included in , or (ii) , and intersects . In case (i), contains and the values it contains will be taken by too many variables if is in it. In case (ii), does not contain and its values will be taken by not enough variables if is not in it. Consider case (i): Since DC did not fail on (6), by a similar reasoning as above for detecting failure, we derive that is composed of intervals such that . Consider the interval containing . The greatest value in the initial domain of was , which is exactly the number of variables with range included in without counting because its range is not included in . Thus, (7) forces and (6) prunes value from because by assumption. Consider now case (ii): is such that . The total number of values taken by the variables being equal to , the number of variables with not intersecting is equal to , that is . Thanks to (7), we know that for any , . So, . The initial domains of variables also tell us that for every in , . Thus, . Successively applying BC on , then on , and so on until will increase all and , to the sum of the minimum values of the variables in the right side of each constraint so that . Then, because , BC on will decrease the maximum value of and to their minimum value, BC on will decrease the maximum value of and to their minimum value, and so on until all are forced to the singleton . At this point, (7) forces for every variable with range not included in the interval because that interval is saturated by variables in , for which . By assumption value is not in , so there exists such an interval that contains . Furthermore, intersects , so it is not included in . Therefore, is forced to 0 and (6) prunes from .
There are constraints (6) that can be woken times down the branch of the search tree in , so a total of down the branch. There are constraints (7) which can be woken times each down the branch for a total cost in time down the branch. Thus a total of . There are constraints (8) that can be woken times down the branch. Each propagation takes time to execute for a total of time down the branch. The final complexity down the branch of the search tree is therefore .
Proof: The proof follows that for Theorem 3 except that fixing prunes the bounds of if and only if exactly one bound of the domain of intersects the interval . The complexity reduces to as BC on (3) and (4) is in (see Theorem 2) and BC on (7) and (8) is in (see Theorem 3).
The best known algorithm for BC on GCC runs in time at each call [Quimper et al.2005] and can be awaken times down a branch. This gives a total of , which is greater than the here when . Our decomposition is also interesting because, as we show in the next section, we can use it to combine together propagators.
5 Other global constraints
Many other global constraints that count variables or values can be decomposed in a similar way. For example, the global constraint is satisfied if and only if the variables are a permutation of the variables. A monolithic flow-based propagator for this constraint is given in [Beldiceanu et al.2004]. The following decomposition encodes the Same constraint where , , and :
This decomposition can be obtained by posting decompositions for and and eliminating common sub-expressions (eGCC is an extended form of the GCC constraint in which upper and lower bounds on occurrences of values are replaced by integer variables). This is another argument in favor of decompositions since it allows constraints to share “internal” state through common intermediate variables. Such sharing can increase propagation.
Consider the following example:
If we have for then both and are BC. However, enforcing BC on the decomposition of removes from the domain of and .
In fact, we conjecture that enforcing BC on this decomposition achieves BC on the Same constraint itself. Similar decompositions can be given for other global constraints like NValue and Common.
6 Experimental Results
To test these decompositions, we ran experiments on pseudo-Boolean encodings (PB) of CSPs containing All-Different and Permutation constraints. We used the MiniSat+ 1.13 solver on an Intel Xeon 4 CPU, 2.0 Ghz, 4G RAM with a timeout of seconds for each experiment. Our decompositions contain two types of constraints: Sum constraints like (2) and Member constraints like (1). The Sum constraints is posted directly to the MiniSat+ solver. To encode Member constraints, we use literals for the truth of [Ohrimenko et al.2007], and clauses of the form . This achieves bound consistency (Theorem 2). To increase propagation, we use a direct encoding with literals for the truth of and clauses , . The overall consistency achieved is therefore between BC and RC. We denote this encoding . To explore the impact of small Hall intervals, we also tried , a PB encoding with only those constraints (2) for which . This detects Hall intervals of size at most . Finally, we decomposed All-Different into a clique of binary inequalities, and used a direct encoding to convert this into SAT (denoted ).
Pigeon Hole Problems.
Table 1 gives results on pigeon hole problems (PHP) with pigeons and holes. Our decomposition is both faster and gives a smaller search tree compared to the decomposition. On such problems, detecting large Hall intervals is essential.
|5||30||/ 0.0||28||/ 0.0||4||/ 0.0|
|7||622||/ 0.0||539||/ 0.0||47||/ 0.0||6||/ 0.0|
|9||16735||/ 0.3||18455||/ 0.7||522||/ 0.0||122||/ 0.0||8||/ 0.0|
|11||998927||/ 29.3||665586||/ 44.8||5681||/ 0.3||171||/ 0.0||180||/ 0.0||10||/ 0.1|
|13||-||/ -||-||/ -||13876||/ 0.9||2568||/ 0.2||247||/ 0.1||195||/ 0.1|
|15||-||/ -||-||/ -||1744765||/ 188.6||24109||/ 2.6||1054||/ 0.2||165||/ 0.1|
|17||-||/ -||-||/ -||-||/ -||293762||/ 48.0||8989||/ 1.1||4219||/ 0.6|
|19||-||/ -||-||/ -||-||/ -||107780||/ 21.8||857175||/ 368.0||39713||/ 9.9|
|21||-||/ -||-||/ -||-||/ -||-||/ -||550312||/ 426.2||57817||/ 33.5|
Double-Wheel Graceful Graphs.
The second set of experiments uses double-wheel graceful graphs [Petrie and Smith2003]. We converted the CSP model in [Petrie and Smith2003] into a PB formula. This model has an All-Different constraint on node labels and a Permutation constraint on edge labels. For the Permutation constraint we use (5). We strengthen the decomposition with clauses to ensure that every value appears at least once. Table 2 show that our decomposition outperforms the augmented
decomposition on many instances. Whilst detecting large Hall intervals can greatly reduce search, in some cases the branching heuristics appear to be fooled by the extra variables introduced in the encodings.
Overall these experiments suggest that detecting Hall intervals reduces search significantly, and focusing on small Hall intervals may be best except on problems where large Hall intervals occur frequently.
|3||176||/ 0.1||90||/ 0.1||63||/ 0.1|
|4||30||/ 0.1||14||/ 0.1||212||/ 0.2|
|5||22||/ 0.2||526||/ 0.4||87||/ 0.3||1290||/ 1.7|
|6||1341||/ 1.0||873||/ 0.9||318||/ 0.7||1212||/ 2.9|
|7||2948||/ 3.6||2047||/ 4.2||1710||/ 3.6||1574||/ 4.0||27||/ 0.9|
|8||2418||/ 5.5||724||/ 2.2||643||/ 2.8||368||/ 2.4||3955||/ 19.5|
|9||3378||/ 8.6||1666||/ 5.7||1616||/ 9.0||30||/ 1.8||10123||/ 129.7||405||/ 6.5|
|10||19372||/ 118.3||9355||/ 66.2||14120||/ 85.9||10||/ 2.1||4051||/ 35.0||5709||/ 71.2|
|11||839||/ 5.4||12356||/ 84.2||1556||/ 13.9||14||/ 2.4||7456||/ 105.2||5552||/ 92.7|
7 Other Related Work
The All-Different constraint first appeared in the ALICE constraint programming language [Lauriere1978]. Regin proposed a DC propagator that runs in time [Régin1994]. Leconte gave a RC propagator based on Hall intervals that runs in time [Leconte1996]. Puget then developed a BC propagator also based on Hall intervals that runs in time [Puget1998]. This was later improved by Melhorn and Thiel [Mehlhorn and Thiel2000] and then Lopez-Ortiz et al. [Lopez-Ortiz et al.2003].
The global cardinality constraint, GCC was introduced in the CHARME language [Oplobedu et al.1989]. Regin proposed a DC propagator based on network flow that runs in time [Régin1996]. Katriel and Thiel proposed a BC propagator for the eGCC constraint [Katriel and Thiel2003]. Quimper et al. proved that enforcing DC on the eGCC constraint is NP-hard [Quimper et al.2004]. They also improved the time complexity to enforce DC and gave the first propagator for enforcing RC on GCC.
Many decompositions have been given for a wide range of global constraint. However, decomposition in general tends to hinder propagation. For instance, [Stergiou and Walsh1999] shows that the decomposition of All-Different constraints into binary inequalities hinders propagation. On the other hand, there are global constraints where decompositions have been given that do not hinder propagation. For example, Beldiceanu et al. identify conditions under which global constraints specified as automata can be decomposed into signature and transition constraints without hindering propagation [Beldiceanu et al.2005]. As a second example, many global constraints can be decomposed using Roots and Range which can themselves often be propagated effectively using simple decompositions [Bessiere et al.2005, Bessiere et al.2006a, Bessiere et al.2006b]. As a third example, decompositions of the Regular and Cfg constraints have been given that do not hinder propagation [Quimper and Walsh2006, Quimper and Walsh2007, Quimper and Walsh2008, Bessiere et al.2008, Katsirelos et al.2008]. As a fourth example, decompositions of the Sequence constraint have been shown to be effective [Brand et al.2007]. Finally, the Precedence constraint can be decomposed into ternary constraints without hindering propagation [Walsh2006].
We have shown that some common global constraints like All-Different and GCC can be decomposed into simple arithmetic constraints whilst still maintaining a global view that achieves range or bound consistency. These decompositions are interesting for a number of reasons. First, we can easily incorporate them into other solvers. Second, the decompositions provide other constraints with access to the state of the propagator. Third, these decompositions provide a fresh perspective on propagation of global constraints. For instance, our results suggest that it may pay to focus propagation and nogood learning on small Hall intervals. Finally, these decompositions raise an important question. Are there propagation algorithms that cannot be efficiently simulated using decompositions? In [Bessiere et al.2009], we use circuit complexity to argue that a domain consistency propagator for the All-Different constraint cannot be simulated using a polynomial sized decomposition.
- [Beldiceanu et al.2004] N. Beldiceanu, I. Katriel, and S. Thiel. Filtering algorithms for the same constraint. In 1st Int. Conf. on Integration of AI and OR Techniques in CP, 65–79, 2004.
- [Beldiceanu et al.2005] N. Beldiceanu, I. Katriel, and S. Thiel. Reformulation of Global Constraints Based on Constraints Checkers Filtering algorithms for the same constraint. Constraints, 10(4): 339–362, 2005.
- [Bessiere et al.2005] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan and T. Walsh. The Range and Roots Constraints: Specifying Counting and Occurrence Problems. In 19th Int. Joint Conf. on AI, 60–65. 2005.
- [Bessiere et al.2006a] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan and T. Walsh. The RANGE Constraint: Algorithms and Implementation. In 3rd Int. Conf. on Integration of AI and OR Techniques in CP (CP-AI-OR), 59–73, 2006.
- [Bessiere et al.2006b] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan and T. Walsh. The ROOTS Constraint. In 12th Int. Conf. on Principles and Practices of CP (CP2006), 75–90. 2006.
- [Bessiere et al.2008] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan and T. Walsh. SLIDE: A Useful Special Case of the CARDPATH Constraint. In 18th European Conf. on AI, 475–479. 2008.
- [Bessiere et al.2009] C. Bessiere, G. Katsirelos, N. Narodytska and T. Walsh. Circuit Complexity and Decompositions of Global Constraints. In 21st Int. Joint Conf. on AI. 2009.
- [Brand et al.2007] S. Brand, N. Narodytska, C-G. Quimper, P. Stuckey and T. Walsh. Encodings of the SEQUENCE Constraint. In 13th Int. Conf. on Principles and Practice of CP (CP2007), 210–224. 2007.
- [Katriel and Thiel2003] I. Katriel and S. Thiel. A fast bound consistency for the global cardinality constraint. In 9th Int. Conf. on Principles and Practice of CP (CP2003). 2003.
- [Katsirelos et al.2008] G. Katsirelos, N. Narodytska and T. Walsh. The Weighted CFG Constraint. In 5th Int. Conf. on Integration of AI and OR Techniques in CP (CP-AI-OR), 323–327, 2008.
- [Lauriere1978] J.L. Lauriere. Alice: A language and a program for solving combinatorial problems. Artificial Intelligence, 10:29–127, 1978.
- [Leconte1996] M. Leconte. A bounds-based reduction scheme for constraints of difference. In 2nd Int. Workshop on Constraint-based Reasoning, 1996.
- [Lopez-Ortiz et al.2003] A. Lopez-Ortiz, C.G. Quimper, J. Tromp, and P. van Beek. A fast and simple algorithm for bounds consistency of the alldifferent constraint. In 18th National Conf. on AI. AAAI 2003.
- [Mehlhorn and Thiel2000] K. Mehlhorn and S. Thiel. Faster algorithms for bound-consistency of the sortedness and the alldifferent constraint. In 6th Int. Conf. on Principles and Practice of CP (CP2000), 306–319. 2000.
- [Ohrimenko et al.2007] O. Ohrimenko, P.J. Stuckey, and M. Codish. Propagation = lazy clause generation. In 13th Int. Conf. Principles and Practice of CP (CP2007), 544–558, 2007.
- [Oplobedu et al.1989] A. Oplobedu, J. Marcovitch, and Y. Tourbier. CHARME: Un langage industriel de programmation par contraintes, illustre par une application chez Renault. In 9th Int. Workshop on Expert Systems and their Applications, 1989.
- [Petrie and Smith2003] K.E. Petrie and B.M. Smith. Symmetry breaking in graceful graphs. In 9th Int. Conf. of Principles and Practice of CP (CP2003), 930–934, 2003.
- [Puget1998] J.F. Puget. A fast algorithm for the bound consistency of alldiff constraints. In 15th National Conf. on AI, 359–366. AAAI, 1998.
- [Quimper and Walsh2006] C.-G. Quimper and T. Walsh. Global Grammar Constraints. In 12th Int. Conf. on Principles and Practices of CP (CP2006), 751–755. 2006.
- [Quimper and Walsh2007] C.-G. Quimper and T. Walsh. Decomposing Global Grammar Constraints. In 13th Int. Conf. on Principles and Practices of CP (CP2007), 590–604. 2007.
- [Quimper and Walsh2008] C.-G. Quimper and T. Walsh. Decompositions of Grammar Constraints. In 23rd National Conf. on AI, 1567–1570. AAAI, 2008.
- [Quimper et al.2004] C-.G. Quimper, P. van Beek, A. Lopez-Ortiz, and A. Golynski. Improved algorithms for the global cardinality constraint. In 10th Int. Conf. on Principles and Practice of CP (CP2004). 2004.
- [Quimper et al.2005] C-G. Quimper, A. Golynski, A. López-Ortiz, and P. van Beek. An efficient bounds consistency algorithm for the global cardinality constraint. Constraints, 10(2):115–135, 2005.
- [Régin1994] J-C. Régin. A filtering algorithm for constraints of difference in CSPs. In 12th National Conf. on AI, 362–367. AAAI, 1994.
- [Régin1996] J-C. Régin. Generalized arc consistency for global cardinality constraints. In 13th National Conf. on AI, 209–215. AAAI, 1996.
- [Stergiou and Walsh1999] K. Stergiou and T. Walsh. The Difference All-difference Makes. In 16th Int. Joint Conf. on AI, 414–419. 1999.
- [Walsh2006] T. Walsh. Symmetry Breaking using Value Precedence. In 17th European Conf. on AI, 168–172. 2006.