| Overview | Group | Tree | Graph | Deprecated | Index | Concepts |
This function creates a new constrained integer expression equal
to the number of variables in x that are fixed
to the value value. This counting constraint has
strong relations to the IloDistribute
constraint, but is generally easier to use. The following example
shows two approaches to creating models with the same solution set.
Using IloCount:
IloIntVarArray cards(env, 10, 0, 100);
for (IloInt i = 0; i < 10; i++)
mdl.add(cards[i] == IloCount(x, i + 1));
Using IloDistribute:
IloIntVarArray cards(env, 10, 0, 100); IloIntArray values(env, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); IloIntVarArray x(env, 100, 1, 10); mdl.add(IloDistribute(env, cards, values, x));
When an IloCount expression is extracted by CP Optimizer,
it is grouped with others counting over the same variable set
to provide stronger inference. This means that the same inference
strength can be obtained using IloCount in place of
IloDistribute.
See Also: