Overview | Group | Tree | Graph | Index | Concepts |
You can use the function IlcSetOf
to reason about a set of constrained variables
that all depend on a given generic constraint.
This function creates a constrained integer set variable, setvar
, equal to the
set of integer values j
such that the generic constraint denoted by ct
is true for j
. At all times, all integer values j
such that ct
is true for j
belong to the required set of setvar
; and all
integer values k
such that ct
is not false for k
belong to
the possible set of setvar
.
The generic constraint ct
must have been created with generic variables stemming
from the indexi
; otherwise, Solver will throw an exception (an instance
of IloSolver::SolverErrorException
).
All generic variables of the constraint ct
must represent arrays of constrained
expressions of the same size; otherwise, Solver will throw an exception (an instance of
IloSolver::SolverErrorException
).
Generic Constraints
A generic constraint is a constraint shared by an array of variables. For example,
IlcAllDiff
is a generic constraint that insures that all the elements
of a given array are different from one another. Solver provides generic constraints to save memory since,
if you use them, you can avoid allocating one object per variable.
You create a generic constraint simply by stating the constraint over generic variables. Each generic variable stands for all the elements of an array of constrained variables.
In that sense, generic variables are only syntactic objects provided by Solver to support generic
constraints, and they can be used only for creating generic constraints. To create a generic variable,
you use the operator []
.The argument passed to that operator is known as the index
for that generic variable; we say that the generic variable stems from that index.
Example
Let's assume we have two arrays, A
and B
, of constrained integer variables
(that is, instances of IlcIntExp
or its subclasses). We want to know the set of elements in
those arrays such that A[i] > B[i]
. All we have to do is this:
IlcIndex i(solver); IlcIntSetVar s = IlcSetOf(i, A[i] > B[i]);
That constrained set variable s
can, in turn, be constrained by other constraints.
For example, we can set its cardinality (the number of elements in it) to 0 (zero). Doing that amounts
to saying that no such i
exists such that A[i] > B[i]
. In other words, for
all i
, A[i] <= B[i]
.
There is a “shortcut” for constraining the cardinality of the set for which a given
constraint is true. That shortcut is implemented by the function IlcCard
.
See Also:
IlcCard, IlcDistribute, IlcIndex