## 5.238. nvalue

Origin
Constraint

$\mathrm{\pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi ½\pi  \pi °\pi »},\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\right)$

Synonyms

$\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi ’}_\mathrm{\pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi }$, $\mathrm{\pi \pi \pi \pi \pi \pi }$.

Arguments
 $\mathrm{\pi ½\pi  \pi °\pi »}$ $\mathrm{\pi \pi \pi \pi }$ $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi \pi \pi \pi }\right)$
Restrictions
 $\mathrm{\pi ½\pi  \pi °\pi »}\beta ₯\mathrm{\pi \pi \pi }\left(1,|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }|\right)$ $\mathrm{\pi ½\pi  \pi °\pi »}\beta €|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }|$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi },\mathrm{\pi \pi \pi }\right)$
Purpose

$\mathrm{\pi ½\pi  \pi °\pi »}$ is the number of distinct values taken by the variables of the collection $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$.

Example
$\left(4,β©3,1,7,1,6βͺ\right)$

The $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint holds since its first argument $\mathrm{\pi ½\pi  \pi °\pi »}=4$ is set to the number of distinct values occurring within the collection $\beta ©3,1,7,1,6\beta ͺ$.

Symmetries
• Items of $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ are permutable.

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

Usage

A classical example from the early 1850s is the dominating queens chess puzzle problem: Place a number of queens on a $n$ by $n$ chessboard in such a way that all squares are either attacked by a queen or are occupied by a queen. A queen can attack all squares located on the same column, on the same row or on the same diagonal. PartΒ (A) of FigureΒ 5.238.1 illustrates a set of five queens which together attack all of the squares of an 8 by 8 chessboard. The dominating queens problem can be modelled as one single $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint:

• We first label the different squares of the chessboard from 1 to ${n}^{2}$.

• We then associate to each square $S$ of the chessboard a domain variable. Its initial domain is set to the numbers of the squares that can be attacked from $S$. For instance, in the context of an 8 by 8 chessboard, the initial domain of ${V}_{29}$ will be set to {2,5,8,11,13,15,20..22,25..32,36..38,43,45,47,50,53,56,57,61} (see the green squares of partΒ (B) of FigureΒ 5.238.1).

• Finally, we post the constraint $\mathrm{\pi \pi \pi \pi \pi \pi }$$\left(Q,\beta ©\mathrm{\pi \pi \pi }-{V}_{1},\mathrm{\pi \pi \pi }-{V}_{2},...,\mathrm{\pi \pi \pi }-{V}_{{n}^{2}}\beta ͺ\right)$ where $Q$ is a domain variable in $\left[1,{n}^{2}\right]$ that gives the total number of queens used for controlling all squares of the chessboard. For the solution depicted by PartΒ (A) of FigureΒ 5.238.1, the number in each square of PartΒ (C) of FigureΒ 5.238.1 gives the value assigned to the corresponding variable. Note that, since a given square can be attacked by several queens, we have also other assignments corresponding to the solution depicted by PartΒ (A) of FigureΒ 5.238.1.

The $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint occurs also in many practical applications. In the context of timetabling one wants to set up a limit on the maximum number of activity types it is possible to perform. For frequency allocation problems, one optimisation criteria corresponds to the fact that you want to minimise the number of distinct frequencies that you use all over the entire network. The $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint generalises several constraints like:

Remark

This constraint appears inΒ [PachetRoy99] under the name of Cardinality on Attributes Values. The $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint is called $\mathrm{\pi \pi \pi \pi \pi \pi }$ in JaCoP (http://www.jacop.eu/). A constraint called $\mathrm{\pi }_\mathrm{\pi \pi \pi \pi }$ enforcing that a set of variables takes at least $k$ distinct values appears in the PhD thesis of J.-C.Β RΓ©ginΒ [Regin95].

It was shown inΒ [BessiereHebrardHnichWalshO4] that, finding out whether a $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint has a solution or not is NP-hard. This was achieved by reduction from 3-SAT. In the same article, it is also shown, by reduction from minimum hitting set cardinality, that computing a sharp lower bound on $\mathrm{\pi ½\pi  \pi °\pi »}$ is NP-hard.

Both reformulations of the $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint and of the $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint use the $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint.

Algorithm

A first filtering algorithm for the $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint was described inΒ [Beldiceanu01]. Assuming that the minimum value of variable $\mathrm{\pi ½\pi  \pi °\pi »}$ is not constrained at all, two algorithms that both achieve bound-consistency were provided one year later inΒ [BeldiceanuCarlssonThiel02]. Under the same assumption, algorithms that partially take into account holes in the domains of the variables of the $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ collection are described inΒ [BeldiceanuCarlssonThiel02], [BessiereHebrardHnichKiziltanWalsh05].

Reformulation

A model, involving linear inequalities constraints, preserving bound-consistency was introduced inΒ [BessiereKatsirelosNarodytskaQuimperWalsh10CP].

Systems
Used in

cost variant: Β (introduce a weight for each value and replace number of distinct values by sum of weights associated with distinct values).

generalisation: $\mathrm{\pi \pi \pi \pi \pi \pi }$Β ($\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$ replaced by $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }\beta \mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }$), $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$Β ($\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$ replaced by $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }\mathrm{mod}\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$), $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }$Β ($\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$ replaced by $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }/\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$), $\mathrm{\pi \pi \pi \pi \pi }$Β ($\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$ replaced by $\mathrm{\pi \pi \pi \pi }$ of $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }$), $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$Β (replace an equality with the number of distinct values by a comparison with the number of distinct values), $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$Β (variable replaced by vector).

implies: $\mathrm{\pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi }$Β ($=\mathrm{\pi ½\pi  \pi °\pi »}$ replaced by $\beta ₯\mathrm{\pi ½\pi  \pi °\pi »}$), $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi }$Β ($=\mathrm{\pi ½\pi  \pi °\pi »}$ replaced by $\beta €\mathrm{\pi ½\pi  \pi °\pi »}$).

related: $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$Β (restrict number of distinct colours on each maximum clique of the interval graph associated with the tasks), $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$Β (restrict number of distinct colours on each maximum clique of the interval graph associated with the tasks assigned to the same machine), $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }$, $\mathrm{\pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$Β (necessary condition for two overlapping $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints), $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi }$.

specialisation: $\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }$Β (enforce to have one single value), $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$Β (enforce a number of distinct values equal to the number of variables), $\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }$Β (enforce to have at least two distinct values).

Keywords
Arc input(s)

$\mathrm{\pi  \pi °\pi \pi Έ\pi °\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 \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{1},\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{2}\right)$

Arc arity
Arc constraint(s)
$\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{1}.\mathrm{\pi \pi \pi }=\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{2}.\mathrm{\pi \pi \pi }$
Graph property(ies)
$\mathrm{\pi \pi \pi \pi }$$=\mathrm{\pi ½\pi  \pi °\pi »}$

Graph class
$\mathrm{\pi ΄\pi \pi \pi Έ\pi  \pi °\pi »\pi ΄\pi ½\pi ²\pi ΄}$

Graph model

PartsΒ (A) andΒ (B) of FigureΒ 5.238.2 respectively show the initial and final graph associated with the Example slot. Since we use the $\mathrm{\pi \pi \pi \pi }$ graph property we show the different strongly connected components of the final graph. Each strongly connected component corresponds to a value that is assigned to some variables of the $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ collection. The 4 following values 1, 3, 6 and 7 are used by the variables of the $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ collection.

Automaton

FigureΒ 5.238.3 depicts the automaton associated with the $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint. To each item of the collection $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ corresponds a signature variable ${\mathrm{\pi }}_{i}$ that is equal to 0.