count
OPL function to count variables of a certain value.
| context | type |
|---|---|
| Model files (.mod) - Not allowed in a CPLEX constraint block. |
int |
Syntax
count(int[ ],int) count(dvar int[ ],int) )
Description
This expression takes two arguments. It counts how many of the variables in the array given as the first argument are equal to the value given as the second argument. This function also works for integer arrays outside constraint blocks both in CP and CPLEX models.
You can use this function within IBM ILOG Script statements by specifying the OPL namespace:
( Opl.xxx() )
Example
using CP;
range R = 1..10;
dvar int+ x[R] in R;
subject to {
count(all(i in R) x[i], 2) == 10;
}