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

<ConsistencyModule:> count(+Value, ?Vars, +Rel, ?N)

Constrain the number of occurrence of Value in Vars (Occ) to satisfy the relation Occ Rel N
?Value
An integer or a (domain) variable (array notation accepted)
?Vars
A collection (a la collection_to_list/2) of (domain) variables or integers
+Rel
One of the atom: #>, #>=, #<, #=<, #=, #\=
?N
An integer or (domain) variable (array notation accepted)

Description

Constrain the number of occurrences of Value in Vars to satisfy the constraint defined by Rel:

           Rel N

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

occurrences/3, atmost/3, atleast/3 are defined using count/3. For example,

         atmost(N, Vars, Value)
is defined by:
        count(Value, Vars, (#=<), N)

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

ConsistencyModule is the optional module specification to give the consistency level for the propagation for this constraint: gfd_gac the (default) and gfd_bc. Both propagation do not achive bound consistency in all cases, and gfd_bc is different from gfd_gac only if Value is a domain variable, as its domain is not pruned with gfd_bc.

This constraint is known as count in the global constraint catalog. It is implemented using gecode's count() constraint (variants with int or IntVar for argument representing Value).

Modes and Determinism

Examples

[eclipse 33]: count(5, [](4,5,5,4,5), (#>=), 2).   % succeed

[eclipse 34]:  count(5, [](4,5,5,4,5), (#>), 2).   % succeed

[eclipse 35]: count(5, [](4,5,5,4,5), (#=), 2).    % fail

[eclipse 36]: count(5, [](4,5,5,4,5), (#\=), 2).   % succeed

[eclipse 37]: count(5, [](4,5,5,4,5), (#=<), 2).   % fail

[eclipse 38]: count(5, [](4,5,5,4,5), (#<), 2).    % fail

[eclipse 39]: count(5, [](4,5,5,4,5), (#>=), 3).   % succeed

[eclipse 40]: count(5, [](4,5,5,4,5), (#>), 3).    % fail

[eclipse 41]: count(5, [](4,5,5,4,5), (#=), 3)     % succeed

[eclipse 42]: N :: [3,5], count(3, [3,A,3,5,3,3], (#=), N).

N = 5
A = 3

[eclipse 43]:  N :: [3,5], count(3, [3,A,3,5,3], (#=), N).

N = 3
A = A{[-1000000 .. 2, 4 .. 1000000]}

[eclipse 44]:  N :: [3,5], count(3, [3,A,3,5,3], (#<), N).

N = 5
A = A{[-1000000 .. 1000000]}

[eclipse 45]:  N :: [3,5], count(3, [3,A,3,5,3], (#>), N).

N = 3
A = 3

[eclipse 46]:  N :: [3,5], count(3, [3,A,3,5,3], (#>=), N).

N = 3
A = A{[-1000000 .. 1000000]}

[eclipse 47]: N :: [3,5], count(3, [3,A,3,5,3], (#=<), N).

N = N{[3, 5]}
A = A{[-1000000 .. 1000000]}

[eclipse 48]: N :: [3,5], count(3, [3,A,3,5,3], (#\=), N).

N = N{[3, 5]}
A = A{[-1000000 .. 1000000]}