[ library(gfd) | Reference Manual | Alphabetic Index ]
# <ConsistencyModule:> among(+Values, ?Vars, +Rel, ?N)

The number of occurrence (Occ) in Vars of values taken from the set of values specified in Values satisfy the relation Occ Rel N
*+Values*
- A collection of specifications for integer values
*?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 in Vars of values taken from the set of
values specified in Value to satisfy the constraint defined by Rel:

Rel N

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

Values specify the values whose occurrence are counted, and accept
the same syntax as domain specification, i.e. each item can be a
a simple element, or a range Lo .. Hi. Each element is either an
integer, or is a ground expression that evaluates to an integer.

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 for domain (generalised arc) consistency.

This constraint is known as counts in the global constraint catalog,
with among and among_vars being the specialised form with #= as
the Rel (i.e. The number of occurrences of values from Values is
exactly N), the name among is used here to better distinguish this
constraint from count/4, for counting the occurrences of a single value.
This constraint is implemented by gecode's count() constraint (the variant
with an IntSet argument for Values).

### Modules

This predicate is sensitive to its module context (tool predicate, see @/2).
## Examples

[eclipse 24]: among([1,3,4,9], [4,5,5,4,1,5], (#=), N).
N = 3
[eclipse 25]: among([1..4,9], [4,5,5,4,1,5], (#=), N).
N = 3
[eclipse 26]: among([1..4,3,9], [4,5,5,4,1,5], (#=), N). % repeated value
N = 3
[eclipse 2]: among([], [4,5,5,4,1,5], (#=), N).
N = 0
[eclipse 3]: among([1,2,3], [], (#=), N).
N = 0
[eclipse 5]: among([1,3,4,9], [4,5,5,4,1,5], (#\=), N).
N = N{[-1000000 .. 2, 4 .. 1000000]}