Link Search Menu Expand Document
Specifications PyCSP3 Tools Instances Competitions About

Constraint nValues

The constraint nValues [BHHKW06] ensures that the number of distinct values taken by variables in list respects a numerical condition $(\odot,k)$ composed of an operator in {lt,le,ge,gt,in,notin} and a right operand which is an integer value, a variable or an integer interval. A variant, called nValuesExcept [BHHKW06] discards some specified values (often, the single value 0). This is the reason why we introduce an optional element except.

  • nValues($X$, $E$, ($\odot$, $k$)) with $X=\langle x_1,x_2,\ldots \rangle$, iff $|\{x_i : 1 \leq i \leq |X|\} \setminus E| \odot k$
  • nValues($X$, ($\odot$, $k$)) iff nValues($X$,$\emptyset$, ($\odot$, $k$))


  <list> (intVar wspace)2+ </list>
  [<except> (intVal wspace)+ </except>]
  <condition> "(" operator "," operand ")" </condition>

This constraint captures atLeastNValues and atMostNValues , since it is possible to specify the relational operator in condition.

In the following example, the constraint c1 states that there must be exactly three distinct values taken by variables x1, x2, x3, x4, whereas c2 states at most w distinct values must be taken by variables y1, y2, y3, y4, y5. The constraint c3 ensures that two different values are taken by variables z1, z2, z3, z4, considering that the value 0 must be ignored.


<nValues id="c1">
  <list> x1 x2 x3 x4 </list>
  <condition> (eq,3) </condition> 
<nValues id="c2">
  <list> y1 y2 y3 y4 y5 </list>
  <condition> (le,w) </condition>  
<nValues id="c3">
  <list> z1 z2 z3 z4 </list>
  <except> 0 </except>
  <condition> (eq,2) </condition>  

The constraint increasingNValues can be built by adding restriction increasing to list but this is not allowed in XCSP3-core.