5.16. alldifferent_except_0
DESCRIPTION | LINKS | GRAPH | AUTOMATON |
- Origin
- Constraint
- Synonyms
, .
- Argument
- Restriction
- Purpose
Enforce all variables of the collection to take distinct values, except those variables that are assigned value 0.
- Example
-
The constraint holds since all the values (that are different from 0) 5, 1, 9 and 3 are distinct.
- All solutions
FigureΒ 5.16.1 gives all solutions to the following non ground instance of the constraint: , , , , .
Figure 5.16.1. All solutions corresponding to the non ground example of the constraint of the All solutions slot
- Typical
- Symmetries
Items of are permutable.
Two distinct values of that are both different from 0 can be swapped; a value of that is different from 0 can be renamed to any unused value that is also different from 0.
- Arg. properties
Contractible wrt. .
- Usage
Quite often it appears that, for some modelling reason, you create a joker value. You do not want that normal constraints hold for variables that take this joker value. For this purpose we modify the binary arc constraint in order to discard the vertices for which the corresponding variables are assigned value 0. This will be effectively the case since all the corresponding arcs constraints will not hold.
- Algorithm
An arc-consistency filtering algorithm for the constraint is described inΒ [Cymer12]. The algorithm is based on the following ideas:
First, one can map solutions of the constraint to var-perfect matchingsA var-perfect matching is a maximum matching covering all vertices representing variables. in a bipartite graph derived from the domain of the variables of the constraint in the following way: to each variable of the constraint corresponds a variable and a joker vertices, while to each potential value corresponds a value vertex; there is an edge between a variable vertex and a value vertex if and only if that value belongs to the domain of the corresponding variable; there is an edge between a variable vertex and its corresponding value vertex.
Second, Dulmage-Mendelsohn decompositionΒ [DulmageMendelsohn58] is used to characterise all edges that do not belong to any var-perfect matching, and therefore prune the corresponding variables.
- Counting
-
Length () 2 3 4 5 6 7 8 Solutions 7 34 209 1546 13327 130922 1441729 Number of solutions for : domains
- See also
-
implies: .
- Keywords
characteristic of a constraint: joker value, all different, sort based reformulation, automaton, automaton with array of counters.
constraint type: value constraint, relaxation.
- Arc input(s)
- Arc generator
-
- Arc arity
- Arc constraint(s)
-
- Graph property(ies)
-
- Graph model
The graph model is the same as the one used for the constraint, except that we discard all variables that are assigned value 0.
PartsΒ (A) andΒ (B) of FigureΒ 5.16.2 respectively show the initial and final graph associated with the Example slot. Since we use the graph property we show one of the largest strongly connected components of the final graph. The holds since all the strongly connected components have at most one vertex: a value different from 0 is used at most once.
Figure 5.16.2. Initial and final graph of the constraint
(a) (b)
- Automaton
FigureΒ 5.16.3 depicts the automaton associated with the constraint. To each variable of the collection corresponds a 0-1 signature variable . The following signature constraint links and : . The automaton counts the number of occurrences of each value different from 0 and finally imposes that each non-zero value is taken at most one time.
Figure 5.16.3. Automaton of the constraint