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

<ConsistencyModule:> count_matches(+Values, ?Vars, +Rel, ?N)

The number of the elements in Vars that match its corresponding value in Values, Matches, satisfies the relation Matches Rel N.
+Values
A collection of M integer values
?Vars
A collection of M (domain) variables or integers
+Rel
One of the atom: #>, #>=, #<, #=<, #=, #\=
?N
An integer or (domain) variable (array notation accepted)

Description

Values and Vars are collections of the same size, and the number of elements in Vars taking on the value given by its corresponding element in Values, Matches, is constrained by the relation:

           Rel N

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

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 implemented by gecode's count() constraint (variant with an IntArgs for Values).

Examples

[eclipse 5]: count_matches([1,2,3,4], [A,B,C,D], (#=), N).

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

[eclipse 6]: L = [A,B,C,D], L :: 4..10, count_matches([1,2,3,4], L, (#=), N).

L = [A{[4 .. 10]}, B{[4 .. 10]}, C{[4 .. 10]}, D{[4 .. 10]}]
A = A{[4 .. 10]}
B = B{[4 .. 10]}
C = C{[4 .. 10]}
D = D{[4 .. 10]}
N = N{[0, 1]}

[eclipse 15]: count_matches([1,2,3,4], [4,3,2,1], (#=), N).

N = 0

[eclipse 16]: count_matches([1,2,3,4], [2,2,3,5],  (#=), N).

N = 2

[eclipse 17]:  count_matches([], [], (#=), N).

N = 0