## 5.175. k_alldifferent

Origin
Constraint

$\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi  \pi °\pi \pi }\right)$

Synonyms

$\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi }$, $\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$, $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }$.

Type
 $\mathrm{\pi }$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi ‘}-\mathrm{\pi \pi \pi \pi }\right)$
Argument
 $\mathrm{\pi  \pi °\pi \pi }$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi \pi }-\mathrm{\pi }\right)$
Restrictions
 $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi },\mathrm{\pi ‘}\right)$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi  \pi °\pi \pi },\mathrm{\pi \pi \pi \pi }\right)$ $|\mathrm{\pi }|>0$ $|\mathrm{\pi  \pi °\pi \pi }|>0$
Purpose

For each collection of variables depicted by an item of $\mathrm{\pi  \pi °\pi \pi }$, enforce their corresponding variables to take distinct values.

Example
$\left(\begin{array}{c}β©\begin{array}{c}\mathrm{\pi \pi \pi \pi }-β©\begin{array}{c}\mathrm{\pi ‘}-5,\hfill \\ \mathrm{\pi ‘}-6,\hfill \\ \mathrm{\pi ‘}-0,\hfill \\ \mathrm{\pi ‘}-9,\hfill \\ \mathrm{\pi ‘}-3\hfill \end{array}βͺ,\hfill \\ \mathrm{\pi \pi \pi \pi }-β©5,6,1,2βͺ\hfill \end{array}βͺ\hfill \end{array}\right)$

The $\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint holds since all the values 5, 6, 0, 9 and 3 are distinct and since all the values 5, 6, 1 and 2 are distinct as well.

Typical
 $|\mathrm{\pi }|>1$ $|\mathrm{\pi  \pi °\pi \pi }|>1$
Symmetries
• Items of $\mathrm{\pi  \pi °\pi \pi }$ are permutable.

• Items of $\mathrm{\pi  \pi °\pi \pi }.\mathrm{\pi \pi \pi \pi }$ are permutable.

• All occurrences of two distinct values of $\mathrm{\pi  \pi °\pi \pi }.\mathrm{\pi \pi \pi \pi }.\mathrm{\pi ‘}$ can be swapped; all occurrences of a value of $\mathrm{\pi  \pi °\pi \pi }.\mathrm{\pi \pi \pi \pi }.\mathrm{\pi ‘}$ can be renamed to any unused value.

Usage

Systems of $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints sharing variables occurs frequently in practice. We give 4 typical problems that can be modelled by a combination of $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints as well as one problem where a system of $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints provides a necessary condition.

• The graph colouring problem is to colour with a restricted number of colours the vertices of a given undirected graph in such a way that adjacent vertices are coloured with distinct colours. The problem can be modelled by a system of $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints. All the next problems can been seen as graph colouring problems where the graphs have some specific structure.

• A Latin square of order $n$ is an $n\Gamma n$ array in which $n$ distinct numbers in $\left[1,n\right]$ are arranged so that each number occurs once in each row and column. The problem is to complete a partially filled Latin square. PartΒ (A) of FigureΒ 5.175.1 gives a partially filled Latin square, while partΒ (B) provides a possible completion.

• A Sudoku is a Latin square of order $9\Gamma 9$ such that the numbers in each major $3\Gamma 3$ block are distinct. As for the Latin square problem, the problem is to complete a partially filled board. PartΒ (A) of FigureΒ 5.175.2 gives a partially filled Sudoku board, while partΒ (B) provides a possible completion. A constraint programming approach for solving Sudoku puzzles is depicted inΒ [Simonis05]. It shows how to generate redundant constraints as well as shavingΒ [MartinShmoys96] in order to find a solution without guessing.

• A task assignment problem consists to assign a given set of non -preemptive tasks, which are fixed in time (i.e.,Β the origin, duration and end of each task are fixed), to a set of resources so that, tasks that are assigned to the same resource do not overlap in time. Each task can be assigned to a predefined set of resources. Problems like aircraft stand allocationΒ [DincbasSimonis91],Β [Simonis01] or air traffic flow managementΒ [BarnierBrisset02] correspond to an example of a real -life task assignment problem. Assignment of service professionalsΒ [AsafEranRichterConnorsGreshOrtegaMcinnis10] is yet another industrial example where professionals have to be assigned positions in such a way that positions assigned to a given professional do not overlap in time.

PartΒ (A) of FigureΒ 5.175.3 gives an example of task assignment problem. For each task we indicate the set of resources where it can potentially be assigned (i.e.,Β the domain of its assignment variable). For instance, task T1 can be assigned to resources 1 or 2. PartΒ (B) of FigureΒ 5.175.3 gives the corresponding interval graph: We have one vertex for each task and an edge between two tasks that overlap in time. We have a system of $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints corresponding to the maximum cliques of the interval graph (i.e.,Β $\left\{$T1,T5,T8$\right\}$, $\left\{$T2,T5,T8$\right\}$, $\left\{$T2,T6$\right\}$, $\left\{$T3,T6,T9$\right\}$, $\left\{$T3,T7,T9$\right\}$, $\left\{$T4,T7,T9$\right\}$). Finally, partΒ (C) of FigureΒ 5.175.3 provides a possible solution to the task assignment problem where tasks T1, T2, T9 are assigned to resource 1, tasks T3, T4, T8 are assigned to resource 2, and tasks T5, T6, T7 are assigned to resource 3.

• The tree partitioning with precedences problem is to compute a vertex -partitioning of a given digraph $\mathrm{\pi ’}$ in disjoint trees (i.e.,Β a forest), so that a given set of precedences holds. The problem can be modelled with a $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi ½\pi \pi \pi ΄\pi ΄},\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\right)$ constraint, where $\mathrm{\pi ½\pi \pi \pi ΄\pi ΄}$ is a domain variable specifying the numbers of trees in the forest and $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }$ is a collection of the digraph's $n$ vertices. Each item $v\beta \mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }$ has the following attributes, which complete the description of the digraph:

• $\mathrm{\pi \pi \pi \pi \pi ‘}$ is an integer in $\left[1,n\right]$ that can be interpreted as the label of $v$.

• $\mathrm{\pi \pi \pi \pi \pi \pi }$ is a domain variable whose domain consists of elements (vertex label) of $\left[1,n\right]$. It can be interpreted as the unique successor of $v$.

• $\mathrm{\pi \pi \pi \pi \pi }$ is a possibly empty set of integers, its elements (vertex label) being in $\left[1,n\right]$. It can be interpreted as the mandatory ancestors of $v$.

We model the $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint by the digraph $\mathrm{\pi ’}=\left(\mathrm{\pi ±},\mathrm{\beta °}\right)$ in which the vertices represent the elements of $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }$ and the arcs represent the successors relations between them. Formally, $\mathrm{\pi ’}$ is defined as follows:

• To the ${i}^{th}$ vertex $\left(1\beta €i\beta €n\right)$, $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[i\right]$, of the $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }$ collection corresponds a vertex of $\mathrm{\pi ±}$ denoted by ${v}_{i}$.

• For every pair of vertices $\left(\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[i\right]$,$\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[j\right]\right)$, where $i$ and $j$ are not necessarily distinct, there is an arc from ${v}_{i}$ to ${v}_{j}$ in $\mathrm{\beta °}$.

The $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint specifies that its associated digraph $\mathrm{\pi ’}$ should be a forest that fulfils the precedence constraints. Formally a ground instance of a $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi ½\pi \pi \pi ΄\pi ΄},\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\right)$ constraint is satisfied if and only if the following conditions hold:

1. $\beta i\beta \left[1,n\right]:\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[i\right].\mathrm{\pi \pi \pi \pi \pi ‘}=i$,

2. Its associated digraph $\mathrm{\pi ’}$ consists of $\mathrm{\pi ½\pi \pi \pi ΄\pi ΄}$ connected components,

3. Each connected component of $\mathrm{\pi ’}$ does not contain any circuit involving more than one vertex,

4. For every vertex $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[i\right]$ such that $j\beta \mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[i\right].\mathrm{\pi \pi \pi \pi \pi }$ there must be an elementary path in $\mathrm{\pi ’}$ from $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[j\right]$ to $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[i\right]$.

We can build the following system of $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints that corresponds to a necessary condition for the $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint: To each vertex $v$ of $\mathrm{\pi ’}$, which both has no predecessors and cannot be the root of a tree, we generate an $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint involving the father variables of those descendants of $v$ in $\mathrm{\pi ’}$ that cannot be the root of a tree.

For the set of precedences depicted by partΒ (A) of FigureΒ 5.175.4The number in a vertex gives the value of the $\mathrm{\pi \pi \pi \pi \pi ‘}$ attribute of the corresponding item., where we assume that $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[12\right]$ is the only vertex that can be a root and where ${F}_{i}$ denotes the father variable associated with $\mathrm{\pi  \pi ΄\pi \pi \pi Έ\pi ²\pi ΄\pi }\left[i\right]$, we get the following system of $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints:

The variables of these two $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints respectively correspond to the descendants of the two source vertices (i.e.,Β ${F}_{1}$ and ${F}_{2}$) of the precedence graph depicted by partΒ (A) of FigureΒ 5.175.4. On partΒ (A) of FigureΒ 5.175.4 the descendants of ${F}_{1}$ and ${F}_{2}$ are respectively depicted with a thick line and a grey circle. Their intersection, $\left\{{F}_{7},{F}_{10},{F}_{11},{F}_{12}\right\}$, from which we remove ${F}_{12}$ belong to the two $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints. In fact, ${F}_{12}$ is not mentioned in the two $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints since its corresponding vertex is the root of a tree. PartΒ (B) of FigureΒ 5.175.4 gives a possible tree satisfying all the precedences constraints expressed by partΒ (A), where precedences are depicted with a dotted line. It corresponds to the following ground solution:

 $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\beta ©$ $\mathrm{\pi \pi \pi \pi \pi ‘}-1$ $\mathrm{\pi \pi \pi \pi \pi \pi }-3$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-2$ $\mathrm{\pi \pi \pi \pi \pi \pi }-4$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-3$ $\mathrm{\pi \pi \pi \pi \pi \pi }-5$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{1\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-4$ $\mathrm{\pi \pi \pi \pi \pi \pi }-8$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{2\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-5$ $\mathrm{\pi \pi \pi \pi \pi \pi }-6$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{1\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-6$ $\mathrm{\pi \pi \pi \pi \pi \pi }-7$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{3\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-7$ $\mathrm{\pi \pi \pi \pi \pi \pi }-10$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{3,4\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-8$ $\mathrm{\pi \pi \pi \pi \pi \pi }-9$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{4\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-9$ $\mathrm{\pi \pi \pi \pi \pi \pi }-7$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{2\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-10$ $\mathrm{\pi \pi \pi \pi \pi \pi }-11$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{5,6,7\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-11$ $\mathrm{\pi \pi \pi \pi \pi \pi }-12$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{7,8,9\right\},$ Β $\mathrm{\pi \pi \pi \pi \pi ‘}-12$ $\mathrm{\pi \pi \pi \pi \pi \pi }-12$ $\mathrm{\pi \pi \pi \pi \pi }-\left\{10,11\right\}\beta ͺ\right)$
Remark

It was shown inΒ [ElbassioniKatrielKutzMahajan05b] that, finding out whether a system of two $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints sharing some variables has a solution or not is NP -hard. This was achieved by reduction from set packing.

A slight variation in the way of describing the arguments of the $\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint appears inΒ [RichterFreundNaveh06] under the name of $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }$: the set of disequalities is described by a set of pairs of variables, where each pair corresponds to a disequality constraint between two given variables.

Within the context of linear programming, a relaxation of the $\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint is provided inΒ [AppaMagosMourtos04]. The special case where $k=2$ is discussed inΒ [AppaMagosMourtos05].

Algorithm

Even if there is no filtering algorithm for the $\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint, one can enforce redundant constraints for the following patterns:

Several propagation rules for the $\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint are also described inΒ [LardeuxMonfroySaubion08].

Reformulation

Given two $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints that share some variables, a reformulation preserving bound-consistency was introduced inΒ [BessiereKatsirelosNarodytskaQuimperWalsh10]. This reformulation is based on an extension of Hall's theorem that is presented in the same paper.

generalisation: $\mathrm{\pi \pi \pi \pi \pi }$, $\mathrm{\pi \pi \pi \pi \pi }$Β (tasks for which the start attribute is not fixed).

Keywords

For all items of $\mathrm{\pi  \pi °\pi \pi }$:

Arc input(s)
$\mathrm{\pi  \pi °\pi \pi }.\mathrm{\pi \pi \pi \pi }$
Arc generator
$\mathrm{\pi Ά\pi Ώ\pi Ό\pi \pi \pi Έ}$$\beta ¦\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi ‘}\mathtt{1},\mathrm{\pi ‘}\mathtt{2}\right)$

Arc arity
Arc constraint(s)
$\mathrm{\pi ‘}\mathtt{1}.\mathrm{\pi ‘}=\mathrm{\pi ‘}\mathtt{2}.\mathrm{\pi ‘}$
Graph property(ies)
$\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi \pi }$$\beta €1$

Graph model

For each collection of variables depicted by an item of $\mathrm{\pi  \pi °\pi \pi }$ we generate a clique with an equality constraint between each pair of vertices (including a vertex and itself) and state that the size of the largest strongly connected component should not exceed one.