count
Returns the number of occurrences of a given value found in a given integer expression array.
Syntax
intExpr count(intExprArray exprs, int v)
Parameters
-
exprs: an array of integer expressions -
v: the value for which occurrences must be counted
Description
This expression counts how many of the expressions in exprs take the value v.
Example
To ensure that at least one of several variables on domain 1..3 is assigned to a given value (e.g. 3), do:
a = intVar(1..3);
b = intVar(1..3);
c = intVar(1..3);
count([a,b,c], 3) != 0;
Notes
The solver is able to aggregate, for x1..xn variables, multiple count expressions using constants y1..yk such that:
count(y1, [x1, ..., xn]); ... ; count(yk, [x1, ..., xn])
is equivalent to:
distribute([c1, c2, ..., ck], [y1, ..., yk], [x1, ..., xn])
where each ci represents the cardinality of the corresponding yi.