Propagating Conjunctions of AllDifferent Constraints

04/15/2010 ∙ by Christian Bessiere, et al. ∙ CSIRO UNSW 0

We study propagation algorithms for the conjunction of two AllDifferent constraints. Solutions of an AllDifferent constraint can be seen as perfect matchings on the variable/value bipartite graph. Therefore, we investigate the problem of finding simultaneous bipartite matchings. We present an extension of the famous Hall theorem which characterizes when simultaneous bipartite matchings exists. Unfortunately, finding such matchings is NP-hard in general. However, we prove a surprising result that finding a simultaneous matching on a convex bipartite graph takes just polynomial time. Based on this theoretical result, we provide the first polynomial time bound consistency algorithm for the conjunction of two AllDifferent constraints. We identify a pathological problem on which this propagator is exponentially faster compared to existing propagators. Our experiments show that this new propagator can offer significant benefits over existing methods.



There are no comments yet.


page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Global constraints are a critical factor in the success of constraint programming. They capture patterns that often occur in practice (e.g. “these courses must occur at different times”). In addition, fast propagation algorithms are associated with each global constraint to reason about potential solutions (e.g. “these 4 courses have only 3 time slots between them so, by a pigeonhole argument, the problem is infeasible”). One of the oldest and most useful global constraints is the AllDifferent constraint [Laurière1978]. This specifies that a set of variables takes all different values. Many different algorithms have been proposed for propagating the AllDifferent constraint [Régin1994, Leconte1996, Puget1998]. Such propagators can have a significant impact on our ability to solve problems [Stergiou & Walsh1999].

Problems often contain multiple AllDifferent constraints (e.g. “The CS courses must occur at different times, as must the IT courses. In addition, CS and IT have several courses in common”). Currently, constraint solvers ignore information about the overlap between multiple constraints (except for the limited communication provided by the domains of common variables). Here, we show the benefits of reasoning about such overlap. This is a challenging problem as finding a solution to just two AllDifferent constraints is NP-hard [Kutz et al.2008] and existing approaches to deal with such overlaps require exponential space [Lardeux et al.2008]. Our approach is to focus on domains that are ordered, as often occurs in practice. For example in our time-tabling problem, values might represent times (which are naturally ordered). In such cases, domains can be compactly represented by intervals. Propagation algorithms can narrow such intervals using the notion of bound consistency. Our main result is to prove we can enforce bound consistency on two AllDifferent constraints in polynomial time. Our algorithm exploits a connection with matching on bipartite graphs. In particular, we consider simultaneous matchings. By generalizing Hall’s theorem, we identify a necessary and sufficient condition for the existence of such a matching and show that the this problem is polynomial for convex graphs.

2 Formal background

Constraint programming. We use capitals for variables and lower case for values. Values range over 1 to . We write for the domain of values for , () for the smallest (greatest) value in . A global constraint is one in which the number of variables is a parameter. For instance, ensures that for any . Constraint solvers prune search by enforcing properties like domain consistency. A constraint is domain consistent (DC) iff when a variable is assigned any value in its domain, there are compatible values in the domains of all other variables. Such an assignment is a support. A constraint is bound consistent (BC) iff when a variable is assigned the minimum or maximum value in its domain, there are compatible values between the minimum and maximum domain value for all other variables. Such an assignment is a bound support. A constraint is bound disentailed iff no possible assignment is a bound support.

Graph Theory. Solutions of AllDifferent correspond to matchings in a bipartite variable/value graph [Régin1994].

Definition 1.

The graph is bipartite if partitions into 2 classes, and , such that every edge has ends in different classes.

Definition 2.

Let be a bipartite graph. A matching that covers is a set of pairwise non-adjacent edges such that every vertex from is incident to exactly one edge from .

We will consider simultaneous matchings on bipartite graphs(sim-BM[Kutz et al.2008].

Definition 3.

An overlapping bipartite graph is a bipartite graph and two sets and such that , , and .

Definition 4.

Let and , be an overlapping bipartite graph. A simultaneous matching is a set of edges such that and are matchings that cover and , respectively.

In the following, we use the convention that a set of vertices is a subset of the partition . We write for the neighborhood of , , and . sim-BM problems frequently occur in real world applications like production scheduling and timetabling. We introduce here a simple exam timetabling problem that will serve as a running example.

Running example.

We have 7 exams offered over 5 days and 2 students. The first student has to take the first 5 exams and the second student has to take the last 5 exams. Due to the availability of examiners, not every exam is offered each day. For example, the first exam cannot be on the last day of the week. Only one exam can be sat each day. This problem can be encoded as a sim-BM problem. represents the exams and contains vertices to . represents the days and contains the vertices 1 to 5. and . We connect vertices between and to encode the availability restrictions of the examiners. The adjacency matrix of the graph is as follows:

Finding a solution for this sim-BM problem is equivalent to solving the timetabling problem. ∎

3 Simultaneous Bipartite Matching

We now consider how to find a simultaneous matching. Unfortunately, this problem is NP-complete in general [Kutz et al.2008]. Our contribution here is to identify a necessary and sufficient condition for the existence of a simultaneous matching based on an extension of Hall’s theorem [Hall1935]. We use this to show that a simultaneous matching on a convex bipartite graph can be found in polynomial time.

In the following, let be the subgraph of the overlapping bipartite graph that is induced by choosing an edge to be in the simultaneous matching. If then . If (and symmetrically if ) then . If is a sim-BM in , then is a sim-BM in . Since the edge is implied throughout, we write . In addition, we write .

3.1 Extension of Hall’s Theorem

Hall’s theorem provides a necessary and sufficient condition for the existence of a perfect matching in a bipartite graph.

Theorem 1 (Hall Condition [Hall1935]).

Let such that . There exists a perfect matching iff for .

Interestingly we only need a small adjustment for simultaneous matching.

Theorem 2 (Simultaneous Hall Condition (sim-HC)).

Let and sets , be an overlapping bipartite graph. There exists a sim-BM, iff for .


We prove sim-HC by induction on . When , the statement holds. Let .

If or then sim-HC reduces to the condition of Hall’s theorem and the statement is true for that reason. Hence, we assume and . We show that there is an edge that can be chosen for a simultaneous matching and the graph will satisfy sim-HC. Following [Diestel2006], page , we consider two cases. The first case when all subsets of satisfy the strict sim-HC, namely, and the second case when we have an equality.

Case 1. Suppose for all sets . As we select any edge and construct the graph (the case is symmetric). For any set we consider two cases: either or . In the first case, the neighborhood of is the same in and , so the sim-HC holds for . In the case that , then either is a shared neighbor of and , which means that but by construction, or is a neighbor of but not of . Therefore . But by construction. In either case, for any set in . By the inductive hypothesis there exists a simultaneous matching in it.

Case 2. Suppose that there exists a set such that . Let such that , and

There exists a simultaneous matching in by the inductive hypothesis. We claim that the sim-HC holds also for . This implies that, by the inductive hypothesis, there exists a simultaneous matching in . Suppose there exists a set that violates the sim-HC in .

We denote as the neighborhood of in and as the neighborhood of in . We know that the sets and are disjoint. We observe that , because by construction of . Moreover . By construction of , we have that , and . Hence, , where . Similarly, and . Therefore, . Finally, we have that

Hence violates the sim-HC in , a contradiction. Therefore, there exists a simultaneous matching in .

Let be a simultaneous matching in . For any edge , we construct the graph and show that and for any .

Let be an edge in . By construction of , we have that . Hence, the construction of leaves the size of the same as in . Moreover, , , .

Consider the remaining options for the edge . If ( is similar) then can be in , so is a shared vertex with . There are two cases to consider: and . In the first case, the construction of leaves the size of the same as because and can share vertices with . In the latter case, , but . Hence, in both cases. Therefore, the sim-HC holds for any . ∎

Running example.

In our running example , , and . It is easy to check that the simultaneous Hall condition holds for all subsets of the partition .

Note that Theorem 2 does not give a polynomial time method to decide if a simultaneous matching exists. Verifying that sim-HC holds requires checking the exponential number of subsets of .

3.2 Removing edges

To build a propagator, we consider how to detect edges that cannot appear in any simultaneous matching.

Definition 5.

Let and sets , be an overlapping bipartite graph. A set , , is

a simultaneous Hall set iff


an almost simultaneous Hall set iff


a loose set iff


Theorem 3.

and sets , be an overlapping bipartite graph. Each edge , and can be extended to a matching that covers and iff

  1. for each set :

  2. for each simultaneous Hall set :

    1. if then

    2. if then

    3. if then

    4. if then

  3. for each almost simultaneous Hall set :

    1. if then


Soundness. The soundness of Rule 1a follows from Theorem 2. Let be an edge that we want to extend to a matching. Suppose that violates one of the rules for a sim-HallSet or an a-sim-HallSet in . We show that if is selected to be in a matching, then fails sim-HC in .

Rule 2a: If violates Rule 2a for a sim-HallSet then and , so the sim-HC is violated for in .

Rule 2b: If violates Rule 2b for a sim-HallSet then and so the sim-HC is violated for in .

Rule 2c: Symmetric to Rule 2b.

Rule 2d: If violates Rule 2d for a sim-HallSet then so the sim-HC is violated for in .

Rule 3a: If violates Rule 3a for an a-sim-HallSet then and , so and the sim-HC is violated for in .

Completeness. Second, we show that Rules 2a3a are complete. We will show that we can use any edge in a maching by showing that the graph satisfies the sim-HC, thus has a sim-BM.

Suppose there is a set that violates the sim-HC in but not in so that




Note that and . Hence, and .

There are three cases to consider for in , when is a loose set, a sim-HallSet and an a-sim-HallSet in . These cases are similar, so we consider only the most difficult case. Let be an a-sim-HallSet in . If then by Rule 3a. Hence , so and therefore (1) and (2) cannot both be true.

If ( is symmetric) then or its complement. In the first case , while in the second . In both cases, so (1) and (2) cannot both be true. ∎

Running example.

Consider again our running example. We show that Rules 2a-3a remove every edge that can not be extended to a matching. Consider the set . This is a sim-HallSet as , and . Hence, by Rule 2d we prune from and by Rule 2a we prune from and . Now consider the set . This is an a-sim-HallSet. By Rule 3a we prune from . The set is also an a-sim-HallSet and, by Rule 3a, we prune from . Next consider the set which is a sim-HallSet. By Rules 2b and 2c we prune from , , and . Now, is a sim-HallSet and is pruned from by Rule 2d. Finally, from the simultaneous Hall set , we prune from using Rule  2c and we are now at the fixpoint.

4 The overlapping AllDifferent constraint

We now uses these results to build a propagator.

Definition 6.

where , , holds iff and hold simultaneously .

Enforcing on the OverlappingAllDiff constraint is -hard [Bessiere et al.2007]. We consider instead enforcing just . This relaxation is equivalent to the simultaneous matching problem on a bipartite convex variable-value graph. Our main result is an algorithm that enforces on the OverlappingAllDiff constraint in time. The algorithm is based on the decomposition of the OverlappingAllDiff constraint into a set of arithmetic constraints derived from Rules 2b3a. It is inspired by a decomposition of AllDifferent [Bessiere et al.2009]. As there, we introduce Boolean variables , to represent whether takes a value in the interval and the variables , and to represent bounds on the number of variables from , and that may take values in the interval . We introduce the following set of constraints for , and :


We also introduce a dummy variable

to simplify the following lemma and theorems.

Lemma 1.

Consider a sequence of values . Enforcing on (8) ensures .


For every such that , constraint (8) ensures that . For every such that constraint (8) ensures that . The left side of each inequality can be substituted into the right side of another inequality until one obtains . ∎

Theorem 4.

Enforcing on (3)-(10) detects bound disentailment of OverlappingAllDiff in time but does not enforce on OverlappingAllDiff.


First we derive useful upper bounds for the variables . Consider a set and an interval such that . Let be a set of intervals that tightly contain variables from so that , be a set of intervals that tightly contain variables from so that , and are intersection intervals between intervals and , i.e., .

We first remove all intervals () that are completely inside an interval (). For any of these intervals ( is similar) there exists an intersection interval such that . We denote the set of removed intervals . The remaining intervals are , and . For any interval , (9) ensures that . Similarly for an interval , we have .

We sort the union of remaining intervals and by their lower bounds and list them as semi-open intervals . Using the sequence where indicates a repetition of times the same sequence, Lemma 1 provides the inequality . Substituting the inequalities that we already defined, we obtain .

For any removed interval we have or . We reintegrate all removed intervals into the inequation to get . Note that