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

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

The value Value occurs in Vars N times
Value
Integer (or (domain) variable)
Vars
Collection (a la collection_to_list/2) of integers or (domain) variables
N
(Domain) variable or integer (array notation accepted)

Description

The value Value occurs in Vars N times.

ConsistencyModule is the optional module specification to give the consistency level for the propagation for this constraint: gfd_gac for domain (generalised arc) consistency. Note that if Value is a domain variable, then the propagation is weak, achieving neither domain or bound consistency until Value becomes ground.

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

This constraint is a specialisation of the more general count/4 constraint, with the (#=) relation, i.e. the occurrences of Value is equal to N.

This constraint is known as exactly in the global constraint catalog, where N is restricted to an integer; the more general count/4 constraint is also known as count in the global constraint catalog, and the constraint is implemented using Gecode's count() constraint.

Examples

[eclipse 11]: occurrences(1,[3,5,1,4,1,3], N).

N = 2

[eclipse 12]: occurrences(6, [], N).

N = 0

[eclipse 15]: [A,B,C] :: [1..10], occurrences(3, [A,B,C], 0). 

A = A{[1, 2, 4 .. 10]}
B = B{[1, 2, 4 .. 10]}
C = C{[1, 2, 4 .. 10]}


[eclipse 16]:  N :: [3, 5], occurrences(3, [3,A,3,5,3], N).

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


[eclipse 17]:  N :: [3, 5], occurrences(3, [3,A,3,5,3,3], N).

N = 5
A = 3

See Also

element / 3, atmost / 3, count / 4, eclipse_6 : collection_to_list / 2, lists : collection_to_list / 2, ic_symbolic : occurrences / 3, fd_global : occurrences / 3, ic_global : occurrences / 3