[ library(gfd) | Reference Manual | Alphabetic Index ]

nvalues(+Collection, +RelOp, ?Limit)

Constrains N, the number of distinct values assigned to Collection to satisfy the relation N Rel Limit.
Collection
Collection of integers or (domain) variables.
RelOp
One of the atom: #>, #>=, #<, #=<, #=, #\=
Limit
Variable or integer

Description

Constrains N, the number of distinct values assigned to Collection to satisfy the relation N Rel Limit.

Rel can be one of #>, #>=, #<, #=<, #=, #\= (or equivalently, >, >=, <, =<, =, \=).

Any input variables which are not already domain variable will be turned into domain variables with default bounds.

This constraint can be embedded in a constraint expression in its functional form (without the last argument).

This constraint is also known as nvalues in the global constraint catalog. It is implemented by Gecode's nvalue() constraint.

Examples

[eclipse 21]: nvalues([4,5,5,4,1,5], (#=), N).

N = 3

[eclipse 22]: nvalues([A,B,C,D], (#>), N).

A = A{[-1000000 .. 1000000]}
B = B{[-1000000 .. 1000000]}
C = C{[-1000000 .. 1000000]}
D = D{[-1000000 .. 1000000]}
N = N{[-1000000 .. 3]}

[eclipse 23]: nvalues([A,B,C,D], (#=), N).

A = A{[-1000000 .. 1000000]}
B = B{[-1000000 .. 1000000]}
C = C{[-1000000 .. 1000000]}
D = D{[-1000000 .. 1000000]}
N = N{[1 .. 4]}