arXiv is now an independent nonprofit! Learn more
License: arXiv.org perpetual non-exclusive license
arXiv:0903.0211v1 [cs.AI] 02 Mar 2009

Range and Roots:
Two Common Patterns
for Specifying and Propagating
Counting and Occurrence ConstraintsThanks: This paper is a compilation and an extension of [10], [11], and [12]. The first author was supported by the ANR project ANR-06-BLAN-0383-02.

Christian Bessiere Affiliation: LIRMM, CNRS and U. Montpellier Affiliation: Montpellier, France Email: bessiere@lirmm.fr    Emmanuel Hebrard Affiliation: 4C and UCC Affiliation: Cork, Ireland Email: e.hebrard@4c.ucc.ie    Brahim Hnich Affiliation: Izmir University of Economics Affiliation: Izmir, Turkey Email: brahim.hnich@ieu.edu.tr    Zeynep Kiziltan Affiliation: Department of Computer Science Affiliation: Univ. di Bologna, Italy Email: zeynep@cs.unibo.it    Toby Walsh Affiliation: NICTA and UNSW Affiliation: Sydney, Australia Email: tw@cse.unsw.edu.au
Keywords: Constraint programming, constraint satisfaction, global constraints, open global constraints, decompositions
Abstract

We propose Range and Roots which are two common patterns useful for specifying a wide range of counting and occurrence constraints. We design specialised propagation algorithms for these two patterns. Counting and occurrence constraints specified using these patterns thus directly inherit a propagation algorithm. To illustrate the capabilities of the Range and Roots constraints, we specify a number of global constraints taken from the literature. Preliminary experiments demonstrate that propagating counting and occurrence constraints using these two patterns leads to a small loss in performance when compared to specialised global constraints and is competitive with alternative decompositions using elementary constraints.

1 Introduction

Global constraints are central to the success of constraint programming [28]. Global constraints allow users to specify patterns that occur in many problems, and to exploit efficient and effective propagation algorithms for pruning the search space. Two common types of global constraints are counting and occurrence constraints. Occurrence constraints place restrictions on the occurrences of particular values. For instance, we may wish to ensure that no value used by one set of variables occurs in a second set. Counting constraints, on the other hand, restrict the number of values or variables meeting some condition. For example, we may want to limit the number of distinct values assigned to a set of variables. Many different counting and occurrences constraints have been proposed to help model a wide range of problems, especially those involving resources (see, for example, [25, 4, 26, 3, 5]).

In this paper, we will show that many such constraints can be specified by means of two new global constraints, Range and Roots  together with some standard elementary constraints like subset and set cardinality. These two new global constraints capture the familiar notions of image and domain of a function. Understanding such notions does not require a strong background in constraint programming. A basic mathematical background is sufficient to understand these constraints and use them to specify other global constraints. We will show, for example, that Range and Roots are versatile enough to allow specification of open global constraints, a recent kind of global constraints for which the set of variables involved is not known in advance.

Specifications made with Range and Roots constraints are executable. We show that efficient propagators can be designed for the Range and Roots constraints. We give an efficient algorithm for propagating the Range constraint based on a flow algorithm. We also prove that it is intractable to propagate the Roots constraint completely. We therefore propose a decomposition of the Roots constraint that can propagate it partially in linear time. This decomposition does not destroy the global nature of the Roots constraint as in many situations met in practice, it prunes all possible values. The proposed propagators can easily be incorporated into a constraint toolkit.

We show that specifying a global constraint using Range and Roots provides us with an reasonable method to propagate counting and occurrence constraints. There are three possible situations. In the first, the global nature of the Range and Roots constraints is enough to capture the global nature of the given counting or occurrence constraint, and propagation is not hindered. In the second situation, completely propagating the counting or occurrence constraint is NP-hard. We must accept some loss of propagation if propagation is to be tractable. Using Range and Roots is then one means to propagate the counting or occurrence constraint partially. In the third situation, the global constraint can be propagated completely in polynomial time but using Roots and Range hinders propagation. In this case, if we want to achieve full propagation, we need to develop a specialised propagation algorithm.

We also show that decomposing occurrence constraints and counting constraints using the Range and Roots constraints performs well in practice. Our experiments on random CSPs and a on real world problem from CSPLib demonstrate that propagating counting and occurrence constraints using the Range and Roots constraints leads to a small loss in performance when compared to specialised global constraints and is competitive with alternative decompositions into more elementary constraints.

The rest of the paper is organised as follows. Section 2 gives the formal background. Section 3 defines the Range and Roots constraints and gives a couple of examples to illustrate how global constraints can be decomposed using these two constraints. In Section 4, we propose a polynomial algorithm for the Range constraint. In Section 5, we give a complete theoretical analysis of the Roots constraint and our decomposition of it, and we discuss implementation details. Section 6 gives many examples of counting and occurrence constraints that can be specified using the Range and Roots constraints. Experimental results are presented in Section 7. Finally, we end with conclusions in Section 8.

2 Formal background

A constraint satisfaction problem consists of a set of variables, each with a finite domain of values, and a set of constraints specifying allowed combinations of values for subsets of variables. We use capitals for variables (e.g. XX, YY and SS), and lower case for values (e.g. vv and ww). We write D(X){D}(X) for the domain of a variable XX. A solution is an assignment of values to the variables satisfying the constraints. A variable is ground when it is assigned a value. We consider both integer and set variables. A set variable SS is often represented by its lower bound lb(S)lb(S) which contains the definite elements (that must belong to the set) and an upper bound ub(S)ub(S) which also contains the potential elements (that may or may not belong to the set).

Constraint solvers typically explore partial assignments enforcing a local consistency property using either specialised or general purpose propagation algorithms. Given a constraint CC, a bound support on CC is a tuple that assigns to each integer variable a value between its minimum and maximum, and to each set variable a set between its lower and upper bounds which satisfies CC. A bound support in which each integer variable is assigned a value in its domain is called a hybrid support. If CC involves only integer variables, a hybrid support is a support. A value (resp. set of values) for an integer variable (resp. set variable) is bound or hybrid consistent with CC iff there exists a bound or hybrid support assigning this value (resp. set of values) to this variable. A constraint CC is bound consistent (BC) iff for each integer variable XiX_{i}, its minimum and maximum values belong to a bound support, and for each set variable SjS_{j}, the values in ub(Sj)ub(S_{j}) belong to SjS_{j} in at least one bound support and the values in lb(Sj)lb(S_{j}) are those from ub(Sj)ub(S_{j}) that belong to SjS_{j} in all bound supports. A constraint CC is hybrid consistent (HC) iff for each integer variable XiX_{i}, every value in D(Xi)D(X_{i}) belongs to a hybrid support, and for each set variable SjS_{j}, the values in ub(Sj)ub(S_{j}) belong to SjS_{j} in at least one hybrid support, and the values in lb(Sj)lb(S_{j}) are those from ub(Sj)ub(S_{j}) that belong to SjS_{j} in all hybrid supports. A constraint CC involving only integer variables is generalised arc consistent (GAC) iff for each variable XiX_{i}, every value in D(Xi)D(X_{i}) belongs to a support. If all variables in CC are integer variables, hybrid consistency reduces to generalised arc consistency, and if all variables in CC are set variables, hybrid consistency reduces to bound consistency.

To illustrate these different concepts, consider the constraint C(X1,X2,T)C(X_{1},X_{2},T) that holds iff the set variable TT is assigned exactly the values used by the integer variables X1X_{1} and X2X_{2}. Let D(X1)={1,3}D(X_{1})=\{1,3\}, D(X2)={2,4}D(X_{2})=\{2,4\}, lb(T)={2}lb(T)=\{2\} and ub(T)={1,2,3,4}ub(T)=\{1,2,3,4\}. BC does not remove any value since all domains are already bound consistent (value 2 was considered as possible for X1X_{1} because BC deals with bounds). On the other hand, HC removes 4 from D(X2)D(X_{2}) and from ub(T)ub(T) as there does not exist any tuple satisfying CC in which X2X_{2} does not take value 2.

We will compare local consistency properties applied to (sets of) logically equivalent constraints, c1c_{1} and c2c_{2}. As in [17], a local consistency property Φ\Phi on c1c_{1} is as strong as Ψ\Psi on c2c_{2} iff, given any domains, if Φ\Phi holds on c1c_{1} then Ψ\Psi holds on c2c_{2}; Φ\Phi on c1c_{1} is stronger than Ψ\Psi on c2c_{2} iff Φ\Phi on c1c_{1} is as strong as Ψ\Psi on c2c_{2} but not vice versa; Φ\Phi on c1c_{1} is equivalent to Ψ\Psi on c2c_{2} iff Φ\Phi on c1c_{1} is as strong as Ψ\Psi on c2c_{2} and vice versa; Φ\Phi on c1c_{1} is incomparable to Ψ\Psi on c2c_{2} iff Φ\Phi on c1c_{1} is not as strong as Ψ\Psi on c2c_{2} and vice versa.

A total function \mathcal{F} from a source set 𝒮\mathcal{S} into a target set 𝒯\mathcal{T} is denoted by :𝒮𝒯\mathcal{F}:\mathcal{S}\longrightarrow\mathcal{T}. The set of all elements in 𝒮\mathcal{S} that have the same image j𝒯j\in\mathcal{T} is 1(j)={i:(i)=j}\mathcal{F}^{-1}(j)=\{i:\mathcal{F}(i)=j\}. The image of a set S𝒮{S}\subseteq\mathcal{S} under \mathcal{F} is (S)=iS(i)\mathcal{F}({S})=\bigcup_{i\in{S}}\mathcal{F}(i), whilst the domain of a set T𝒯{T}\subseteq\mathcal{T} under \mathcal{F} is 1(T)=jT1(j)\mathcal{F}^{-1}({T})=\bigcup_{j\in{T}}\mathcal{F}^{-1}(j). Throughout, we will view a set of integer variables, X1X_{1} to XnX_{n} as a function 𝒳:{1,..,n}i=1i=n𝒟(Xi)\mathcal{X}:\{1,..,n\}\longrightarrow\bigcup_{i=1}^{i=n}\mathcal{D}(X_{i}). That is, 𝒳(i)\mathcal{X}(i) is the value of XiX_{i}.

3 Two useful patterns: Range and Roots

Many counting and occurrence constraints can be specified using simple non-global constraints over integer variables (like XmX\leq m), simple non-global constraints over set variables (like S1S2S_{1}\subseteq S_{2} or |S|=k|S|=k) available in most constraint solvers, and two special global constraints acting on sequences of variables: Range and Roots. Range captures the notion of image of a function and Roots captures the notion of domain. Specification with Range and Roots is executable. It permits us to decompose other global constraints into more primitive constraints.

Given a function 𝒳\mathcal{X} representing a set of integer variables, X1X_{1} to XnX_{n}, the Range constraint holds iff a set variable TT is the image of another set variable SS under 𝒳\mathcal{X}.

Range([X1,..,Xn],S,T)iffT=𝒳(S)(that is,T={Xi|iS})\mbox{\sc Range}([X_{1},..,X_{n}],S,T)\ \ \mbox{\rm iff}\ \ T=\mathcal{X}({S})\ \ (\textrm{that is},T=\{X_{i}~|~i\in S\})

The Roots constraint holds iff a set variable SS is the domain of the another set variable TT under 𝒳\mathcal{X}.

Roots([X1,,Xn],S,T)iffS=𝒳1(T)(that is,S={i|XiT})\mbox{\sc Roots}([X_{1},\ldots,X_{n}],S,T)\ \mbox{\rm iff}\ \ {S}=\mathcal{X}^{-1}({T})\ \ (\textrm{that is},S=\{i~|~X_{i}\in T\})

Range and Roots are not exact inverses. A Range constraint can hold, but the corresponding Roots constraint may not, and vice versa. For instance, Range([1,1],{1},{1})\mbox{\sc Range}([1,1],\{1\},\{1\}) holds but not Roots([1,1],{1},{1})\mbox{\sc Roots}([1,1],\{1\},\{1\}) since 𝒳1(1)={1,2}\mathcal{X}^{-1}(1)=\{1,2\}, and Roots([1,1,1],{1,2,3},{1,2})\mbox{\sc Roots}([1,1,1],\{1,2,3\},\{1,2\}) holds but not Range([1,1,1],{1,2,3},{1,2})\mbox{\sc Range}([1,1,1],\{1,2,3\},\{1,2\}) as no XiX_{i} is assigned to 22.

Before showing how to propagate Range and Roots efficiently, we give two examples that illustrate how some counting and occurrence global constraints from [2] can be specified using Range and Roots.

The NValue constraint counts the number of distinct values used by a sequence of variables [22, 8, 7]. NValue([X1,..,Xn],N)\mbox{\sc NValue}([X_{1},..,X_{n}],N) holds iff N=|{Xi| 1in}|N=|\{X_{i}\ |\ 1\leq i\leq n\}|. A way to implement this constraint is with a Range constraint:

NValue([X1,..,Xn],N)iff\displaystyle\mbox{\sc NValue}([X_{1},..,X_{n}],N)\ \ \mbox{\rm iff}
Range([X1,..,Xn],{1,..,n},T) and |T|=N\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},T)\ \and\ |T|=N

The AtMost constraint is one of the oldest global constraints [32]. The AtMost constraint puts an upper bound on the number of variables using a particular value. AtMost([X1,..,Xn],d,N)\mbox{\sc AtMost}([X_{1},..,X_{n}],d,N) holds iff |{i|Xi=d}|N|\{i\ |\ X_{i}=d\}|\leq N. It can be decomposed using a Roots constraint.

AtMost([X1,..,Xn],d,N)iff\displaystyle\mbox{\sc AtMost}([X_{1},..,X_{n}],d,N)\ \ \mbox{\rm iff}
Roots([X1,..,Xn],S,{d}) and |S|N\displaystyle\mbox{\sc Roots}([X_{1},..,X_{n}],S,\{d\})\ \and\ |S|\leq N

These two examples show that it can be quite simple to decompose global constraints using Range and Roots. As we will show later, some other global constraints will require the use of both Range and Roots in the same decomposition. The next sections show how Range and Roots can be propagated efficiently.

4 Propagating the Range constraint

Enforcing hybrid consistency on the Range constraint is polynomial. This can be done using a maximum network flow problem. In fact, the Range constraint can be decomposed using a global cardinality constraint (Gcc) for which propagators based on flow problems already exist [26, 24]. But the Range constraint does not need the whole power of maximum network flow problems, and thus HC can be enforced on it at a lower cost than that of calling a Gcc propagator. In this section, we propose an efficient way to enforce HC on Range. To simplify the presentation, the use of the flow is limited to a constraint that performs only part of the work needed for enforcing HC on Range. This constraint, that we name Occurs([X1,,Xn],T)\mbox{\sc Occurs}([X_{1},\ldots,X_{n}],T), ensures that all the values in the set variable TT are used by the integer variables X1X_{1} to XnX_{n}:

Occurs([X1,,Xn],T)iffT𝒳({1..n})(that is,T{Xi|i1..n})\mbox{\sc Occurs}([X_{1},\ldots,X_{n}],T)\ \ \mbox{\rm iff}\ \ T\subseteq\mathcal{X}({\{1..n\}})\ \ (\textrm{that is},T\subseteq\{X_{i}~|~i\in 1..n\})

We first present an algorithm for achieving HC on Occurs (Section 4.1), and then use this to propagate the Range constraint (Section 4.2).

4.1 Hybrid consistency on Occurs

We achieve HC on Occurs([X1,,Xn],T)\mbox{\sc Occurs}([X_{1},\ldots,X_{n}],T) using a network flow.

4.1.1 Building the network flow

We use a unit capacity network [1] in which capacities between two nodes can only be 0 or 1. This is represented by a directed graph where an arc from node xx to node yy means that a maximum flow of 1 is allowed between xx and yy while the absence of an arc means that the maximum flow allowed is 0. The unit capacity network GC=(N,E)G_{C}=(N,E) of the constraint C=Occurs([X1,,Xn],T)C=\mbox{\sc Occurs}([X_{1},\ldots,X_{n}],T) is built in the following way. N={s}N1N2{t}N=\{s\}\cup N_{1}\cup N_{2}\cup\{t\}, where ss is a source node, tt is a sink node, N1={v|vD(Xi)}N_{1}=\{v~|~v\in\bigcup D(X_{i})\} and N2={zv|vD(Xi)}{xi|i[1..n]}N_{2}=\{z_{v}~|~v\in\bigcup D(X_{i})\}\cup\{x_{i}~|~i\in[1..n]\}. The set of arcs EE is as follows:

E=({s}×N1){(v,zv),vlb(T)}{(v,xi)|vD(Xi)}(N2×{t})E=(\{s\}\times N_{1})\cup\{(v,z_{v}),\forall v\notin lb(T)\}\cup\{(v,x_{i})~|~v\in D(X_{i})\}\cup(N_{2}\times\{t\})

GCG_{C} is quadripartite, i.e., E({s}×N1)(N1×N2)(N2×{t})E\subseteq(\{s\}\times N_{1})\cup(N_{1}\times N_{2})\cup(N_{2}\times\{t\}). In Fig. 1, we depict the network GCG_{C} of the constraint C=Occurs([X1,X2,X3],T)C=\mbox{\sc Occurs}([X_{1},X_{2},X_{3}],T) with D(X1)={1,2}D(X_{1})=\{1,2\}, D(X2)={2,3,4}D(X_{2})=\{2,3,4\}, D(X3)={3,4}D(X_{3})=\{3,4\}, lb(T)={3,4}lb(T)=\{3,4\} and ub(T)={1,2,3,4}ub(T)=\{1,2,3,4\}. The intuition behind this graph is that when a flow uses an arc from a node vv to a node xix_{i} this means that XiX_{i} is assigned vv, and when a flow uses the arc (v,zv)(v,z_{v}) this means that vv is not necessarily used by the XiX_{i}’s.11 1 Note that in our presentation of the graph, the edges go from the nodes representing the values to the nodes representing the variables. This is the opposite to the direction used in the presentation of network flows for propagators of the AllDifferent or Gcc constraints [25, 26]. In Fig. 1 nodes 3 and 4 are linked only to nodes x2x_{2} and x3x_{3}, that is, values 3 and 4 must necessarily be taken by one of the variables XiX_{i} (3 and 4 belong to lb(T)lb(T)). On the contrary, nodes 1 and 2 are also linked to nodes z1z_{1} and z2z_{2} because values 1 and 2 do not have to be taken by a XiX_{i} (they are not in lb(T)lb(T)).

Refer to caption
Figure 1: Unit capacity network of the constraint C=Occurs([X1,X2,X3],T)C=\mbox{\sc Occurs}([X_{1},X_{2},X_{3}],T) with D(X1)={1,2}D(X_{1})=\{1,2\}, D(X2)={2,3,4}D(X_{2})=\{2,3,4\}, D(X3)={3,4}D(X_{3})=\{3,4\}, lb(T)={3,4}lb(T)=\{3,4\} and ub(T)={1,2,3,4}ub(T)=\{1,2,3,4\}. Arcs are directed from left to right.

In the particular case of unit capacity networks, a flow is any set EEE^{\prime}\subseteq E: any arc in EE^{\prime} is assigned 1 and the arcs in EEE\setminus E^{\prime} are assigned 0. A feasible flow from ss to tt in GCG_{C} is a subset EfE_{f} of EE such that nN{s,t}\forall n\in N\setminus\{s,t\} the number of arcs of EfE_{f} entering nn is equal to the number of arcs of EfE_{f} going out of nn, that is, |{(n,n)Ef}|=|{(n,n′′)Ef}||\{(n^{\prime},n)\in E_{f}\}|=|\{(n,n^{\prime\prime})\in E_{f}\}|. The value of the flow EfE_{f} from ss to tt, denoted val(Ef,s,t)val(E_{f},s,t), is val(Ef,s,t)=|{n|(s,n)Ef}|val(E_{f},s,t)=|\{n~|~(s,n)\in E_{f}\}|. A maximum flow from ss to tt in GCG_{C} is a feasible flow EME_{M} such that there does not exist a feasible flow EfE_{f}, with val(Ef,s,t)>val(EM,s,t)val(E_{f},s,t)>val(E_{M},s,t). A maximum flow for the network of Fig. 1 is given in Fig. 2.

Refer to caption
Figure 2: A maximum flow for the network of Fig. 1. Bold arcs are those that belong to the flow. Arcs are directed from left to right.

By construction a feasible flow cannot have a value greater than |N1||N_{1}| and cannot contain two arcs entering a node xix_{i} from N2N_{2}. Hence, we can define a function φ\varphi linking feasible flows and partial instantiations on the XiX_{i}’s. Given any feasible flow EfE_{f} from ss to tt in GCG_{C}, φ(Ef)={(Xi,v)|(v,xi)Ef}\varphi(E_{f})=\{(X_{i},v)~|~(v,x_{i})\in E_{f}\}. The maximum flow in Fig. 2 corresponds to the instantiation X2=4,X3=3X_{2}=4,X_{3}=3. The way GCG_{C} is built induces the following theorem.

Theorem 1

Let GC=(N,E)G_{C}=(N,E) be the capacity network of a constraint C=Occurs([X1,,Xn],T)C=\mbox{\sc Occurs}([X_{1},\ldots,X_{n}],T).

  1. 1.

    A value vv in the domain D(Xi)D(X_{i}) for some i[1..n]i\in[1..n] is HC iff there exists a flow EfE_{f} from ss to tt in GCG_{C} with val(Ef,s,t)=|N1|val(E_{f},s,t)=|N_{1}| and (v,xi)Ef(v,x_{i})\in E_{f}

  2. 2.

    If the XiX_{i}’s are HC, TT is HC iff ub(T)iD(Xi)ub(T)\subseteq\bigcup_{i}D(X_{i})

Proof. (1.\Rightarrow) Let II be a solution for CC with (Xi,v)I(X_{i},v)\in I. Build the following flow HH: Put (v,xi)(v,x_{i}) in HH; wI[T],wv\forall w\in I[T],w\neq v, take a variable XjX_{j} such that (Xj,w)I(X_{j},w)\in I (we know there is at least one since II is solution), and put (w,xj)(w,x_{j}) in HH; wI[T],wv\forall w^{\prime}\notin I[T],w^{\prime}\neq v, add (w,zw)({w^{\prime}},z_{w^{\prime}}) to HH. Add to HH the edges from ss to N1N_{1} and from N2N_{2} to tt so that we obtain a feasible flow. By construction, all wN1w\in N_{1} belong to an edge of HH. So, val(H,s,t)=|N1|val(H,s,t)=|N_{1}| and HH is a maximum flow with (v,xi)H(v,x_{i})\in H.

(1.\Leftarrow) Let EME_{M} be a flow from ss to tt in GCG_{C} with (v,xi)EM(v,x_{i})\in E_{M} and val(EM,s,t)val(E_{M},s,t) =|N1|=|N_{1}|. By construction of GCG_{C}, we are guaranteed that all nodes in N1N_{1} belong to an arc in EM(N1×N2)E_{M}\cap(N_{1}\times N_{2}), and that for every value wlb(T)w\in lb(T), {y|(w,y)E}{xi|i[1..n]}\{y~|~(w,y)\in E\}\subseteq\{x_{i}~|~i\in[1..n]\}. Thus, for each wlb(T),Xj|(Xj,w)φ(EM)w\in lb(T),\exists X_{j}~|~(X_{j},w)\in\varphi(E_{M}). Hence, any extension of φ(EM)\varphi(E_{M}) where each unassigned XjX_{j} takes any value in D(Xj)D(X_{j}) and T=lb(T)T=lb(T) is a solution of CC with Xi=vX_{i}=v.

(2.\Rightarrow) If TT is HC, all values in ub(T)ub(T) appear in at least one solution tuple. Since CC ensures that Ti{Xi}T\subseteq\bigcup_{i}\{X_{i}\}, ub(T)ub(T) cannot contain a value appearing in none of the D(Xi)D(X_{i}).

(2.\Leftarrow) Let ub(T)iD(Xi)ub(T)\subseteq\bigcup_{i}D(X_{i}). Since all XiX_{i}’s are HC, we know that each value vv in iD(Xi)\bigcup_{i}D(X_{i}) is taken by some XiX_{i} in at least one solution tuple II. Build the tuple II^{\prime} so that I[Xi]=I[Xi]I^{\prime}[X_{i}]=I[X_{i}] for each i[1..n]i\in[1..n] and I[T]=I[T]{v}I^{\prime}[T]=I[T]\cup\{v\}. II^{\prime} is still solution of CC. So, ub(T)ub(T) is as tight as it can be wrt HC. In addition, since all XiX_{i}’s are HC, this means that in every solution tuple II, for each vlb(T)v\in lb(T) there exists ii such that I[Xi]=vI[X_{i}]=v. So, lb(T)lb(T) is HC. \Box

Following Theorem 1, we need a way to check which edges belong to a maximum flow. Residual graphs are useful for this task. Given a unit capacity network GCG_{C} and a maximal flow EME_{M} from ss to tt in GCG_{C}, the residual graph RGC(EM)=(N,ER)R_{G_{C}}(E_{M})=(N,E_{R}) is the directed graph obtained from GCG_{C} by reversing all arcs belonging to the maximum flow EME_{M}; that is, ER={(x,y)EEM}{(y,x)|(x,y)EEM}E_{R}=\{(x,y)\in E\setminus E_{M}\}\cup\{(y,x)~|~(x,y)\in E\cap E_{M}\}. Given the network GCG_{C} of Fig. 1 and the maximum flow EME_{M} of Fig. 2, RGC(EM)R_{G_{C}}(E_{M}) is depicted in Fig. 3. Given a maximum flow EME_{M} from ss to tt in GCG_{C}, given (x,y)N1×N2EEM(x,y)\in N_{1}\times N_{2}\cap E\setminus E_{M}, there exists a maximum flow containing (x,y)(x,y) iff (x,y)(x,y) belongs to a cycle in RGC(EM)R_{G_{C}}(E_{M}) [29]. Furthermore, finding all the arcs (x,y)(x,y) that do not belong to a cycle in a graph can be performed by building the strongly connected components of the graph. We see in Fig. 3 that the arcs (1,x1)(1,x_{1}) and (2,x1)(2,x_{1}) belong to a cycle. So, they belong to some maximum flow and (X1,1)(X_{1},1) and (X1,2)(X_{1},2) are hybrid consistent. (2,x2)(2,x_{2}) does not belong to any cycle. So, (X2,2)(X_{2},2) is not HC.

Refer to caption
Figure 3: Residual graph obtained from the network in Fig. 1 and the maximum flow in Fig. 2.

4.1.2 Using the network flow for achieving HC on Occurs

We now have all the tools for achieving HC on any Occurs constraint. We first build GCG_{C}. We compute a maximum flow EME_{M} from ss to tt in GCG_{C}; if val(EM,s,t)<|N1|val(E_{M},s,t)<|N_{1}|, we fail. Otherwise we compute RGC(EM)R_{G_{C}}(E_{M}), build the strongly connected components in RGC(EM)R_{G_{C}}(E_{M}), and remove from D(Xi)D(X_{i}) any value vv such that (v,xi)(v,x_{i}) belongs to neither EME_{M} nor to a strongly connected component in RGC(EM)R_{G_{C}}(E_{M}). Finally, we set ub(T)ub(T) to ub(T)iD(Xi)ub(T)\cap\bigcup_{i}D(X_{i}). Following Theorem 1 and properties of residual graphs, this algorithm enforces HC on Occurs([X1,..,Xn],T)\mbox{\sc Occurs}([X_{1},..,X_{n}],T).

Complexity. Building GCG_{C} is in O(nd)O(nd) where dd is the maximum domain size. We need then to find a maximum flow EME_{M} in GCG_{C}. This can be done in two sub-steps. First, we use the arc (v,zv)(v,z_{v}) for each vlb(T)v\notin lb(T) (in O(|iD(Xi)|)O(|\bigcup_{i}D(X_{i})|)). Afterwards, we compute a maximum flow on the subgraph composed of all paths traversing nodes ww with wlb(T)w\in lb(T) (because there is no arc (w,zw)(w,z_{w}) in GCG_{C} for such ww). The complexity of finding a maximum flow in a unit capacity network is in O(ke)O(\sqrt{k}\cdot e) if kk is the number of nodes and ee the number of edges. This gives a complexity in O(|lb(T)||lb(T)|n)O(\sqrt{|lb(T)|}\cdot|lb(T)|\cdot n) for this second sub-step. Building the residual graph and computing the strongly connected components is in O(nd)O(nd). Extracting the HC domains for the XiX_{i}’s is direct. There remains to compute BC on TT, which takes O(nd)O(nd). Therefore, the total complexity is in O(nd+n|lb(T)|3/2)O(nd+n\cdot|lb(T)|^{3/2}).

Incrementality. In constraint solvers, constraints are usually maintained in a locally consistent state after each modification (restriction) of the domains of the variables. It is thus interesting to consider the total complexity of maintaining HC on Occurs after an arbitrary number of restrictions on the domains (values removed from D(Xi)D(X_{i}) and ub(T)ub(T), or added to lb(T)lb(T)) as we descend a branch of a backtracking search tree. Whereas some constraints are completely incremental (i.e., the total complexity after any number of restrictions is the same as the complexity of one propagation), this is not the case for constraints based on flow techniques like AllDifferent or Gcc [25, 26]. They potentially require the computation of a new maximum flow after each modification. Restoring a maximum flow from one that lost pp edges is in O(pe)O({p}\cdot e). If values are removed one by one (ndnd possible times), and if each removal affects the current maximum flow, the overall complexity over a sequence of restrictions on XiX_{i}’s, SS, TT, is in O(n2d2)O(n^{2}d^{2}).

4.2 Hybrid consistency on Range

Enforcing HC on Range([X1,,Xn],S,T)\mbox{\sc Range}([X_{1},\ldots,X_{n}],S,T) can be done by decomposing it as an Occurs constraint on new variables YiY_{i} and some channelling constraints ([16]) linking TT and the YiY_{i}’s to SS and the XiX_{i}’s. Interestingly, we do not need to maintain HC on the decomposition but just need to propagate the constraints in one pass.

The algorithm Propag-Range, enforcing HC on the Range constraint, is presented in Algorithm 1. In line 1, a special encoding is built, where a YiY_{i} is introduced for each XiX_{i} with index in ub(S)ub(S). The domain of a YiY_{i} is the same as that of XiX_{i} plus a dummy value. The dummy value works as a flag. If Occurs prunes it from D(Yi)D(Y_{i}) this means that YiY_{i} is necessary in Occurs to cover lb(T)lb(T). Then, XiX_{i} is also necessary to cover lb(T)lb(T) in Range. In line 1, HC on Occurs removes a value from a YiY_{i} each time it contains other values that are necessary to cover lb(T)lb(T) in every solution tuple. HC also removes values from ub(T)ub(T) that cannot be covered by any YiY_{i} in a solution. Line 1 updates the bounds of SS and the domain of YiY_{i}’s. Finally, in line 1, the channelling constraints between YiY_{i} and XiX_{i} propagate removals on XiX_{i} for each ii which belongs to SS in all solutions.

procedure Propag-Range([X1,,Xn],S,T)([X_{1},\ldots,X_{n}],S,T);
Introduce the set of integer variables Y={Yi|iub(S)}Y=\{Y_{i}~|~i\in ub(S)\},
with D(Yi)=D(Xi){dummy}D(Y_{i})=D(X_{i})\cup\{dummy\};
Achieve hybrid consistency on the constraint Occurs(Y,T)\mbox{\sc Occurs}(Y,T);
Achieve hybrid consistency on the constraints iSYiTi\in S\leftrightarrow Y_{i}\in T, for all YiYY_{i}\in Y;
Achieve GAC on the constraints (Yi=dummy)(Yi=Xi)(Y_{i}=dummy)\lor(Y_{i}=X_{i}), for all YiYY_{i}\in Y;
Algorithm 1 Hybrid consistency on Range
Theorem 2

The algorithm Propag-Range is a correct algorithm for enforcing HC on Range, that runs in O(nd+n|lb(T)|3/2)O(nd+n\cdot|lb(T)|^{3/2}) time, where dd is the maximal size of XiX_{i} domains.

Proof. Soundness. A value vv is removed from D(Xi)D(X_{i}) in line 1 if it is removed from YiY_{i} together with dummydummy in lines 1 or 1. If a value vv is removed from YiY_{i} in line 1, this means that any tuple on variables in YY covering lb(T)lb(T) requires that YiY_{i} takes a value from D(Yi)D(Y_{i}) other than vv. So, we cannot find a solution of Range in which Xi=vX_{i}=v since lb(T)lb(T) must be covered as well. A value vv is removed from D(Yi)D(Y_{i}) in line 1 if ilb(S)i\in lb(S) and vub(T)v\not\in ub(T). In this case, Range cannot be satisfied by a tuple where Xi=vX_{i}=v. If a value vv is removed from ub(T)ub(T) in line 1, none of the tuples of values for variables in YY covering lb(T)lb(T) can cover vv as well. Since variables in YY duplicate variables XiX_{i} with index in ub(S)ub(S), there is no hope to satisfy Range if vv is in TT. Note that ub(T)ub(T) cannot be modified in line 1 since YY contains only variables YiY_{i} for which ii was in ub(S)ub(S). If a value vv is added to lb(T)lb(T) in line 1, this is because there exists ii in lb(S)lb(S) such that D(Yi)ub(T)={v}D(Y_{i})\cap ub(T)=\{v\}. Hence, vv is necessarily in TT in all solutions of Range. An index ii can be removed from ub(S)ub(S) only in line 1. This happens when the domain of YiY_{i} does not intersect ub(T)ub(T). In such a case, this is evident that a tuple where iSi\in S could not satisfy Range since XiX_{i} could not take a value in TT. Finally, if an index ii is added to lb(S)lb(S) in line 1, this is because D(Yi)D(Y_{i}) is included in lb(T)lb(T), which means that the dummy value has been removed from D(Yi)D(Y_{i}) in line 1. This means that YiY_{i} takes a value from lb(T)lb(T) in all solutions of Occurs. XiX_{i} also has to take a value from lb(T)lb(T) in all solutions of Range.

Completeness Suppose that a value vv is not pruned from D(Xi)D(X_{i}) after line 1 of Propag-Range. If YiYY_{i}\in Y, we know that after line 1 there was an instantiation II on YY and TT, solution of Occurs with I[Yi]=vI[Y_{i}]=v or with Yi=dummyY_{i}=dummy (thanks to the channelling constraints in line 1). We can build the tuple II^{\prime} on X1,..Xn,S,TX_{1},..X_{n},S,T where XiX_{i} takes value vv, every XjX_{j} with jub(S)j\in ub(S) and I[Yj]I[T]I[Y_{j}]\in I[T] takes I[Yj]I[Y_{j}], and the remaining XjX_{j}’s take any value in their domain. TT is set to I[T]I[T] plus the values taken by XjX_{j}’s with jlb(S)j\in lb(S). These values are in ub(T)ub(T) thanks to line 1. Finally, SS is set to lb(S)lb(S) plus the indices of the YjY_{j}’s with I[Yj]I[T]I[Y_{j}]\in I[T]. These indices are in ub(S)ub(S) since the only jj’s removed from ub(S)ub(S) in line 1 are such that D(Yj)ub(T)=D(Y_{j})\cap ub(T)=\emptyset, which prevents I[Yj]I[Y_{j}] from taking a value in I[T]I[T]. Thus II^{\prime} is a solution of Range with I[Xi]=vI^{\prime}[X_{i}]=v. We have proved that the XiX_{i}’s are hybrid consistent after Propag-Range.

Suppose a value iub(S)i\in ub(S) after line 1. Thanks to constraint in line 1 we know there exists vv in D(Yi)ub(T)D(Y_{i})\cap ub(T), and so, vD(Xi)ub(T)v\in D(X_{i})\cap ub(T). Now, XiX_{i} is hybrid consistent after line 1. Thus Xi=vX_{i}=v belongs to a solution of Range. If we modify this solution by putting ii in SS and vv in TT (if not already there), we keep a solution.

Completeness on lb(S)lb(S), lb(T)lb(T) and ub(T)ub(T) is proved in a similar way.

Complexity. The important thing to notice in Propag-Range is that constraints in lines 11 are propagated in sequence. Thus, Occurs is propagated only once, for a complexity in O(nd+n|lb(T)|3/2)O(nd+n\cdot|lb(T)|^{3/2}). Lines 1, 1, and 1 are in O(nd)O(nd). Thus, the complexity of Propag-Range is in O(nd+n|lb(T)|3/2)O(nd+n\cdot|lb(T)|^{3/2}). This reduces to linear time complexity when lb(T)lb(T) is empty.

Incrementality. The overall complexity over a sequence of restrictions on XiX_{i}’s, SS and TT is in O(n2d2)O(n^{2}d^{2}). (See incrementality of Occurs in Section 4.1.) \Box

Note that the Range constraint can be decomposed using the Gcc constraint. However, propagation on such a decomposition is in O(n2d+n2.66)O(n^{2}d+n^{2.66}) time complexity (see [24]). Propag-Range is thus significantly cheaper.

5 Propagating the Roots constraint

We now give a thorough theoretical analysis of the Roots constraint. In Section 5.1, we provide a proof that enforcing HC on Roots is NP-hard in general. Section 5.2 presents a decomposition of the Roots constraint that permits us to propagate the Roots constraint partially in linear time. Section 5.3 shows that in many cases this decomposition does not destroy the global nature of the Roots constraint as enforcing HC on the decomposition achieves HC on the Roots constraint. Section 5.4 shows that we can obtain BC on the Roots constraint by enforcing BC on its decomposition. Finally, we provide some implementation details in Section 5.5.

5.1 Complete propagation

Unfortunately, propagating the Roots constraint completely is intractable in general. Whilst we made this claim in [10], a proof has not yet been published. For this reason, we give one here.

Theorem 3

Enforcing HC on the Roots constraint is NP-hard.

Proof. We transform 3Sat into the problem of the existence of a solution for Roots. Finding a hybrid support is thus NP-hard. Hence enforcing HC on Roots is NP-hard. Let φ={c1,,cm}\varphi=\{c_{1},\ldots,c_{m}\} be a 3CNF on the Boolean variables x1,,xnx_{1},\ldots,x_{n}. We build the constraint Roots([X1,,Xn+m],S,T)\mbox{\sc Roots}([X_{1},\ldots,X_{n+m}],S,T) as follows. Each Boolean variable xix_{i} is represented by the variable XiX_{i} with domain D(Xi)={i,i}D(X_{i})=\{i,-i\}. Each clause cp=xi¬xjxkc_{p}=x_{i}\lor\neg x_{j}\lor x_{k} is represented by the variable Xn+pX_{n+p} with domain D(Xn+p)={i,j,k}D(X_{n+p})=\{i,-j,k\}. We build SS and TT in such a way that it is impossible for both the index ii of a Boolean variable xix_{i} and its complement i-i to belong to TT. We set lb(T)=lb(T)=\emptyset and ub(T)=i=1n{i,i}ub(T)=\bigcup_{i=1}^{n}\{i,-i\}, and lb(S)=ub(S)={n+1,,n+m}lb(S)=ub(S)=\{n+1,\ldots,n+m\}. An interpretation MM on the Boolean variables x1,,xnx_{1},\ldots,x_{n} is a model of φ\varphi iff the tuple τ\tau in which τ[Xi]=i\tau[X_{i}]=i iff M[xi]=0M[x_{i}]=0 can be extended to a solution of Roots. (This extension puts in TT value ii iff M[xi]=1M[x_{i}]=1 and assigns Xn+pX_{n+p} with the value corresponding to the literal satisfying cpc_{p} in MM.) \Box

We thus have to look for a lesser level of consistency for Roots or for particular cases on which HC is polynomial. We will show that bound consistency is tractable and that, under conditions often met in practice (e.g. one of the last two arguments of Roots is ground), enforcing HC is also.

5.2 A decomposition of Roots

To show that Roots can be propagated tractably, we will give a straightforward decomposition into ternary constraints that can be propagated in linear time. This decomposition does not destroy the global nature of the Roots constraint since enforcing HC on the decomposition will, in many cases, achieve HC on the original Roots constraint, and since in all cases, enforcing BC on the decomposition achieves BC on the original Roots constraint. Given Roots([X1,..,Xn],S,T)\mbox{\sc Roots}([X_{1},..,X_{n}],S,T), we decompose it into the implications:

iS\displaystyle i\in S \displaystyle\rightarrow XiT\displaystyle X_{i}\in T
XiT\displaystyle X_{i}\in T \displaystyle\rightarrow iS\displaystyle i\in S

where i[1..n]i\in[1..n]. We have to be careful how we implement such a decomposition in a constraint solver. First, some solvers will not achieve HC on such constraints (see Sec 5.5 for more details). Second, we need an efficient algorithm to be able to propagate the decomposition in linear time. As we explain in more detail in Sec 5.5, a constraint solver could easily take quadratic time if it is not incremental.

We first show that this decomposition prevents us from propagating the Roots constraint completely. However, this is to be expected as propagating Roots completely is NP-hard and this decomposition is linear to propagate. In addition, as we later show, in many circumstances met in practice, the decomposition does not in fact hinder propagation.

Theorem 4

HC on Roots([X1,..,Xn],S,T)\mbox{\sc Roots}([X_{1},..,X_{n}],S,T) is strictly stronger than HC on iSXiTi\in S\rightarrow X_{i}\in T, and XiTiSX_{i}\in T\rightarrow i\in S for all i[1..n]i\in[1..n].

Proof. Consider X1{1,2}X_{1}\in\{1,2\}, X2{3,4}X_{2}\in\{3,4\}, X3{1,3}X_{3}\in\{1,3\}, X4{2,3}X_{4}\in\{2,3\}, lb(S)=ub(S)={3,4}lb(S)=ub(S)=\{3,4\}, lb(T)=lb(T)=\emptyset, and ub(T)={1,2,3,4}ub(T)=\{1,2,3,4\}. The decomposition is HC. However, enforcing HC on Roots will prune 3 from D(X2)D(X_{2}). \Box

In fact, enforcing HC on the decomposition achieves a level of consistency between BC and HC on the original Roots constraint. Consider X1{1,2,3}X_{1}\in\{1,2,3\}, X2{1,2,3}X_{2}\in\{1,2,3\}, lb(S)=ub(S)={1,2}lb(S)=ub(S)=\{1,2\}, lb(T)={}lb(T)=\{\}, and ub(T)={1,3}ub(T)=\{1,3\}. The Roots constraint is BC. However, enforcing HC on the decomposition will remove 2 from the domains of X1X_{1} and X2X_{2}. In the next section, we identify exactly when the decomposition achieves HC on Roots.

5.3 Some special cases

Many of the counting and occurrence constraints do not use the Roots constraint in its more general form, but have some restrictions on the variables SS, TT or XiX_{i}’s. For example, it is often the case that TT or SS are ground. We select four important cases that cover many of these uses of Roots and show that enforcing HC on Roots is then tractable.

C1.

ilb(S),D(Xi)lb(T)\forall i\in lb(S),D(X_{i})\subseteq lb(T)

C2.

iub(S),D(Xi)ub(T)=\forall i\notin ub(S),D(X_{i})\cap ub(T)=\emptyset

C3.

X1,..,XnX_{1},..,X_{n} are ground

C4.

TT is ground

We will show that in any of these cases, we can achieve HC on Roots simply by propagating the decomposition.

Theorem 5

If one of the conditions C1C1 to C4C4 holds, then enforcing HC on iSXiTi\in S\rightarrow X_{i}\in T, and XiTiSX_{i}\in T\rightarrow i\in S for all i[1..n]i\in[1..n] achieves HC on Roots([X1,..,Xn],S,T)\mbox{\sc Roots}([X_{1},..,X_{n}],S,T).

Proof. Our proof will exploit the following properties that are guaranteed to hold when we have enforced HC on the decomposition.

P1

if D(Xi)lb(T)D(X_{i})\subseteq lb(T) then ilb(S)i\in lb(S)

P2

if D(Xi)ub(T)=D(X_{i})\cap ub(T)=\emptyset then iub(S)i\notin ub(S)

P3

if ilb(S)i\in lb(S) then D(Xi)ub(T)D(X_{i})\subseteq ub(T)

P4

if iub(S)i\notin ub(S) then D(Xi)lb(T)=D(X_{i})\cap lb(T)=\emptyset

P5

if D(Xi)={v}D(X_{i})=\{v\} and ilb(S)i\in lb(S) then vlb(T)v\in lb(T)

P6

if D(Xi)={v}D(X_{i})=\{v\} and iub(S)i\notin ub(S) then vub(T)v\notin ub(T)

P7

if ii is added to lb(S)lb(S) by the constraint XiTiSX_{i}\in T\to i\in S then D(Xi)lb(T)D(X_{i})\subseteq lb(T)

P8

if ii is deleted from ub(S)ub(S) by the constraint iSXiTi\in S\to X_{i}\in T then D(Xi)ub(T)=D(X_{i})\cap ub(T)=\emptyset

Soundness. Immediate.

Completeness. We assume that one of the conditions C1—C4 holds and the decomposition is HC. We will first prove that the Roots constraint is satisfiable. Then, we will prove that, for any XiX_{i}, all the values in D(Xi)D(X_{i}) belong to a solution of Roots, and that the bounds on SS and TT are as tight as possible.

We prove that the Roots constraint is satisfiable. Suppose that one of the conditions C1—C4 holds and that the decomposition is HC. Build the following tuple τ\tau of values for the XiX_{i}, SS, and TT. Initialise τ[S]\tau[S] and τ[T]\tau[T] with lb(S)lb(S) and lb(T)lb(T) respectively. Now, let us consider the four conditions separately.

(C1) For each iτ[S]i\in\tau[S], choose any value vv in D(Xi)D(X_{i}) for τ[Xi]\tau[X_{i}]. From the assumption and from property P7 we deduce that vv is in lb(T)lb(T), and so in τ[T]\tau[T]. For each other ii, assign XiX_{i} with any value in D(Xi)lb(T)D(X_{i})\setminus lb(T). (This set is not empty thanks to property P1.) τ\tau obviously satisfies Roots.

(C2) For each iτ[S]i\in\tau[S], choose any value in D(Xi)D(X_{i}) for τ[Xi]\tau[X_{i}]. By construction such a value is in ub(T)ub(T) thanks to property P3. If necessary, add τ[Xi]\tau[X_{i}] to τ[T]\tau[T]. For each other iub(S)i\in ub(S), assign XiX_{i} with any value in D(Xi)τ[T]D(X_{i})\setminus\tau[T] if possible. Otherwise assign XiX_{i} with any value in D(Xi)D(X_{i}) and add ii to τ[S]\tau[S]. For each iub(S)i\notin ub(S), assign XiX_{i} any value from its domain. By assumption and by property P8 we know that D(Xi)ub(T)=D(X_{i})\cap ub(T)=\emptyset. Thus, τ\tau satisfies Roots.

(C3) τ[Xi]\tau[X_{i}] is already assigned for all XiX_{i}. For each iτ[S]i\in\tau[S], property P5 tells us that τ[Xi]\tau[X_{i}] is in τ[T]\tau[T], and for each ilb(S)i\notin lb(S), property P1 tells us that τ[Xi]\tau[X_{i}] is outside lb(T)lb(T). τ\tau satisfies Roots.

(C4) For each iτ[S]i\in\tau[S] choose any value vv in D(Xi)D(X_{i}) for τ[Xi]\tau[X_{i}]. Property P3 tells us vub(T)v\in ub(T). By assumption, vv is thus in τ[T]\tau[T]. For each ii outside ub(S)ub(S), assign XiX_{i} with any value vv in D(Xi)D(X_{i}). (vv is outside τ[T]\tau[T] by assumption and property P4). For each other ii, assign XiX_{i} with any value in D(Xi)D(X_{i}) and update τ[S]\tau[S] if necessary. τ\tau satisfies Roots.

We have proved that the Roots constraint has a solution. We now prove that for any value in ub(S)ub(S) or in ub(T)ub(T) or in D(Xi)D(X_{i}) for any XiX_{i}, we can transform the arbitrary solution of Roots into a solution that contains that value. Similarly, for any value not in lb(S)lb(S) or not in lb(T)lb(T), we can transform the arbitrary solution of Roots into a solution that does not contain that value.

Let us prove that lb(T)lb(T) is tight. Suppose the tuple τ\tau is a solution of the Roots constraint. Let vlb(T)v\not\in lb(T) and vτ[T]v\in\tau[T]. We show that there exists a solution with vτ[T]v\not\in\tau[T]. (Remark that this case is irrelevant to condition C4.) We remove vv from τ[T]\tau[T]. For each ilb(S)i\not\in lb(S) such that τ[Xi]=v\tau[X_{i}]=v we remove ii from τ[S]\tau[S]. With C1 we are sure that none of the ii in lb(S)lb(S) have τ[Xi]=v\tau[X_{i}]=v, thanks to property P7 and the fact that vlb(T)v\not\in lb(T). With C3 we are sure that none of the ii in lb(S)lb(S) have τ[Xi]=v\tau[X_{i}]=v, thanks to property P5 and the fact that vlb(T)v\not\in lb(T). There remains to check C2. For each ilb(S)i\in lb(S), we know that vv,vD(Xi)ub(T)\exists v^{\prime}\neq v,v^{\prime}\in D(X_{i})\cap ub(T), thanks to properties P3 and P5. We set XiX_{i} to vv^{\prime} in τ\tau, we add vv^{\prime} to τ[T]\tau[T] and add all kk with τ[Xk]=v\tau[X_{k}]=v^{\prime} to τ[S]\tau[S]. We are sure that kub(S)k\in ub(S) because vub(T)v^{\prime}\in ub(T) plus condition C2 and property P8.

Completeness on ub(T)ub(T), lb(S)lb(S), ub(S)ub(S) and XiX_{i}’s are shown with similar proofs. Let vub(T)τ[T]v\in ub(T)\setminus\tau[T]. (Again C4 is irrelevant.) We show that there exists a solution with vτ[T]v\in\tau[T]. Add vv to τ[T]\tau[T] and for each iub(S)i\in ub(S), if τ[Xi]=v\tau[X_{i}]=v, put ii in τ[S]\tau[S]. C2 is solved thanks to property P8 and the fact that vub(T)v\in ub(T). C3 is solved thanks to property P6 and the fact that vub(T)v\in ub(T). There remains to check C1. For each iub(S)i\not\in ub(S) and τ[Xi]=v\tau[X_{i}]=v, we know that vv,vD(Xi)lb(T)\exists v^{\prime}\neq v,v^{\prime}\in D(X_{i})\setminus lb(T) (thanks to properties P4 and P6). We set XiX_{i} to vv^{\prime} in τ\tau and remove vv^{\prime} from τ[T]\tau[T]. Each kk with τ[Xk]=v\tau[X_{k}]=v^{\prime} is removed from τ[S]\tau[S], and this is possible because we are in condition C1, vlb(T)v^{\prime}\not\in lb(T), and thanks to property P7.

Let vD(Xi)v\in D(X_{i}) and τ[Xi]=v,vv\tau[X_{i}]=v^{\prime},v^{\prime}\neq v. (C3 is irrelevant.) Assign vv to XiX_{i} in τ\tau. If both vv and vv^{\prime} or none of them are in τ[T]\tau[T], we are done. There remain two cases. First, if vτ[T]v\in\tau[T] and vτ[T]v^{\prime}\not\in\tau[T], the two alternatives to satisfy Roots are to add ii in τ[S]\tau[S] or to remove vv from τ[T]\tau[T]. If iub(S)i\in ub(S), we add ii to τ[S]\tau[S] and we are done. If iub(S)i\not\in ub(S), we know that vlb(T)v\not\in lb(T) thanks to property P4. So, vv is removed from τ[T]\tau[T] and we are sure that the XjX_{j}’s can be updated consistently for the same reason as in the proof of lb(T)lb(T). Second, if vτ[T]v\not\in\tau[T] and vτ[T]v^{\prime}\in\tau[T], the two alternatives to satisfy Roots are to remove ii from τ[S]\tau[S] or to add vv to τ[T]\tau[T]. If ilb(S)i\notin lb(S), we remove ii from τ[S]\tau[S] and we are done. If ilb(S)i\in lb(S), we know that vub(T)v\in ub(T) thanks to property P3. So, vv is added to τ[T]\tau[T] and we are sure that the XjX_{j}’s can be updated consistently for the same reason as in the proof of ub(T)τ[T]ub(T)\setminus\tau[T].

Let ilb(S)i\not\in lb(S) and iτ[S]i\in\tau[S]. We show that there exists a solution with iτ[S]i\not\in\tau[S]. We remove ii from τ[S]\tau[S]. Thanks to property P1, we know that D(Xi)lb(T)D(X_{i})\not\subseteq lb(T). So, we set XiX_{i} to a value vD(Xi)lb(T)v^{\prime}\in D(X_{i})\setminus lb(T). With C4 we are done because we are sure vτ[T]v^{\prime}\not\in\tau[T]. With conditions C1, C2, and C3, if vτ[T]v^{\prime}\in\tau[T], we remove it from τ[T]\tau[T] and we are sure that the XjX_{j}’s can be updated consistently for the same reason as in the proof of lb(T)lb(T).

Let iub(S)τ[S]i\in ub(S)\setminus\tau[S]. We show that there exists a solution with iτ[S]i\in\tau[S]. We add ii to τ[S]\tau[S]. Thanks to property P2, we know that D(Xi)ub(T)D(X_{i})\cap ub(T)\neq\emptyset. So, we set XiX_{i} to a value vD(Xi)ub(T)v^{\prime}\in D(X_{i})\cap ub(T). With condition C4 we are done because we are sure vτ[T]v^{\prime}\in\tau[T]. With conditions C1, C2, and C3, if vτ[T]v^{\prime}\not\in\tau[T], we add it to τ[T]\tau[T] and we are sure that the XjX_{j}’s can be updated consistently for the same reason as in the proof of ub(T)τ[T]ub(T)\setminus\tau[T]. \Box

5.4 Bound consistency

In addition to being able to enforce HC on Roots in some special cases, enforcing HC on the decomposition always enforces a level of consistency at least as strong as BC. In fact, in any situation (even those where enforcing HC is intractable), enforcing BC on the decomposition enforces BC on the Roots constraint.

Theorem 6

Enforcing BC on iSXiTi\in S\rightarrow X_{i}\in T, and XiTiSX_{i}\in T\rightarrow i\in S for all i[1..n]i\in[1..n] achieves BC on Roots([X1,..,Xn],S,T)\mbox{\sc Roots}([X_{1},..,X_{n}],S,T).

Proof. Soundness. Immediate.
Completeness. The proof follows the same structure as that in Theorem 5. We relax the properties P1–P4 into properties P1’–P4’.

P1’

if [min(Xi),max(Xi)]lb(T)[min(X_{i}),max(X_{i})]\subseteq lb(T) then ilb(S)i\in lb(S)

P2’

if [min(Xi),max(Xi)]ub(T)=[min(X_{i}),max(X_{i})]\cap ub(T)=\emptyset then iub(S)i\not\in ub(S)

P3’

if ilb(S)i\in lb(S) then the bounds of XiX_{i} are included in ub(T)ub(T)

P4’

if iub(S)i\notin ub(S) then the bounds of XiX_{i} are outside lb(T)lb(T)

Let us prove that lb(T)lb(T) and ub(T)ub(T) are tight. Let oo be the total ordering on D=iD(Xi)ub(T)D=\bigcup_{i}D(X_{i})\cup ub(T). Build the tuples σ\sigma and τ\tau as follows: For each vlb(T)v\in lb(T): put vv in σ[T]\sigma[T] and τ[T]\tau[T]. For each vub(T)lb(T)v\in ub(T)\setminus lb(T), following oo, do: put vv in σ[T]\sigma[T] or τ[T]\tau[T] alternately. For each ilb(S)i\in lb(S), P3’ guarantees that both min(Xi)min(X_{i}) and max(Xi)max(X_{i}) are in ub(T)ub(T). By construction of σ[T]\sigma[T] (and τ[T]\tau[T]) with alternation of values, if min(Xi)max(Xi)min(X_{i})\neq max(X_{i}), we are sure that there exists a value in σ[T]\sigma[T] (in τ[T]\tau[T]) between min(Xi)min(X_{i}) and max(Xi)max(X_{i}). In the case |D(Xi)|=1|D(X_{i})|=1, P5 guarantees that the only value is in σ[T]\sigma[T] (in τ[T]\tau[T]). Thus, we assign XiX_{i} in σ\sigma (in τ\tau) with such a value in σ[T]\sigma[T] (in τ[T]\tau[T]). For each iub(S)i\notin ub(S), we assign XiX_{i} in σ\sigma with a value in [min(Xi),[min(X_{i}), max(Xi)]σ[T]max(X_{i})]\setminus\sigma[T] (the same for τ\tau). We know that such a value exists with the same reasoning as for ilb(S)i\in lb(S) on alternation of values, and thanks to P4’ and P6. We complete σ\sigma and τ\tau by building σ[S]\sigma[S] and τ[S]\tau[S] consistently with the assignments of XiX_{i} and TT. The resulting tuples satisfy Roots. From this we deduce that lb(T)lb(T) and ub(T)ub(T) are BC as all values in ub(T)lb(T)ub(T)\setminus lb(T) are either in σ\sigma or in τ\tau, but not both.

We show that the XiX_{i} are BC. Take any XiX_{i} and its lower bound min(Xi)min(X_{i}). If ilb(S)i\in lb(S) we know that min(Xi)min(X_{i}) is in TT either in σ\sigma or in τ\tau thanks to P3’ and by construction of σ\sigma and τ\tau. We assign min(Xi)min(X_{i}) to XiX_{i} in the relevant tuple. This remains a solution of Roots. If iub(S)i\notin ub(S), we know that min(Xi)min(X_{i}) is outside TT either in σ\sigma or in τ\tau thanks to P4’ and by construction of σ\sigma and τ\tau. We assign min(Xi)min(X_{i}) to XiX_{i} in the relevant tuple. This remains a solution of Roots. If iub(S)lb(S)i\in ub(S)\setminus lb(S), assign XiX_{i} to min(Xi)min(X_{i}) in σ\sigma. If min(Xi)σ[T]min(X_{i})\notin\sigma[T], remove ii from σ[S]\sigma[S] else add ii to σ[S]\sigma[S]. The tuple obtained is a solution of Roots using the lower bound of XiX_{i}. By the same reasoning, we show that the upper bound of XiX_{i} is BC also, and therefore, all XiX_{i}’s are BC.

We prove that lb(S)lb(S) and ub(S)ub(S) are BC with similar proofs. Let us show that ub(S)ub(S) is BC. Take any XiX_{i} with iub(S)i\in ub(S) and iσ[S]i\notin\sigma[S]. Since XiX_{i} was assigned any value from [min(Xi),max(Xi)][min(X_{i}),max(X_{i})] when σ\sigma was built, and since we know that [min(Xi),max(Xi)]ub(T)[min(X_{i}),max(X_{i})]\cap ub(T)\neq\emptyset thanks to P2’, we can modify σ\sigma by assigning XiX_{i} a value in ub(T)ub(T), putting the value in TT if not already there, and adding ii into SS. The tuple obtained satisfies Roots. So ub(S)ub(S) is BC.

There remains to show that lb(S)lb(S) is BC. Thanks to P1’, we know that values iub(S)lb(S)i\in ub(S)\setminus lb(S) are such that [min(Xi),max(Xi)]lb(T)[min(X_{i}),max(X_{i})]\setminus lb(T)\neq\emptyset. Take v[min(Xi),max(Xi)]lb(T)v\in[min(X_{i}),max(X_{i})]\setminus lb(T). Thus, either σ\sigma or τ\tau is such that vTv\notin T. Take the corresponding tuple, assign XiX_{i} to vv and remove ii from SS. The modified tuple is still a solution of Roots and lb(S)lb(S) is BC. \Box

5.5 Implementation details

This decomposition of the Roots constraint can be implemented in many solvers using disjunctions of membership and negated membership constraints: 𝚘𝚛(𝚖𝚎𝚖𝚋𝚎𝚛(i,S),𝚗𝚘𝚝𝚖𝚎𝚖𝚋𝚎𝚛(Xi,T)){\tt or}({\tt member}(i,S),{\tt not\-member}(X_{i},T)) and 𝚘𝚛(𝚗𝚘𝚝𝚖𝚎𝚖𝚋𝚎𝚛(i,S),𝚖𝚎𝚖𝚋𝚎𝚛(Xi,T)){\tt or}({\tt not\-member}(i,S),{\tt member}(X_{i},T)). However, this requires a little care. Unfortunately, some existing solvers (like Ilog Solver) may not achieve HC on such disjunctions of primitives. For instance, the negated membership constraint 𝚗𝚘𝚝𝚖𝚎𝚖𝚋𝚎𝚛(Xi,T){\tt notmember}(X_{i},T) may be activated only if XiX_{i} is instantiated with a value of TT (whereas it should be as soon as D(Xi)lb(T)D(X_{i})\subseteq lb(T)). We have to ensure that the solver wakes up when it should to ensure we achieve HC. As we explain in the complexity proof, we also have to be careful that the solver does not wake up too often or we will lose the optimal O(nd)O(nd) time complexity which can be achieved.

Theorem 7

It is possible to enforce HC (or BC) on the decomposition of Roots([X1,..,Xn],S,T)\mbox{\sc Roots}([X_{1},..,X_{n}],S,T) in O(nd)O(nd) time, where d=max(i.|D(Xi)|,|ub(T)|)d=max(\forall i.|D(X_{i})|,|ub(T)|).

Proof. The decomposition of Roots is composed of 2n2n constraints. To obtain an overall complexity in O(nd)O(nd), the total amount of work spent propagating each of these constraints must be in O(d)O(d) time.

First, it is necessary that each of the 2n2n constraints of the decomposition is not called for propagation more than dd times. Since SS can be modified up to nn times (nn can be larger than dd) it is important that not all constraints are called for propagation at each change in lb(S)lb(S) or ub(S)ub(S). By implementing ’propagating events’ as described in [20, 30], we can ensure that when a value ii is added to lb(S)lb(S) or removed from ub(S)ub(S), constraints jSXjTj\in S\to X_{j}\in T and XjTjSX_{j}\in T\to j\in S, jij\neq i, are not called for propagation.

Second, we show that enforcing HC on constraint iSXiTi\in S\to X_{i}\in T is in O(d)O(d) time. Testing the precondition (does ii belong to lb(S)lb(S)?) is constant time. If true, removing from D(Xi)D(X_{i}) all values not in ub(T)ub(T) is in O(d)O(d) time and updating lb(T)lb(T) (if |D(Xi)|=1|D(X_{i})|=1) is constant time. Testing that the postcondition is false (is D(Xi)D(X_{i}) disjoint from ub(T)ub(T)?) is in O(d)O(d) time. If false, updating ub(S)ub(S) is constant time. Thus HC on iSXiTi\in S\to X_{i}\in T is in O(d)O(d) time. Enforcing HC on XiTiSX_{i}\in T\to i\in S is in O(d)O(d) time as well because testing the precondition (D(Xi)lb(T)D(X_{i})\subseteq lb(T)?) is in O(d)O(d) time, updating lb(S)lb(S) is constant time, testing that the postcondition is false (iub(S)i\notin ub(S)?) is constant time, and removing from D(Xi)D(X_{i}) all values in lb(T)lb(T) is in O(d)O(d) time and updating ub(T)ub(T) (if |D(Xi)|=1|D(X_{i})|=1) is constant time.

When TT is modified, all constraints are potentially concerned. Since TT can be modified up to dd times, we can have dd calls of the propagation in O(d)O(d) time for each of the 2n2n constraints. It is thus important that the propagation of the 2n2n constraints is incremental to avoid an O(nd2)O(nd^{2}) overall complexity. An algorithm for iSXiTi\in S\to X_{i}\in T is incremental if the complexity of calling the propagation of the constraint iSXiTi\in S\to X_{i}\in T up to dd times (once for each change in TT or D(Xi)D(X_{i})) is the same as propagating the constraint once. This can be achieved by an AC2001-like algorithm that stores the last value found in D(Xi)ub(T)D(X_{i})\cap ub(T), which is a witness that the postcondition can be true. (Similarly, the last value found in D(Xi)lb(T)D(X_{i})\setminus lb(T) is a witness that the precondition of the constraint XiTiSX_{i}\in T\to i\in S can be false.) Finally, each time lb(T)lb(T) (resp. ub(T)ub(T)) is modified, D(Xi)D(X_{i}) must be updated for each ii outside ub(S)ub(S) (resp. inside lb(S)lb(S)). If the propagation mechanism of the solver provides the values that have been added to lb(T)lb(T) or removed from ub(T)ub(T) to the propagator of the 2n2n constraints (as described in [33]), updating a given D(Xi)D(X_{i}) has a total complexity in O(d)O(d) time for the dd possible changes in TT. The proof that BC can also be enforced in linear time follows a similar argument. \Box

6 A catalog of decompositions using Range and Roots

We have shown how to propagate the Range and Roots constraints. Specification of counting and occurrence constraints using Range and Roots will thus be executable. Range and Roots permit us to decompose counting and occurrence global constraints into more primitive constraints, each of which having an associated polynomial propagation algorithm. In some cases, such decomposition does not hinder propagation. In other cases, enforcing local consistency on the global constraint is intractable, and decomposition is one method to obtain a polynomial propagation algorithm [13, 15, 14].

In a technical report [9], we present a catalog containing over 70 global constraints from [2] specified with the help of the Range and Roots constraints. Here we present a few of the more important constraints. In the subsequent five subsections, we list some counting and occurrence constraints which can be specified using Range constraints, using Roots constraints, and using both Range and Roots constraints. We also show that Range and Roots can be used to specify open global constraints, a new kind of global constraints introduced recently. We finally include problem domains other than counting and occurrence to illustrate the wide range of global constraints expressible in terms of Range and Roots.

6.1 Applications of Range constraint

Range constraints are often useful to specify constraints on the values used by a sequence of variables.

6.1.1 All different

The AllDifferent constraint forces a sequence of variables to take different values from each other. Such a constraint is useful in a wide range of problems (e.g. allocation of activities to different slots in a time-tabling problem). It can be propagated efficiently [25]. It can also be decomposed with a single Range constraint:

AllDifferent([X1,..,Xn])iff\displaystyle\mbox{\sc AllDifferent}([X_{1},..,X_{n}])\ \ \mbox{\rm iff}
Range([X1,..,Xn],{1,..,n},T) and |T|=n\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},T)\ \and\ |T|=n

A special but nevertheless important case of this constraint is the Permutation constraint. This is an AllDifferent constraint where we additionally know RR, the set of values to be taken. That is, the sequence of variables is a permutation of the values in RR where |R|=n|R|=n. This also can be decomposed using a single Range constraint:

Permutation([X1,..,Xn],R)iff\displaystyle\mbox{\sc Permutation}([X_{1},..,X_{n}],R)\ \ \mbox{\rm iff}
Range([X1,..,Xn],{1,..,n},R)\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},R)

Such a decomposition of the Permutation constraint obviously does not hinder propagation. However, decomposition of AllDifferent into a Range constraint does. This example illustrates that, whilst many global constraints can be expressed in terms of Range and Roots, there are some global constraints like AllDifferent for which it is worth developing specialised propagation algorithms. Nevertheless, Range and Roots provide a means of propagation for such constraints in the absence of specialised algorithms. They can also enhance the existing propagators. For instance, HC on the Range decomposition is incomparable to AC on the decomposition of AllDifferent which uses a clique of binary inequality constraints. Thus, we may be able to obtain more pruning by using both decompositions.

Theorem 8

(1) GAC on Permutation is equivalent to HC on the decomposition with Range. (2) GAC on AllDifferent is stronger than HC on the decomposition with Range. (3) AC on the decomposition of AllDifferent into binary inequalities is incomparable to HC on the decomposition with Range.

Proof: (1) Permutation can be encoded as a single Range. Moreover, since RR is fixed, HC is equivalent to AC. (2) Consider X1X_{1}, X2{1,2}X_{2}\in\{1,2\}, X3{1,2,3,4}X_{3}\in\{1,2,3,4\}, and {1,2}T{1,2,3,4}\{1,2\}\subseteq T\subseteq\{1,2,3,4\}. Then Range([X1,X2,X3],{1,2,3},T)\mbox{\sc Range}([X_{1},X_{2},X_{3}],\{1,2,3\},T) and |T|=3|T|=3 are both HC, but AllDifferent([X1,X2,X3])\mbox{\sc AllDifferent}([X_{1},X_{2},X_{3}]) is not GAC. (3) Consider X1X_{1}, X2{1,2}X_{2}\in\{1,2\}, X3{1,2,3}X_{3}\in\{1,2,3\}, and T={1,2,3}T=\{1,2,3\}. Then X1X2X_{1}\neq X_{2}, X1X3X_{1}\neq X_{3} and X2X3X_{2}\neq X_{3} are AC but Range([X1,X2,X3],{1,2,3},T)\mbox{\sc Range}([X_{1},X_{2},X_{3}],\{1,2,3\},T) is not HC. Consider X1X_{1}, X2{1,2,3,4}X_{2}\in\{1,2,3,4\}, X3{2}X_{3}\in\{2\}, and {2}T{1,2,3,4}\{2\}\subseteq T\subseteq\{1,2,3,4\}. Then Range([X1,X2,X3],{1,2,3},T)\mbox{\sc Range}([X_{1},X_{2},X_{3}],\{1,2,3\},T) and |T|=3|T|=3 are HC. But X1X3X_{1}\neq X_{3} and X2X3X_{2}\neq X_{3} are not AC. \Box

6.1.2 Disjoint

We may require that two sequences of variables be disjoint (i.e. have no value in common). For instance, two sequences of tasks sharing the same resource might be required to be disjoint in time. The Disjoint([X1,..,Xn],[Y1,..,Ym])\mbox{\sc Disjoint}([X_{1},..,X_{n}],[Y_{1},..,Y_{m}]) constraint introduced in [2] ensures XiYjX_{i}\neq Y_{j} for any ii and jj. We prove here that we cannot expect to enforce GAC on such a constraint as it is NP-hard to do so in general.

Theorem 9

Enforcing GAC on Disjoint is NP-hard.

Proof: We reduce 3-SAT to the problem of deciding if a Disjoint constraint has any satisfying assignment. Finding support is therefore NP-hard. Consider a formula φ\varphi with nn variables and mm clauses. For each Boolean variable xx, we let Xx{x,¬x}X_{x}\in\{x,\neg x\} and Yj{x,¬y,z}Y_{j}\in\{x,\neg y,z\} where the jjth clause in φ\varphi is x¬yzx\vee\neg y\vee z. If φ\varphi has a model then the Disjoint constraint has a satisfying assignment in which the XxX_{x} take the literals false in this model. \Box

One way to propagate a Disjoint constraint is to decompose it into two Range constraints:

Disjoint([X1,..,Xn],[Y1,..,Ym])iff\displaystyle\mbox{\sc Disjoint}([X_{1},..,X_{n}],[Y_{1},..,Y_{m}])\ \ \mbox{\rm iff}
Range([X1,..,Xn],{1,..,n},S) and \displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},S)\ \and\
Range([Y1,..,Ym],{1,..,m},T) and ST={}\displaystyle\mbox{\sc Range}([Y_{1},..,Y_{m}],\{1,..,m\},T)\ \and\ S\cap T=\{\}

Enforcing HC on this decomposition is polynomial. Decomposition thus offers a simple and promising method to propagate a Disjoint constraint. Not surprisingly, the decomposition hinders propagation (otherwise we would have a polynomial algorithm for a NP-hard problem).

Theorem 10

GAC on Disjoint is stronger than HC on the decomposition.

Proof: Consider X1,Y1{1,2}X_{1},Y_{1}\in\{1,2\}, X2,Y2{1,3}X_{2},Y_{2}\in\{1,3\}, Y3{2,3}Y_{3}\in\{2,3\} and {}S,T{1,2,3}\{\}\subseteq S,T\subseteq\{1,2,3\}. Then Range([X1,X2],{1,2},S)\mbox{\sc Range}([X_{1},X_{2}],\{1,2\},S) and Range([Y1,Y2,Y3],{1,2,3},T)\mbox{\sc Range}([Y_{1},Y_{2},Y_{3}],\{1,2,3\},T) are HC, and ST={}S\cap T=\{\} is BC. However, enforcing GAC on Disjoint([X1,X2],[Y1,Y2,Y3])\mbox{\sc Disjoint}([X_{1},X_{2}],[Y_{1},Y_{2},Y_{3}]) prunes 3 from X2X_{2} and 1 from both Y1Y_{1} and Y2Y_{2}. \Box

6.1.3 Number of values

The NValue constraint is useful in a wide range of problems involving resources since it counts the number of distinct values used by a sequence of variables [22, 8, 7]. As we saw in Section 3, NValue([X1,..,Xn],N)\mbox{\sc NValue}([X_{1},..,X_{n}],N) holds iff N=|{Xi| 1in}|N=|\{X_{i}\ |\ 1\leq i\leq n\}|. The AllDifferent constraint is a special case of the NValue constraint in which N=nN=n. Unfortunately, it is NP-hard in general to enforce GAC on a NValue constraint [13]. However, there is an O(nlog(n))O(n\log(n)) algorithm to enforce a level of consistency similar to BC [3]. An alternative and even simpler way to implement this constraint is with a Range constraint:

NValue([X1,..,Xn],N)iff\displaystyle\mbox{\sc NValue}([X_{1},..,X_{n}],N)\ \ \mbox{\rm iff}
Range([X1,..,Xn],{1,..,n},T) and |T|=N\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},T)\ \and\ |T|=N

HC on this decomposition is incomparable to BC on the NValue constraint.

Theorem 11

BC on NValue is incomparable to HC on the decomposition.

Proof: Consider X1,X2{1,2}X_{1},X_{2}\in\{1,2\}, X3{1,2,3,4}X_{3}\in\{1,2,3,4\}, N{3}N\in\{3\} and {}T{1,2,3,4}\{\}\subseteq T\subseteq\{1,2,3,4\}. Then Range([X1,X2,X3],{1,2,3},T)\mbox{\sc Range}([X_{1},X_{2},X_{3}],\{1,2,3\},T) and |T|=N|T|=N are both HC. However, enforcing BC on NValue([X1,X2,X3],N)\mbox{\sc NValue}([X_{1},X_{2},X_{3}],N) prunes 1 and 2 from X3X_{3}.

Consider X1,X2,X3{1,3}X_{1},X_{2},X_{3}\in\{1,3\} and N{3}N\in\{3\}. Then NValue([X1,X2,X3],N)\mbox{\sc NValue}([X_{1},X_{2},X_{3}],N) is BC. However, enforcing HC on Range([X1,X2,X3],{1,2,3},T)\mbox{\sc Range}([X_{1},X_{2},X_{3}],\{1,2,3\},T) makes {}T{1,3}\{\}\subseteq T\subseteq\{1,3\} which will cause |T|=3|T|=3 to fail. \Box

6.1.4 Uses

In [5], propagation algorithms achieving GAC and BC are proposed for the UsedBy constraint. UsedBy([X1,..,Xn],[Y1,..,Ym])([X_{1},..,X_{n}],[Y_{1},..,Y_{m}]) holds iff the multiset of values assigned to Y1,..,YmY_{1},..,Y_{m} is a subset of the multiset of values assigned to X1,..,XnX_{1},..,X_{n}. We now introduce a variant of the UsedBy constraint called the Uses constraint. Uses([X1,..,Xn],[Y1,..,Ym])([X_{1},..,X_{n}],[Y_{1},..,Y_{m}]) holds iff the set of values assigned to Y1,..,YmY_{1},..,Y_{m} is a subset of the set of values assigned to X1,..,XnX_{1},..,X_{n}. That is, UsedBy takes into account the number of times a value is used while Uses does not. Unlike the UsedBy constraint, enforcing GAC on Uses is NP-hard.

Theorem 12

Enforcing GAC on Uses is NP-hard.

Proof: We reduce 3-SAT to the problem of deciding if a Uses constraint has a solution. Finding support is therefore NP-hard. Consider a formula φ\varphi with nn Boolean variables and mm clauses. For each Boolean variable xx, we introduce a variable Xx{x,x}X_{x}\in\{x,-x\}. For each clause cj=x¬yzc_{j}=x\vee\neg y\vee z, we introduce Yj{x,y,z}Y_{j}\in\{x,-y,z\}. Then φ\varphi has a model iff the Uses constraint has a satisfying assignment, and xx is true iff Xx=xX_{x}=x. \Box

One way to propagate a Uses constraint is to decompose it using Range constraints:

Uses([X1,..,Xn],[Y1,..,Ym])iff\displaystyle\mbox{\sc Uses}([X_{1},..,X_{n}],[Y_{1},..,Y_{m}])\ \ \mbox{\rm iff}
Range([X1,..,Xn],{1,..,n},T) and\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},T)\ \and
Range([Y1,..,Ym],{1,..,m},T) and TT\displaystyle\mbox{\sc Range}([Y_{1},..,Y_{m}],\{1,..,m\},T^{\prime})\ \and\ T^{\prime}\subseteq T

Enforcing HC on this decomposition is polynomial. Not surprisingly, this hinders propagation (otherwise we would have a polynomial algorithm for a NP-hard problem).

Theorem 13

GAC on Uses is stronger than HC on the decomposition.

Proof: Consider X1{1,2,3,4}X_{1}\in\{1,2,3,4\}, X2{1,2,3,5}X_{2}\in\{1,2,3,5\}, X3,X4{4,5,6}X_{3},X_{4}\in\{4,5,6\}, Y1{1,2}Y_{1}\in\{1,2\}, Y2{1,3}Y_{2}\in\{1,3\}, and Y3{2,3}Y_{3}\in\{2,3\}. The decomposition is HC while GAC on Uses prunes 4 from the domain of X1X_{1} and 5 from the domain of X2X_{2}. \Box

Thus, decomposition is a simple method to obtain a polynomial propagation algorithm.

6.2 Applications of Roots constraint

Range constraints are often useful to specify constraints on the values used by a sequence of variables. Roots constraint, on the other hand, are useful to specify constraints on the variables taking particular values.

6.2.1 Global cardinality

The global cardinality constraint introduced in [26] constrains the number of times values are used. We consider a generalization in which the number of occurrences of a value may itself be an integer variable. More precisely, Gcc([X1,..,Xn],[d1,..,dm],[O1,..,Om])\mbox{\sc Gcc}([X_{1},..,X_{n}],[d_{1},..,d_{m}],[O_{1},..,O_{m}]) holds iff |{i|Xi=dj}|=Oj|\{i\ |\ X_{i}=d_{j}\}|=O_{j} for all jj. Such a Gcc constraint can be decomposed into a set of Roots constraints:

Gcc([X1,..,Xn],[d1,..,dm],[O1,..,Om])iff\displaystyle\mbox{\sc Gcc}([X_{1},..,X_{n}],[d_{1},..,d_{m}],[O_{1},..,O_{m}])\ \ \mbox{\rm iff}
i.Roots([X1,..,Xn],Si,{di}) and |Si|=Oi\displaystyle\forall i\ .\ \mbox{\sc Roots}([X_{1},..,X_{n}],S_{i},\{d_{i}\})\ \and\ |S_{i}|=O_{i}

Enforcing HC on these Roots constraints is polynomial since the sets {di}\{d_{i}\} are ground (See Theorem 5). Enforcing GAC on a generalised Gcc constraint is NP-hard, but we can enforce GAC on the XiX_{i} and BC on the OjO_{j} in polynomial time using a specialised algorithm [24]. This is more than is achieved by the decomposition.

Theorem 14

GAC on the XiX_{i} and BC on the OjO_{j} of a Gcc constraint is stronger than HC on the decomposition using Roots constraints.

Proof: As sets are represented by their bounds, HC on the decomposition cannot prune more on the OjO_{j} than BC does on the Gcc. To show strictness, consider X1,X2{1,2}X_{1},X_{2}\in\{1,2\}, X3{1,2,3}X_{3}\in\{1,2,3\}, di=id_{i}=i and O1,O2,O3{0,1}O_{1},O_{2},O_{3}\in\{0,1\}. The decomposition is HC (with {}S1,S2{1,2,3}\{\}\subseteq S_{1},S_{2}\subseteq\{1,2,3\} and {}S3{3}\{\}\subseteq S_{3}\subseteq\{3\}). However, enforcing GAC on the XiX_{i} and BC on the OjO_{j} of the Gcc constraint will prune 1 and 2 from X3X_{3} and 0 from O1O_{1}, O2O_{2} and O3O_{3}. \Box

This illustrates another global constraint for which it is worth developing a specialised propagation algorithm.

6.2.2 Among

The Among constraint was introduced in CHIP to help model resource allocation problems like car sequencing [4]. It counts the number of variables using values from a given set. Among([X1,..,Xn],\mbox{\sc Among}([X_{1},..,X_{n}], [d1,..,dm],N)[d_{1},..,d_{m}],N) holds iff N=|{i|Xi{d1,..,dm}}|N=|\{i\ |\ X_{i}\in\{d_{1},..,d_{m}\}\}|.

An alternative way to propagate the Among constraint is to decompose it using a Roots constraint:

Among([X1,..,Xn],[d1,..,dm],N)iff\displaystyle\mbox{\sc Among}([X_{1},..,X_{n}],[d_{1},..,d_{m}],N)\ \ \mbox{\rm iff}
Roots([X1,..,Xn],S,{d1,..,dm}) and |S|=N\displaystyle\mbox{\sc Roots}([X_{1},..,X_{n}],S,\{d_{1},..,d_{m}\})\ \and\ |S|=N

It is polynomial to enforce HC on this case of the Roots constraint since the target set is ground. This decomposition also does not hinder propagation. It is therefore a potentially attractive method to implement the Among constraint.

Theorem 15

GAC on Among is equivalent to HC on the decomposition using Roots.

Proof: Suppose the decomposition into Roots([X1,..,Xn],S,{d1,..,dm})\mbox{\sc Roots}([X_{1},..,X_{n}],S,\{d_{1},..,d_{m}\}) and |S|=N|S|=N is HC. The variables XiX_{i} divide into three categories: those whose domain only contains elements from {d1,..,dm}\{d_{1},..,d_{m}\} (at most min(N)\min(N) such variables); those whose domain do not contain any such elements (at most nmax(N)n-\max(N) such vars); those whose domain contains both elements from this set and from outside. Consider any value for a variable XiX_{i} in the first such category. To construct support for this value, we assign the remaining variables in the first category with values from {d1,..,dm}\{d_{1},..,d_{m}\}. If the total number of assigned values is less than min(N)\min(N), we assign a sufficient number of variables from the second category with values from {d1,..,dm}\{d_{1},..,d_{m}\} to bring up the count to min(N)\min(N). We then assign all the remaining unassigned XjX_{j} with values outside {d1,..,dm}\{d_{1},..,d_{m}\}. Finally, we assign min(N)\min(N) to NN. Support can be constructed for variables in the other two categories in a similar way, as well as for any value of NN between min(N)\min(N) and max(N)\max(N). \Box

6.2.3 At most and at least

The AtMost and AtLeast constraints are closely related. The AtMost constraint puts an upper bound on the number of variables using a particular value, whilst the AtLeast puts a lower bound. For instance, AtMost([X1,..,Xn],d,N)\mbox{\sc AtMost}([X_{1},..,X_{n}],d,N) holds iff |{i|Xi=d}|N|\{i\ |\ X_{i}=d\}|\leq N. Both AtMost and AtLeast can be decomposed into Roots constraints. For example:

AtMost([X1,..,Xn],d,N)iff\displaystyle\mbox{\sc AtMost}([X_{1},..,X_{n}],d,N)\ \ \mbox{\rm iff}
Roots([X1,..,Xn],S,{d}) and |S|N\displaystyle\mbox{\sc Roots}([X_{1},..,X_{n}],S,\{d\})\ \and\ |S|\leq N

Again it is polynomial to enforce HC on these cases of the Roots constraint, and the decomposition does not hinder propagation. Decomposition is therefore also a potential method to implement the AtMost and AtLeast constraints in case we do not have such constraints available in our constraint toolkit.

Theorem 16

GAC on AtMost is equivalent to HC on the decomposition. Roots([X1,..,Xn],S,{d})\mbox{\sc Roots}([X_{1},..,X_{n}],S,\{d\}) and on |S|N|S|\leq N.

GAC on AtLeast is equivalent to HC on the decomposition. Roots([X1,..,Xn],S,{d})\mbox{\sc Roots}([X_{1},..,X_{n}],S,\{d\}) and on |S|N|S|\geq N.

Proof: The proof of the last theorem can be easily adapted to these two constraints. \Box

6.3 Applications of Range and Roots constraints

Some global constraints need both Range and Roots constraints in their specifications.

6.3.1 Assign and number of values

In bin packing and knapsack problems, we may wish to assign both a value and a bin to each item, and place constraints on the values appearing in each bin. For instance, in the steel mill slab design problem (prob038 in CSPLib), we assign colours and slabs to orders so that there are a limited number of colours on each slab. Assign&NValues([X1,..,Xn],[Y1,..,Yn],N)\mbox{\sc Assign\&NValues}([X_{1},..,X_{n}],[Y_{1},..,Y_{n}],N) holds iff |{Yi|Xi=j}|N|\{Y_{i}\ |\ X_{i}=j\}|\leq N for each jj [2]. We cannot expect to enforce GAC on such a constraint as it is NP-hard to do so in general.

Theorem 17

Enforcing GAC on Assign&NValues is NP-hard.

Proof: Deciding if the constraint AtMostNValue has a solution is NP-complete, where AtMostNValue([Y1,..,Yn],N)\mbox{\sc AtMostNValue}([Y_{1},..,Y_{n}],N) holds iff |{Yi| 1in}|N|\{Y_{i}\ |\ 1\leq i\leq n\}|\leq N [8, 7]. The problem of the existence of a solution in this constraint is equivalent to the problem of the existence of a solution in Assign&NValues([X1,..,Xn],[Y1,..,Yn],N)\mbox{\sc Assign\&NValues}([X_{1},..,X_{n}],[Y_{1},..,Y_{n}],N) where D(Xi)={0},i1..nD(X_{i})=\{0\},\forall i\in 1..n. Deciding whether Assign&NValues is thus NP-complete and enforcing GAC is NP-hard. \Box

Assign&NValues can be decomposed into a set of Range and Roots constraints:

Assign&NValues([X1,..,Xn],[Y1,..,Yn],N)iff\displaystyle\mbox{\sc Assign\&NValues}([X_{1},..,X_{n}],[Y_{1},..,Y_{n}],N)\ \ \mbox{\rm iff}
j.Roots([X1,..,Xn],Sj,{j}) and\displaystyle\forall j\ .\ \mbox{\sc Roots}([X_{1},..,X_{n}],S_{j},\{j\})\ \and
Range([Y1,..,Yn],Sj,Tj) and |Tj|N\displaystyle\hskip 20.00003pt\mbox{\sc Range}([Y_{1},..,Y_{n}],S_{j},T_{j})\ \and\ |T_{j}|\leq N

However, this decomposition hinders propagation.

Theorem 18

GAC on Assign&NValues is stronger than HC on the decomposition.

Proof: Consider N=1N=1, X1,X2{0}X_{1},X_{2}\in\{0\}, Y1{1,2},Y2{2,3}Y_{1}\in\{1,2\},Y_{2}\in\{2,3\}. HC on the decomposition enforces S0={1,2}S_{0}=\{1,2\} and {}T0{1,2,3}\{\}\subseteq T_{0}\subseteq\{1,2,3\} but no pruning on the XiX_{i} and YjY_{j}. However, enforcing GAC on Assign&NValues([X1,X2],[Y1,Y2],N)\mbox{\sc Assign\&NValues}([X_{1},X_{2}],[Y_{1},Y_{2}],N) prunes 1 from Y1Y_{1} and 3 from Y2Y_{2}. \Box

6.3.2 Common

A generalization of the Among and AllDifferent constraints introduced in [2] is the Common constraint. Common(N,M,[X1,..,Xn],[Y1,..,Ym])\mbox{\sc Common}(N,M,[X_{1},..,X_{n}],[Y_{1},..,Y_{m}]) ensures N=|{i|j,Xi=Yj}|N=|\{i\ |\ \exists j,X_{i}=Y_{j}\}| and M=|{j|i,Xi=Yj}|M=|\{j\ |\ \exists i,X_{i}=Y_{j}\}|. That is, NN variables in XiX_{i} take values in common with YjY_{j} and MM variables in YjY_{j} takes values in common with XiX_{i}. We prove that we cannot expect to enforce GAC on such a constraint as it is NP-hard to do so in general.

Theorem 19

Enforcing GAC on Common is NP-hard.

Proof: We again use a transformation from 3-SAT. Consider a formula φ\varphi with nn Boolean variables and mm clauses. For each Boolean variable ii, we introduce a variable Xi{i,i}X_{i}\in\{i,-i\}. For each clause cj=x¬yzc_{j}=x\vee\neg y\vee z, we introduce Yj{x,y,z}Y_{j}\in\{x,-y,z\}. We let N{0,..,n}N\in\{0,..,n\} and M=mM=m. φ\varphi has a model iff the Common constraint has a solution in which the XiX_{i} take the literals true in this model. \Box

One way to propagate a Common constraint is to decompose it into Range and Roots constraints:

Common(N,M,[X1,..,Xn],[Y1,..,Ym])iff\displaystyle\mbox{\sc Common}(N,M,[X_{1},..,X_{n}],[Y_{1},..,Y_{m}])\ \ \mbox{\rm iff}
Range([Y1,..,Ym],{1,..,m},T) and\displaystyle\mbox{\sc Range}([Y_{1},..,Y_{m}],\{1,..,m\},T)\ \and
Roots([X1,..,Xn],S,T) and |S|=N and\displaystyle\mbox{\sc Roots}([X_{1},..,X_{n}],S,T)\ \and\ |S|=N\ \and
Range([X1,..,Xn],{1,..,n},V) and\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},V)\ \and
Roots([Y1,..,Ym],U,V) and |U|=M\displaystyle\mbox{\sc Roots}([Y_{1},..,Y_{m}],U,V)\ \and\ |U|=M

Enforcing HC on this decomposition is polynomial. Decomposition thus offers a simple method to propagate a Common constraint. Not surprisingly, the decomposition hinders propagation.

Theorem 20

GAC on Common is stronger than HC on the decomposition.

Proof: Consider N=M=0N=M=0, X1,Y1{1,2}X_{1},Y_{1}\in\{1,2\}, X2,Y2{1,3}X_{2},Y_{2}\in\{1,3\}, Y3{2,3}Y_{3}\in\{2,3\}. Hybrid consistency on the decomposition enforces {}T,V{1,2,3}\{\}\subseteq T,V\subseteq\{1,2,3\}, and S=U={}S=U=\{\} but no pruning on the XiX_{i} and YjY_{j}. However, enforcing GAC on Common(N,M,[X1,X2],[Y1,Y2,Y3])\mbox{\sc Common}(N,M,[X_{1},X_{2}],[Y_{1},Y_{2},Y_{3}]) prunes 2 from X1X_{1}, 3 from X2X_{2} and 1 from both Y1Y_{1} and Y2Y_{2}. \Box

6.3.3 Symmetric all different

In certain domains, we may need to find symmetric solutions. For example, in sports scheduling problems, if one team is assigned to play another then the second team should also be assigned to play the first. SymAllDiff([X1,..,Xn])\mbox{\sc SymAllDiff}([X_{1},..,X_{n}]) ensures Xi=jX_{i}=j iff Xj=iX_{j}=i [27]. It can be decomposed into a set of Range and Roots constraints:

SymAllDiff([X1,..,Xn])iff\displaystyle\mbox{\sc SymAllDiff}([X_{1},..,X_{n}])\ \ \mbox{\rm iff}
Range([X1,..,Xn],{1,..,n},{1,..,n})\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},\{1,..,n\})\ \land
i.Roots([X1,..,Xn],Si,{i})XiSi|Si|=1\displaystyle\forall i\,.\,\mbox{\sc Roots}([X_{1},..,X_{n}],S_{i},\{i\})\ \land\ X_{i}\in S_{i}\ \land\ |S_{i}|=1

It is polynomial to enforce HC on these cases of the Roots constraint. However, as with the AllDifferent constraint, it is more effective to use a specialised propagation algorithm like that in [27].

Theorem 21

GAC on SymAllDiff is stronger than HC on the decomposition.

Proof: Consider X1{2,3}X_{1}\in\{2,3\}, X2{1,3}X_{2}\in\{1,3\}, X3{1,2}X_{3}\in\{1,2\}, {}S1{2,3}\{\}\subseteq S_{1}\subseteq\{2,3\}, {}S2{1,3}\{\}\subseteq S_{2}\subseteq\{1,3\}, and {}S3{1,2}\{\}\subseteq S_{3}\subseteq\{1,2\}. Then the decomposition is HC. However, enforcing GAC on SymAllDiff([X1,X2,X3])\mbox{\sc SymAllDiff}([X_{1},X_{2},X_{3}]) will detect unsatisfiability. \Box

To our knowledge, this constraint has not been integrated into any constraint solver. Thus, this decomposition provides a means of propagation for the SymAllDiff constraint.

6.3.4 Uses

In Section 6.1.4, we decomposed the constraint Uses with Range constraints. Another way to propagate a Uses constraint is to decompose it using both Range and Roots constraints:

Uses([X1,..,Xn],[Y1,..,Ym])iff\displaystyle\mbox{\sc Uses}([X_{1},..,X_{n}],[Y_{1},..,Y_{m}])\ \ \mbox{\rm iff}
Range([X1,..,Xn],{1,..,n},T) and\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],\{1,..,n\},T)\ \and
Roots([Y1,..,Ym],{1,..,m},T)\displaystyle\mbox{\sc Roots}([Y_{1},..,Y_{m}],\{1,..,m\},T)

Enforcing HC on this decomposition is polynomial. Again, such a decomposition hinders propagation as achieving GAC on a Uses constraint is NP-Hard. Interestingly, the decomposition of Uses using Range constraints presented in Section 6.1.4 and the decomposition presented here are equivalent.

Theorem 22

HC on the decomposition of Uses using only Range constraints is equivalent to HC on the decomposition using Range and Roots constraints.

Proof: We just need to show that HC on Roots([Y1,..,Ym],{1,..,m},T)\mbox{\sc Roots}([Y_{1},..,Y_{m}],\{1,..,m\},T) is equivalent to HC on Range([Y1,..,Ym],{1,..,m},T) and TT\mbox{\sc Range}([Y_{1},..,Y_{m}],\{1,..,m\},T^{\prime})\and T^{\prime}\subseteq T. Since, the Range and the Roots constraints are over the same set of variables ([Y1,..,Ym][Y_{1},..,Y_{m}]) and the same set of indices ({1,..,m}\{1,..,m\}) is fixed for both, then it follows that set variable TT^{\prime} maintained by Range is a subset of TT maintained by Roots. \Box

6.4 Open constraints

Open global constraints have recently been introduced. They are a new kind of global constraints for which the set of variables involved is not fixed. Range and Roots constraints are particularly useful to specify many such open global constraints.

The Gcc constraint has been extended to OpenGcc, a Gcc constraint for which the set of variables involved is not known in advance [34]. Given variables X1,..,XnX_{1},..,X_{n} and a set variable SS, S{1..n}\emptyset\subseteq S\subseteq\{1..n\}, OpenGcc([X1,..,Xn],S,[d1,..,dm],[O1,..,Om])\mbox{\sc OpenGcc}([X_{1},..,X_{n}],S,[d_{1},..,d_{m}],[O_{1},..,O_{m}]) holds iff |{iS|Xi=dj}|=Oj|\{i\in S\ |\ X_{i}=d_{j}\}|=O_{j} for all jj. OpenGcc can be decomposed into a set of Roots constraints in almost the same way as Gcc was decomposed in Section 6.2.1:

OpenGcc([X1,..,Xn],S,[d1,..,dm],[O1,..,Om])iff\displaystyle\mbox{\sc OpenGcc}([X_{1},..,X_{n}],S,[d_{1},..,d_{m}],[O_{1},..,O_{m}])\ \ \mbox{\rm iff}
S=i1..mSi and\displaystyle S=\bigcup_{i\in 1..m}S_{i}\ \and
i.Roots([X1,..,Xn],Si,{di}) and |Si|=Oi\displaystyle\forall i\ .\ \mbox{\sc Roots}([X_{1},..,X_{n}],S_{i},\{d_{i}\})\ \and\ |S_{i}|=O_{i}

Propagators for such an open constraint have not yet been included in constraint solvers. In [34], a propagator is proposed for the case where OiO_{i}’s are ground intervals. In the decomposition above, the OiO_{i}’s can either be variables or ground intervals. However, even when OiO_{i}’s are ground intervals, both the decomposition and the propagator presented in [34] hinder propagation and are incomparable to each other.

Theorem 23

Even if OiO_{i}’s are ground intervals, (1) HC on the OpenGcc constraint is stronger than HC on the decomposition using Roots constraints, (2) the propagator in [34] and HC on the decomposition using Roots constraints are incomparable.

Proof: (1) Consider X1,X2{1,2}X_{1},X_{2}\in\{1,2\}, X3{1,2,3}X_{3}\in\{1,2,3\}, di=id_{i}=i, S={1,2,3}S=\{1,2,3\} and O1,O2,O3=[0,1]O_{1},O_{2},O_{3}=[0,1]. The decomposition is HC (with {}S1,S2{1,2,3}\{\}\subseteq S_{1},S_{2}\subseteq\{1,2,3\} and {}S3{3}\{\}\subseteq S_{3}\subseteq\{3\}). However, enforcing HC on the OpenGcc constraint will prune 1 and 2 from X3X_{3}.

(2) Consider the example in case (1). The propagator in [34] will prune 1 and 2 from X3X_{3} whereas the decomposition is HC. Consider X1{1,2}X_{1}\in\{1,2\}, X2{2,3}X_{2}\in\{2,3\}, X3{3,4}X_{3}\in\{3,4\}, di=id_{i}=i, {}S{1,2,3}\{\}\subseteq S\subseteq\{1,2,3\} and O1=[1,1]O_{1}=[1,1], O2=[0,1]O_{2}=[0,1], O3=[0,0]O_{3}=[0,0], O4=[0,0]O_{4}=[0,0]. The propagator in [34] will prune the only value in the XiX_{i} variables which is not HC, that is, value 2 for X1X_{1}. It will not prune the bounds on SS. However, enforcing HC on the decomposition using Roots constraints will set S1={1}S_{1}=\{1\}, then will prune value 2 for X1X_{1}, will shrink S2S_{2} to {}S2{2}\{\}\subseteq S_{2}\subseteq\{2\}, will set S3=S4={}S_{3}=S_{4}=\{\} and will finally shrink SS to {1}S{1,2}\{1\}\subseteq S\subseteq\{1,2\}. \Box

As observed in [34], the definition of OpenGcc subsumes the definition for the open version of the AllDifferent constraint. Given variables X1,..,XnX_{1},..,X_{n} and a set variable SS, S{1..n}\emptyset\subseteq S\subseteq\{1..n\}, OpenAllDifferent([X1,..,Xn],S)\mbox{\sc OpenAllDifferent}([X_{1},..,X_{n}],S) holds iff XiXj,i,jSX_{i}\neq X_{j},\forall i,j\in S. Interestingly, this constraint can be decomposed using Range in almost the same way as AllDifferent was decomposed in Section 6.1.1.

OpenAllDifferent([X1,..,Xn],S)iff\displaystyle\mbox{\sc OpenAllDifferent}([X_{1},..,X_{n}],S)\ \ \mbox{\rm iff}
Range([X1,..,Xn],S,T) and |S|=|T|\displaystyle\mbox{\sc Range}([X_{1},..,X_{n}],S,T)\ \and\ |S|=|T|

Not surprisingly, this decomposition hinders propagation (see the example used in Theorem 8 to show that the decomposition of AllDifferent using Range hinders propagation). Nevertheless, as in the case of OpenGcc, we do not know of any polynomial algorithm for achieving HC on OpenAllDifferent.

6.5 Applications beyond counting and occurrence constraints

The Range and Roots constraints are useful for specifying a wide range of counting and occurrence constraints. Nevertheless, their expressive power permits their use to specify many other constraints.

6.5.1 Element

The Element constraint introduced in [31] indexes into an array with a variable. More precisely, Element(I,[X1,..,Xn],J)\mbox{\sc Element}(I,[X_{1},..,X_{n}],J) holds iff XI=JX_{I}=J. For example, we can use such a constraint to look up the price of a component included in a configuration problem. The Element constraint can be decomposed into a Range constraint without hindering propagation:

Element(I,[X1,..,Xn],J)iff|S|=|T|=1 and\displaystyle\mbox{\sc Element}(I,[X_{1},..,X_{n}],J)\ \ \mbox{\rm iff}\ \ |S|=|T|=1\ \and
IS and JT and Range([X1,..,Xn],S,T)\displaystyle I\in S\ \and\ J\in T\ \and\ \mbox{\sc Range}([X_{1},..,X_{n}],S,T)
Theorem 24

GAC on Element is equivalent to HC on the decomposition.

Proof: SS has all the values in the domain of II in its upper bound. Similarly TT has all the values in the domain of JJ in its upper bound. In addition, SS and TT are forced to take a single value. Thus enforcing HC on Range([X1,..,Xn],S,T)\mbox{\sc Range}([X_{1},..,X_{n}],S,T) has the same effect as enforcing GAC on Element(I,[X1,..,Xn],J)\mbox{\sc Element}(I,[X_{1},..,X_{n}],J). \Box

6.5.2 Global contiguity

The Contiguity constraint ensures that, in a sequence of 0/1 variables, those taking the value 1 appear contiguously. This is a discrete form of convexity. The constraint was introduced in [21] to model a hardware configuration problem. It can be decomposed into a Roots constraint:

Contiguity([X1,..,Xn])iff\displaystyle\mbox{\sc Contiguity}([X_{1},..,X_{n}])\ \ \mbox{\rm iff}
Roots([X1,..,Xn],S,{1}) and\displaystyle\mbox{\sc Roots}([X_{1},..,X_{n}],S,\{1\})\ \and
X=max(S) and Y=min(S) and |S|=XY+1\displaystyle X=\max(S)\ \and\ Y=\min(S)\ \and\ |S|=X-Y+1

Again it is polynomial to enforce HC on this case of the Roots constraint. Unfortunately, decomposition hinders propagation. Whilst Range and Roots can specify concepts quite distant from counting and occurrences like convexity, it seems that we may need other algorithmic ideas to propagate them effectively.

Theorem 25

GAC on Contiguity is stronger than HC on the decomposition.

Proof: Consider X1,X3{0,1}X_{1},X_{3}\in\{0,1\}, X2,X4{1}X_{2},X_{4}\in\{1\}. Hybrid consistency on the decomposition will enforce {2,4}S{1,2,3,4}\{2,4\}\subseteq S\subseteq\{1,2,3,4\}, X{4}X\in\{4\}, Y{1,2}Y\in\{1,2\} and |S||S| to be in {3,4}\{3,4\} but no pruning will happen. However, enforcing GAC on Contiguity([X1,..,Xn])\mbox{\sc Contiguity}([X_{1},..,X_{n}]) will prune 0 from X3X_{3}. \Box

7 Experimental results

We now experimentally assess the value of using the Range and Roots constraints in specifying global counting and occurrence constraints. For these experiments, we implemented an algorithm achieving HC on Range and an algorithm achieving HC on the decomposition of Roots presented in Section 5.2. Note that our algorithm for the decomposition of Roots does not use the Ilog Solver primitives 𝚖𝚎𝚖𝚋𝚎𝚛(value,set){\tt member}(value,set) and 𝚗𝚘𝚝𝚖𝚎𝚖𝚋𝚎𝚛(value,set){\tt not\-member}(value,set) because Ilog Solver does not appear to give complete propagation on combinations of such primitives (see the discussion in Section 5.5). We therefore implemented our own algorithms from scratch.

7.1 Pruning power of Roots

In Section 5.2 we proposed a decomposition of the Roots constraint into simple implications. The purpose of this subsection is to measure the pruning power of HC on the decomposition of Roots with respect to HC on the original Roots constraint when we do not meet any of the conditions that make HC on the decomposition equivalent to HC on the original constraint (see Section 5.3). We should bear in mind that enforcing HC on the Roots constraint is NP-hard in general. In order to enforce HC on the Roots constraint we used a simple table constraint (i.e., a constraint in extension) that has an exponential time and space complexity. Consequently, the size of the instances on which we were able to run this filtering method was severely constrained.

An instance is a set of integer variables {X1,..Xn}\{X_{1},..X_{n}\} and two set variables SS and TT. It can be described by a tuple n,m,k,r\langle n,m,k,r\rangle. The parameter nn stands for the number of integer variables. These nn variables are initialised with the domain {1,,m}\{1,\ldots,m\}. The upper bound of SS is initialised with {1,,n}\{1,\ldots,n\} and the upper bound of TT is initialised with {1,,m}\{1,\ldots,m\}. The parameter kk corresponds to the number of elements of the set variable SS (resp. set variable TT) that are, with equal probability, either put in the lower bound or excluded from the upper bound of SS (resp. of TT). Finally, the parameter rr is the total number of values removed, with uniform probabilities from the domains of the integer variables, keeping at least one value per domain. We generated 10001000 random instances for each combination of n,m[4,..6]n,m\in[4,..6], k[1..min(n,m)]k\in[1..min(n,m)] and r[1..n(m1)]r\in[1..n(m-1)].

For each one of the instances we generated, we propagated Roots([X1,..Xn],S,T)([X_{1},..X_{n}],S,T) using either the table constraint (enforcing HC), or our decomposition (enforcing HC in special cases). We observed that on 2929 out of the 3232 combinations of the parameters nn, mm and kk, the decomposition achieves HC for all 10001000 instances of every value of rr. On the remaining three classes (4,6,3,\langle 4,6,3,*\rangle, 5,6,3,\langle 5,6,3,*\rangle and 6,6,3,\langle 6,6,3,*\rangle), the decomposition fails to detect 0.003%0.003\% of the inconsistent values.

As a second experiment, we used the same instances expect that we did not fix or remove kk values randomly from TT, that is, in all instances, lb(T)=lb(T)=\emptyset and ub(T)={1,,m}ub(T)=\{1,\ldots,m\}. All other settings remained equal. By doing so, we allowed the random domains to reach situations equivalent to that of the counter example given in the proof of Theorem 4. With this setting, we observed that the decomposition still achieves HC on 1818 out of the 3232 combinations of the parameters nn, mm and kk, for all 10001000 instances of every value of rr. On the remaining classes, the percentage of inconsistent values not pruned by the decomposition increases to 0.039%0.039\%.

Clearly, this experiment is limited in its scope, first by the relatively small size of the instances, and second by the choices made for generating random domains. However, we conclude that examples of inconsistent values not being detected by the decomposition appear to be rare.

7.2 Pruning power and efficiency of Range

Contrary to the Roots constraint, we have a complete HC propagator for the Range constraint. Thus, we do not need to assess the pruning power of our propagator. Nevertheless, it can be interesting to compare the pruning power and the efficiency of decomposing a global constraint using Range or using another decomposition with simpler constraints.

The purpose of this subsection is to compare the decomposition of Uses using Range constraints against a simple decomposition using more elementary constraints. We chose the Uses constraint because it is NP-hard to achieve GAC on the Uses constraint (see Section 6.1.4) and there is no propagator available for this constraint in the literature. Furthermore, one of the time-tabling problems at the University of Montpellier can easily be modelled as a CSP with Uses constraints. We first compare the two decompositions of Uses (with or without Range) in terms of run-time as well as pruning power on random CSPs. Then, we solve the problem of building the set of courses in the Master of Computer Science at the University of Montpellier with the two decompositions.

7.2.1 Random CSPs

In order to isolate the effect of the Range constraint from other modelling issues, we used the following protocol: we randomly generated instances of binary CSPs and we added Uses([X1,..,Xn],[Y1,..,Yn][X_{1},..,X_{n}],[Y_{1},..,Y_{n}]) constraints. In all our experiments, we encode Uses in two different ways:

[range]:

by decomposing Uses using Range as described in Section 6.1.4,

[decomp]:

by decomposing the Uses constraint using primitive constraints as described next.

Uses([X1,..,Xn],[Y1,..,Yn])iff\mbox{\sc Uses}([X_{1},..,X_{n}],[Y_{1},..,Y_{n}])\ \ \mbox{\rm iff}
iSXiTjTiS.Xi=j\hskip 85.35826pti\in S\rightarrow X_{i}\in T~\wedge~j\in T\rightarrow\exists i\in S.X_{i}=j\wedge~~~~~~
iSYiTjTiS.Yi=j\hskip 85.35826pti\in S^{\prime}\rightarrow Y_{i}\in T^{\prime}~\wedge~j\in T^{\prime}\rightarrow\exists i\in S^{\prime}.Y_{i}=j\wedge~~~~~~
TT\hskip 85.35826ptT\subseteq T^{\prime}

The problem instances are generated according to model B in [23], and can be described with the following parameters: the number of XX and YY variables nxnx and nyny in Uses constraints, the total number of variables nznz, the domain size dd, the number of binary constraint m1m_{1}, the number of forbidden tuples tt per binary constraint, and the number of Uses constraints m2m_{2}. Note that the Uses constraints can have overlapping or disjoint scopes of variables. We distinguish the two cases. All reported results are averages on 1000 instances.

Figure 4: Propagating random binary constraint satisfaction problems with three overlapping Uses constraints (class A).

Our first experiment studies the effectiveness of decomposing Uses with Range for propagation alone (not solving). We compared the number of values removed by propagation on the models obtained by representing Uses constraints in two different ways, either using Range (range) or using the simple decomposition (decomp). To simulate what happens inside a backtrack search, we repeatedly and randomly choose a variable, assign it to one of its values and propagate the set of random binary constraints. After doing so for a given number of variables, if the CSP is still consistent, we enforce HC on each one of the two decompositions above. Hence, in the experiments, the constraints are exposed to a wide range of different variable domains. We report the ratio of values removed by propagation on the following classes of problems:

classA:\displaystyle class~A: nx=5,ny=10,nz=35,d=20,m1=70,t=150,m2=3(overlap)\displaystyle\langle nx=5,ny=10,nz=35,d=20,m_{1}=70,t=150,m_{2}=3\ (overlap)\rangle
classB:\displaystyle class~B: nx=5,ny=10,nz=45,d=20,m1=90,t=150,m2=3(disjoint)\displaystyle\langle nx=5,ny=10,nz=45,d=20,m_{1}=90,t=150,m_{2}=3\ (disjoint)\rangle

in which the number of assigned variables varies between 1 and 14. A failure detected by the propagation algorithm yields a ratio of 1 (all values are removed).

We observe in Figures 4 and 5 that propagating the Uses constraint using the Range constraint (range model) is much more effective than propagating it using the decomposition using elementary constraints (decomp model). In certain cases, the range model more than doubles the amount of values pruned. For instance after 77 random assignments the decomp model prunes only 28.8% of the values for the first problem class (Fig. 4) and 4.4% for the second (Fig. 5) whilst the Range algorithm respectively prunes 56% and 10.2% of the values. As we see in the next experiments, such a difference in pruning can map to considerable savings when solving a problem.

Figure 5: Propagating random binary constraint satisfaction problems with three disjoint Uses constraints (class B).

Our second experiment studies the efficiency of decomposing Uses with Range when solving the problems. Our solver used the smallest-domain-first variable ordering heuristic with the lexicographical value ordering and a cut-off at 600 seconds. We compared the cost of solving the two types of models: range and decomp. We report the number of fails and the cpu-time needed to find the first solution on the following classes of problems:

classC:\displaystyle class~C: nx=5,ny=10,nz=25,d=10,m1=40,t,m2=2\displaystyle\langle nx=5,ny=10,nz=25,d=10,m_{1}=40,t,m_{2}=2\rangle
classD:\displaystyle class~D: nx=5,ny=10,nz=30,d=10,m1=60,t,m2=2\displaystyle\langle nx=5,ny=10,nz=30,d=10,m_{1}=60,t,m_{2}=2\rangle

in which tt varies between 30 and 80.

Refer to caption
Refer to caption
Figure 6: Solving random binary constraint satisfaction problems with two overlapping Uses constraints (class C).
Refer to caption
Refer to caption
Figure 7: Solving random binary constraint satisfaction problems with two disjoint Uses constraints (class D).

We observe in Figures 6 and 7 that using the decomposition using the elementary constraints (decomp model) is not efficient (note the log scale). The instances solved here (classes C and D) are much smaller than those used for propagation (classes A and B). Solving larger instances was impractical. This second experiment shows that Range can reasonably solve problems containing Uses constraints. It also shows the clear benefit of using our algorithm in preference to the decomposition using elementary constraints over the under-constrained region. As the problems get over-constrained, the binary constraints dominate the pruning, and the algorithm has a slight overhead in run-time, pruning the same as the decomposition using elementary constraints.

7.2.2 Problem of the courses in the master of computer science

To confirm the results obtained on several types of random instances, we tackle the problem of deciding which courses to run in the Master of Computer Science at the University of Montpellier. This problem, which is usually solved by hand with the help of an Excel program, can be specified as follows. The second year of the Master of Computer Science advertises a set CC of possible courses. There is a set LL of nn lecturers who have skills to teach some subset of the courses (between 1 and 9 per lecturer). There is a set SS of mm students who bid for which courses they would like to attend (between 6 and 10 bids per student). A course runs only if at least 5 students bid for it. Every lecturer participates in just one course, but several lecturers can be assigned to the same course. There is also a set PLP\subseteq L of professors who are in charge of the course in which they participate. The goal is to run enough courses so that all lecturers are assigned to one course and all students can attend at least one of the courses for which they bid.

The models we used have variables LiL_{i} representing which course is taught by lecturer ii and variables SjS_{j} representing one of the courses student jj wants to attend. D(Li)D(L_{i}) contains all courses lecturer ii can teach except those that received less than 5 bids. D(Sj)D(S_{j}) contains all courses student jj has bid for, except those that received less than 5 bids. We put a constraint Uses([L1,,Ln],[S1,,Sm])\mbox{\sc Uses}([L_{1},\ldots,L_{n}],[S_{1},\ldots,S_{m}]) and a constraint AllDifferent(Li1,,Lip)\mbox{\sc AllDifferent}(L_{i_{1}},\ldots,L_{i_{p}}) where {Li1,,Lip}=P\{L_{i_{1}},\ldots,L_{i_{p}}\}=P. Model range decomposes Uses with Range, and model decomp decomposes Uses with primitive constraints as described in Section 7.2.1.

In the only instance we could obtain from the university, year-2008, there are 50 lecturers, 26 professors, 53 courses, and 177 students. We solved year-2008, both with model decomp and with model range. Both models could find a solution in a few milliseconds.

We modified the two models so that the satisfaction of the students is improved. Instead of trying to satisfy only one of their choices, we try now to satisfy kk choices. The models are modified in the following way. We create kk copies of each variable SjS_{j}, that is, Sj1,Sj2,,SjkS^{1}_{j},S^{2}_{j},\ldots,S^{k}_{j}, with D(Sji)D(S^{i}_{j}) containing the same values as D(Sj)D(S_{j}) (see above). We post constraints Sj1<Sj2<<SjkS^{1}_{j}<S^{2}_{j}<\ldots<S^{k}_{j} that break symmetries and guarantee that Sj1,Sj2,,SjkS^{1}_{j},S^{2}_{j},\ldots,S^{k}_{j} all take different values. Then, instead of having a single Uses constraint, we have kk Uses constraints, one on each set S1i,S2i,,SmiS^{i}_{1},S^{i}_{2},\ldots,S^{i}_{m} of variables: Uses([L1,,Ln],[S11,,Sm1])\mbox{\sc Uses}([L_{1},\ldots,L_{n}],[S^{1}_{1},\ldots,S^{1}_{m}]), \ldots, Uses([L1,,Ln],[S1k,,Smk])\mbox{\sc Uses}([L_{1},\ldots,L_{n}],[S^{k}_{1},\ldots,S^{k}_{m}]). Model range-kk decomposes Uses with Range, and model decomp-kk decomposes Uses with primitive constraints as described in Section 7.2.1.

We solved instance year-2008 with k=2,3,4,5k=2,3,4,5. When k=2k=2 or k=3k=3, both models find a solution in a few milliseconds, decomp-kk being slightly faster than range-kk. range-4 finds a solution in 4 fails and 5.83 sec. whereas decomp-4 was stopped after 24 hours without finding any solution. range-5 and decomp-5 were stopped after 24 hours without finding any solution or proving that none exists. This experiment shows that it can be effective to solve a real-world problem containing a global constraint like Uses by specifying it with Range instead of using a decomposition with elementary constraints.

7.3 Solving problems using Range and Roots

In Section 7.2.2, we showed how decomposing a global constraint with Range can be useful to solve a real-world problem. In this subsection we study another real-world problem that involves a greater variety of global constraints, some allowing decompositions with Range, some others with Roots. More importantly, we will compare monolithic propagators of existing well-known global constraints with their decompositions using Range and Roots. The purpose of this subsection is to see if solving real-world constraint problems using Range and Roots leads to acceptable performance compared to specialised global constraints and their propagators.

We used a model for the Mystery Shopper problem [16] due to Helmut Simonis that appears in CSPLib (prob004). We used the same problem instances as in [10] but perform a more thorough and extensive analysis. We partition the constraints of this problem into three groups:

Temporal and geographical:

All visits for any week are made by different shoppers. Similarly, a particular area cannot be visited more than once by the same shopper.

Shopper:

Each shopper makes exactly the required number of visits.

Saleslady:

A saleslady must be visited by some shoppers from at least 2 different groups (the shoppers are partitioned into groups).

The first group of constraints can be modelled by using AllDifferent constraints [25], the second can be modelled by Gcc [26] and the third by Among constraints [4]. We experimented with several models using Ilog Solver where these constraints are either implemented as their Ilog Solver primitives (respectively, IloAllDiff, IloDistribute, and a decomposition using IloSum on Boolean variables) or as their decompositions with Range and Roots. The decomposition of Among([X1,..,Xn],[d1,..,dm],N)\mbox{\sc Among}([X_{1},..,X_{n}],[d_{1},..,d_{m}],N) we use is the one presented in [6], that is, (Bi=1Xi[d1,..,dm]),i1..niBi=N(B_{i}=1\leftrightarrow X_{i}\in[d_{1},..,d_{m}]),\forall i\in 1..n\land\sum_{i}B_{i}=N. Note that this decomposition of the Among constraint maintains GAC in theory [6]. This decomposition can be implemented in many solvers using disjunctions of membership constraints: 𝚘𝚛(𝚗𝚘𝚝𝚖𝚎𝚖𝚋𝚎𝚛(Xi,[d1,..,dm]),Bi=1){\tt or}({\tt notmember}(X_{i},[d_{1},..,d_{m}]),B_{i}=1) and 𝚘𝚛(𝚖𝚎𝚖𝚋𝚎𝚛(Xi,[d1,..,dm]),Bi=0){\tt or}({\tt member}(X_{i},[d_{1},..,d_{m}]),B_{i}=0). Unfortunately, Ilog Solver does not appear to achieve GAC on such disjunctions of primitives because the negated membership constraint 𝚗𝚘𝚝𝚖𝚎𝚖𝚋𝚎𝚛(Xi,[d1,..,dm]){\tt notmember}(X_{i},[d_{1},..,d_{m}]) is activated only if XiX_{i} is instantiated with a value in [d1,..,dm][d_{1},..,d_{m}] whereas it should be as soon as D(Xi)[d1,..,dm]D(X_{i})\subseteq[d_{1},..,d_{m}].

We report results for the following representative models:

  • Alld-Gcc-Sum uses only Ilog Solver primitives;

  • Alld-Gcc-Roots where Among is encoded using Roots;

  • Alld-Roots-Sum where Gcc is encoded using Roots;

  • Range-Gcc-Sum where AllDifferent is encoded using Range;

  • Alld-Roots-Roots where Among and Gcc are encoded using Roots;

Note that Among encoded as Roots uses the decomposition presented in Section 6.2.2, the Gcc uses the decomposition presented in Section 6.2.1, and AllDifferent uses the decomposition presented in Section 6.1.1.

We study the following important questions:

  • How does the Roots decomposition of the Among constraint compare to the Sum decomposition in terms of pruning and run-times?

  • Does the decomposition of Gcc using Roots lead to a reasonable and acceptable loss in performance?

  • Does the decomposition of AllDifferent using Range lead to a reasonable and acceptable loss in performance?

  • Do we gain in performance by branching on the set variables introduced by the Roots decomposition?

To answer the first question, we will compare the model Alld-Gcc-Sum against the model Alld-Gcc-Roots. To answer the second question, we will compare the model Alld-Gcc-Sum against the model Alld-Roots-Sum. To answer the third question, we will compare the model Alld-Gcc-Sum against the model Range-Gcc-Sum. To answer the fourth question, we will compare Alld-Gcc-Sum against the model Alld-Roots-Roots that branches on the set variables.

The instances we use in the experiments are generated as follows. For each number of salesladies s{10,15,20,25,30,35}s\in\{10,15,20,25,30,35\}, we generate (s+2/4)4\lceil(s+2/4)*4\rceil shoppers, 44 visits. Furthermore, to determine the partitioning of the outlets, we bound the number of salesladies per outlet between a lower bound and an upper bound and generate all possible partitions within these bounds. The number of instances for each class is as follows; for 10 salesladies we have 10 instances, for 15 salesladies we have 52 instances, for 20 salesladies we have 35 instances, for 25 salesladies we have 20 instances, for 30 salesladies we have 10 instances, and for 35 salesladies we have 56 instances.

We also tested two variable and value ordering heuristics:

  • We branch on the variables with the minimum domain first and assign values lexicographically. We refer to this as domdom;

  • We assign a shopper to each saleslady for the first, then for the second week and so on. This a static variables and value ordering heuristic. We refer to this as lexlex.

However, since lexlex was consistently better than domdom we only report the results using lexlex.

All instances solved in the experiments use a time limit of 5 minutes. For each class of instances we report the number of instances solved (#solved), the average cpu-time in seconds over all instances solved by the method (by self), the average cpu-time in seconds over all instances solved by both methods (by all), the average number of failures over all instances solved by the method (by self), the average number of failures over all instances solved by both methods (by all).

7.3.1 Among

Table 1: The sum decomposition of Among in the Mystery Shopper problem versus the Roots decomposition using lexlex as a branching strategy.
alld-gcc-sum-lex alld-gcc-roots-lex
Size #solved time (sec.) #fails #solved time (sec.) #fails
by self by all by self by all by self by all by self by all
10 9 0.01 0.01 0.89 0.89 9 0.01 0.01 0.89 0.89
15 29 0.07 0.07 431.55 431.55 29 0.07 0.07 281.90 281.90
20 25 0.02 0.02 10.60 10.60 25 0.02 0.02 9.48 9.48
25 16 0.03 0.03 7.06 7.06 16 0.04 0.04 7.00 7.00
30 6 0.05 0.05 50.00 50.00 6 0.07 0.07 49.67 49.67
35 31 0.23 0.23 414.68 414.68 31 0.24 0.24 269.32 269.32

When branching on the integer variables using lexlex (Table 1) strategy, the Alld-Gcc-Roots model tends to perform better than the Alld-Gcc-Sum model in terms of pruning (smaller number of fails). Note that the Sum decomposition misses some pruning because of the Ilog Solver propagators used in this decomposition, as explained at the beginning of Section 7.3. This explains the discrepancy. Both models solve the same number of instances. The results show that in this case of the Among constraint, our Roots decomposition is as efficient as the decomposition using elementary Sum constraints. Minor run-time differences are probably due to the cheaper propagator of Ilog Solver which achieves less pruning.

7.3.2 Gcc

The Gcc constraint is one of the most efficient and effective global constraints available in most constraint toolkits. The results comparing the Alld-Gcc-Sum model versus its equivalent (the Alld-Roots-Sum model) where instead of Gcc constraints we use our decomposition using Roots are shown in Table 2. We observe that when branching on the integer variables using lexlex, the loss in terms of pruning due to our decomposition is very low: the difference in number of fails is less than 5% on the hardest instances. This means that our decomposition should scale well when size and difficulty of problems increases. The difference in run-times is larger (up to more than one order of magnitude). This can be explained in part by the propagation algorithms for Range and Roots that we have implemented in Ilog Solver. They are far from being optimised, as opposed to the highly specialised native Gcc propagator. Overall, the loss appears to be acceptable. Our results show that, for the Gcc constraint, the decomposition into Roots leads to adequate performance for prototyping. Nevertheless, providing more efficient propagators for Roots is an interesting and open issue.

Table 2: The Gcc constraints in the Mystery Shopper problem versus the Roots decomposition using lexlex as a branching strategy.
alld-gcc-sum-lex alld-roots-sum-lex
Size #solved time (sec.) #fails #solved time (sec.) #fails
by self by all by self by all by self by all by self by all
10 9 0.01 0.01 0.89 0.89 9 0.01 0.01 1.78 1.78
15 29 0.07 0.07 431.55 431.55 29 0.43 0.43 434.38 434.38
20 25 0.02 0.02 10.60 10.60 25 0.10 0.10 10.60 10.60
25 16 0.03 0.03 7.06 7.06 16 0.23 0.23 38.31 38.31
30 6 0.05 0.05 50.00 50.00 6 0.43 0.43 72.33 72.33
35 31 0.23 0.27 414.68 505.48 23 3.89 3.89 521.74 521.74

7.3.3 Alldifferent

The AllDifferent constraint is again one of the most efficient and effective global constraints available in most constraint toolkits. The results comparing the Alld-Gcc-Sum model versus its equivalent (the Range-Gcc-Sum model) where instead of AllDifferent constraints we use our decomposition using Range are shown in Table 3. We observe that when branching on the integer variables using lexlex both methods achieve the same amount of pruning even if we are not in a case where AllDifferent constraints are Permutation constraints (see Section 6.1.1). This means that even when our decomposition using Range theoretically hinders propagation, it can in practice achieve GAC. Concerning run-time efficiency, we observe that both methods solve the same number of instances. This is probably a consequence of the good level of pruning achieved by the decomposition of AllDifferent using Range. But the Alld-Gcc-Sum model is usually faster, up to one order of magnitude in the extreme case. Again, this can be explained in part by our basic implementation of the Range and Roots propagators in Ilog Solver, as opposed to the highly specialised native AllDifferent propagator.

Table 3: The AllDifferent constraints in the Mystery Shopper problem versus the Range decomposition using lexlex as a branching strategy.
alld-gcc-sum-lex range-gcc-sum-lex
Size #solved time (sec.) #fails #solved time (sec.) #fails
by self by all by self by all by self by all by self by all
10 9 0.01 0.01 0.89 0.89 9 0.02 0.02 0.89 0.89
15 29 0.07 0.07 431.55 431.55 29 0.18 0.18 431.55 431.55
20 25 0.02 0.02 10.60 10.60 25 0.17 0.17 10.60 10.60
25 16 0.03 0.03 7.06 7.06 16 0.32 0.32 7.06 7.06
30 6 0.05 0.05 50.00 50.00 6 0.57 0.57 50.00 50.00
35 31 0.23 0.23 414.68 414.68 31 1.39 1.39 414.68 414.68

7.3.4 Exploiting the set variables

Table 4: Branching on set variables in the Mystery Shoppers Problem
alld-gcc-sum-lex alld-roots-roots-set
Size #solved time (sec.) #fails #solved time (sec.) #fails
by self by all by self by all by self by all by self by all
10 9 0.01 0.01 0.89 0.89 10 0.05 0.05 98.20 91.33
15 29 0.07 0.07 431.55 431.55 52 0.12 0.05 102.83 23.34
20 25 0.02 0.02 10.60 10.60 35 1.30 1.25 852.14 794.20
25 16 0.03 0.03 7.06 7.06 20 5.08 5.12 2218.00 2170.12
30 6 0.05 0.05 50.00 50.00 10 15.05 3.65 4476.40 1675.33
35 31 0.23 0.23 414.68 412.24 51 33.88 35.86 6111.67 6410.14

In the previous subsections, we have seen that decomposing global constraints with Range and Roots constraints is a viable approach. Such decompositions generally give very small (if any) loss in terms of pruning and they give acceptable run-time performance. However, we have seen that our basic decomposition using Roots can be slow compared to highly specialised propagators such as those used by Ilog Solver for the Gcc constraint. In this subsection, we show that, even without optimising our code, we can improve the run-time performance of our decomposition just by exploiting its internal structure through the extra variables it introduces.

The decomposition of global constraints using Range and Roots introduces extra set variables. We here explore the possibility of branching on the set variables as follows. We branch on the set variables first, then on the integer variables with min domain once all set variables are instantiated. We refer to this as setset. We compare the best model that uses the available constraints in Ilog Solver (model Alld-Gcc-Sum) versus the best model that branches on the set variables (model Alld-Roots-Roots, in which the Among and the Gcc constraints are expressed using the Roots constraint). Surprisingly, we solve significantly more instances when branching on the set variables than the model Alld-Gcc-Sum. But, again, Alld-Gcc-Sum is a more efficient model when it manages to solve the instance.

These results are primarily due to the better branching strategy. However, such a strategy would not be easily implementable without Roots since the extra set variables are part of it. We observe here that the extra set variables introduced by the Roots decomposition may provide new possibilities for branching strategies that might be beneficial in practice.

These results show that by simply changing the branching strategy so that it exploits the internal structure of the decompositions, we obtain a significant increase in performance. This gain compensates the loss in cpu-time caused by the preliminary nature of our implementation.

8 Conclusion

We have proposed two global constraints useful in specifying many counting and occurrence constraints: the Range constraint which computes the range of values used by a set of variables, and the Roots constraint which computes the variables in a set mapping onto particular values. These two constraints capture the notion of image and domain of a function, making them easy to understand to the non expert in constraint programming. We have shown that these two constraints can easily specify counting and occurrence constraints. For example, the open versions of some well-known global constraints can be specified with Range and Roots. Beyond counting and occurrence constraints, we have shown that the expressive power of Range and Roots allows them to specify many other constraints.

We have proposed propagation algorithms for these two constraints. Hence, any global constraint specified using Range and Roots can be propagated. In some cases, this gives a propagation algorithm which achieves GAC on the original global constraint (e.g. the Permutation and Among constraints). In other cases, this propagation algorithm may not make the original constraint GAC, but achieving GAC is NP-hard (e.g. the NValue and Common constraints). Decomposition is then one method to obtain a polynomial algorithm. In the remaining cases, the propagation algorithm may not make the constraint GAC, although specialised propagation algorithms can do so in polynomial time (e.g. the SymAllDiff constraint). Our method can still be attractive in this last case as it provides a generic means of propagation for counting and occurrence constraints when specialised algorithms have not yet been proposed or are not available in the constraint toolkit.

We have presented a comprehensive study of the Range constraint. We proposed an algorithm for enforcing hybrid consistency on Range. We also have presented a comprehensive study of the Roots constraint. We proved that propagating completely the Roots constraint is intractable in general. We therefore proposed a decomposition to propagate it partially. This decomposition achieves hybrid consistency on the Roots constraint under some simple conditions often met in practice. In addition, enforcing bound consistency on the decomposition achieves bound consistency on the Roots constraint whatever conditions hold.

Our experiments show the benefit we can obtain by incorporating the Range and the Roots constraints in a constraint toolkit. First, despite being intractable, the Roots constraint can be propagated using the decomposition we presented. Even if this decomposition hinders propagation in theory, our experiments show that it is seldom the case in practice. Second, in the absence of specialised propagation algorithms, Range and Roots appear to be a simple and a reasonable method for propagating (possibly intractable) global constraints that is competitive to other decompositions into more elementary constraints. Our experiments show that sometimes we do better than these other decompositions either in terms of pruning or in solution time or both (like the case of the decomposition of the Uses constraint). In addition, compared to highly specialised propagation algorithms like those for the AllDifferent and Gcc constraints in Ilog Solver, the loss in performance when using Range and Roots was not great. Thus, if the constraint toolkit lacks a specialised propagation algorithm, Range and Roots offer a quick, easy, and acceptable way of propagation. Finally, we observed that the extra set variables introduced in Range and Roots decompositions can be exploited in the design of new branching strategies. These extra set variables may provide both a modelling and solving advantage to the user. We hope that by presenting these results, developers of the many different constraint toolkits will be encouraged to include the Range and Roots constraints into their solvers.

Acknowledgements

We thank Eric Bourreau for having provided the data for the problem of the master of computer science of the university of Montpellier. We also thank our reviewers for their helpful comments which improved this paper.

References

  • [1] R.K. Ahuja, T.L. Magnanti, and J.B. Orlin. Network flows. Prentice Hall, Upper Saddle River NJ, 1993.
  • [2] N. Beldiceanu. Global constraints as graph properties on a structured network of elementary constraints of the same type. Technical report, Swedish Institute of Computer Science, 2000. SICS Technical Report T2000/01.
  • [3] N. Beldiceanu. Pruning for the minimum constraint family and for the number of distinct values constraint family. In T. Walsh, editor, CP, volume 2239 of Lecture Notes in Computer Science, pages 211–224. Springer, 2001.
  • [4] N. Beldiceanu and E. Contejean. Introducing global constraints in CHIP. Mathl. Comput. Modelling, 20:97–123, no. 12 1994.
  • [5] N. Beldiceanu, I. Katriel, and S. Thiel. Filtering algorithms for the same and usedby constraints. In MPI Technical Report MPI-I-2004-1-001, 2004.
  • [6] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan, and T. Walsh. Among, common and disjoint constraints. In B. Hnich, M. Carlsson, F. Fages, and F. Rossi, editors, CSCLP, volume 3978 of Lecture Notes in Computer Science, pages 29–43. Springer, 2005.
  • [7] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan, and T. Walsh. Filtering algorithms for the NVALUE constraint. Constraints, 11(4):271–293, 2006.
  • [8] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan, and T. Walsh. Filtering algorithms for the NVALUE constraint. In R. Bartak and M. Milano, editors, CPAIOR, volume 3524 of Lecture Notes in Computer Science, pages 79–93. Springer, 2005.
  • [9] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan, and T. Walsh. The RANGE and ROOTS constraints: some applications. Technical report COMIC-2006-003, 2006.
  • [10] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan, and T. Walsh. The RANGE and ROOTS constraints: Specifying counting and occurrence problems. In L.P. Kaelbling and A. Saffiotti, editors, IJCAI, pages 60–65. Professional Book Center, 2005.
  • [11] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan, and T. Walsh. The RANGE constraint: Algorithms and implementation. In J.C. Beck and B.M. Smith, editors, CPAIOR, volume 3990 of Lecture Notes in Computer Science, pages 59–73. Springer, 2006.
  • [12] C. Bessiere, E. Hebrard, B. Hnich, Z. Kiziltan, and T. Walsh. The ROOTS constraint. In F. Benhamou, editor, CP, volume 4204 of Lecture Notes in Computer Science, pages 75–90. Springer, 2006.
  • [13] C. Bessiere, E. Hebrard, B. Hnich, and T. Walsh. The complexity of global constraints. In D.L. McGuinness and G. Ferguson, editors, AAAI, pages 112–117. AAAI Press / The MIT Press, 2004.
  • [14] C. Bessiere, E. Hebrard, B. Hnich, and T. Walsh. The complexity of reasoning with global constraints. Constraints, 12(2):239–259, 2007.
  • [15] C. Bessiere, E. Hebrard, B. Hnich, and T. Walsh. The tractability of global constraints. In M. Wallace, editor, CP, volume 3258 of Lecture Notes in Computer Science, pages 716–720. Springer, 2004.
  • [16] B.M.W. Cheng, K.M.F. Choi, J.H.M. Lee, and J.C.K. Wu. Increasing constraint propagation by redundant modeling: an experience report. Constraints, 4(2):167–192, 1999.
  • [17] R. Debruyne and C. Bessiere. Some practicable filtering techniques for the constraint satisfaction problem. In IJCAI, pages 412–417, 1997.
  • [18] B. Hnich, Z. Kiziltan, and T. Walsh. Modelling a balanced academic curriculum problem. In CPAIOR, pages 121–131, 2002.
  • [19] ILOG. Reference and User Manual. ILOG Solver 5.3, ILOG S.A., 2002.
  • [20] F. Laburthe. Choco: implementing a CP kernel. In Proceedings of TRICS: Techniques foR Implementing Constraint programming Systems, a post-conference workshop of CP, Singapore, 2000.
  • [21] M. Maher. Analysis of a global contiguity constraint. In Proceedings of the Workshop on Rule Based Constraint Reasoning and Programming, held alongside CP, Ithaca NY, 2002.
  • [22] F. Pachet and P. Roy. Automatic generation of music programs. In J. Jaffar, editor, CP, volume 1713 of Lecture Notes in Computer Science, pages 331–345. Springer, 1999.
  • [23] P. Prosser. An empirical study of phase transitions in binary constraint satisfaction problems. Artif. Intell., 81(1-2):81–109, 1996.
  • [24] C.G. Quimper, A. López-Ortiz, P. van Beek, and A. Golynski. Improved algorithms for the global cardinality constraint. In M. Wallace, editor, CP, volume 3258 of Lecture Notes in Computer Science, pages 542–556. Springer, 2004.
  • [25] J.C. Régin. A filtering algorithm for constraints of difference in csps. In AAAI, pages 362–367, 1994.
  • [26] J.C. Régin. Generalized arc consistency for global cardinality constraint. In AAAI/IAAI, Vol. 1, pages 209–215, 1996.
  • [27] J.C. Régin. The symmetric alldiff constraint. In T. Dean, editor, IJCAI, pages 420–425. Morgan Kaufmann, 1999.
  • [28] F. Rossi, P. van Beek, and T. Walsh. Handbook of Constraint Programming, Elsevier, 2006.
  • [29] A. Schrijver. Combinatorial Optimization - Polyhedra and Efficiency. Springer-Verlag, Berlin, 2003.
  • [30] C. Schulte and P.J. Stuckey. Speeding up constraint propagation. In M. Wallace, editor, CP, volume 3258 of Lecture Notes in Computer Science, pages 619–633. Springer, 2004.
  • [31] P. Van Hentenryck and J.P. Carillon. Generality versus specificity: An experience with ai and or techniques. In AAAI, pages 660–664, 1988.
  • [32] P. Van Hentenryck and Y. Deville. The cardinality operator: A new logical connective for constraint logic programming. In ICLP, pages 745–759, 1991.
  • [33] P. Van Hentenryck, Y. Deville, and C.M. Teng. A generic arc-consistency algorithm and its specializations. Artif. Intell., 57(2-3):291–321, 1992.
  • [34] W.J. van Hoeve and J.C. Régin. Open constraints in a closed world. In J.C. Beck and B.M. Smith, editors, CPAIOR, volume 3990 of Lecture Notes in Computer Science, pages 244–257. Springer, 2006.