Overview | Group | Tree | Graph | Index | Concepts |
An instance of this class is a counting constraint in a model. You can use an instance of this class to count the number of occurrences of several values among the constrained variables in an array of constrained variables. You can also use an instance of this class to force the constrained variables of an array to assume values in such a way that only a limited number of the constrained variables assume each value.
For example, if we have five cars to paint in three available colors, then we might
refer to the cars as c1
, c2
, c3
,
c4
, c5
, and the colors as p1
, p2
,
p3
. If we can allow no more than three cars to be painted
p1
, exactly three cars to be painted p2
, and no more than
one car to be painted p3
, then we can represent our problem informally in
terms of this constraint like this:
cards = [[0,3], [3,3], [0,1]] values = [p1, p2, p3] vars = [c1, c2, c3, c4, c5]
In more formal terms, the constrained variables in the array cards
are
equal to the number of occurrences in the array vars
of the values in the
array values
. More precisely, for each i
,
cards[i]
is equal to the number of occurrences of values[i]
in the array vars
. After propagation of this constraint, the minimum of
cards[i]
is at least equal to the number of variables contained in
vars
bound to the value at values[i]
; and the maximum of
cards[i]
is at most equal to the number of variables contained in
vars
that contain the value at values[i]
in their domain.
The arrays cards
and values
must be the same length;
otherwise, Concert Technology throws an exception on platforms that support C++
exceptions when exceptions are enabled.
When an instance of this class is created by a constructor with only
cards
and vars
as arguments (that is, there is no
values
parameter), then the array of values that are being counted must
be an array of consecutive integers starting with 0 (zero). In that case, for each
i
, cards[i]
is equal to the number of occurrences of
i
in the array vars
. After propagation of this constraint,
the minimum of cards[i]
is at least equal to the number of variables
contained in vars
bound to the value i
; and the maximum of
cards[i]
is at most equal to the number of variables contained in
vars
that contain i
in their domain.
In order for the constraint to take effect, you must add it to a model with the
template IloAdd
or the member function
IloModel::add
and extract the model for an algorithm
with the member function IloAlgorithm::extract
.
Most member functions in this class contain assert
statements. For an
explanation of the macro NDEBUG
(a way to turn on or turn off these
assert
statements), see the concept
Assert and NDEBUG.
See Also:
Constructor Summary | |
---|---|
public | IloDistribute() |
public | IloDistribute(IloDistribute::ImplClass *) |
public | IloDistribute(const IloEnv, const IloIntVarArray, const IloIntArray, const IloIntVarArray, const char *) |
public | IloDistribute(const IloEnv, const IloIntVarArray, const IloIntVarArray, const char *) |
Method Summary | |
---|---|
public IloDistribute::ImplClass * | getImpl() |
Inherited Methods from IloConstraint |
---|
getImpl |
Inherited Methods from IloIntExprArg |
---|
getImpl |
Inherited Methods from IloNumExprArg |
---|
getImpl |
Inherited Methods from IloExtractable |
---|
end, getEnv, getId, getImpl, getName, getObject, setName, setObject |
Constructor Detail |
---|
This constructor creates a counting constraint in a model. You must use
the template IloAdd
or the member function
IloModel::add
to add this constraint to a
model and then use IloAlgorithm::extract
to
extract the model for an algorithm in order for the constraint to be taken
into account.
The arrays cards
and values
must be the same
length; otherwise Concert Technology throws the exception
InvalidArraysException
.
This constructor creates a counting constraint in a model. You must use
the template IloAdd
or the member function
IloModel::add
to add this constraint to a
model and then use IloAlgorithm::extract
to
extract the model for an algorithm in order for the constraint to be taken
into account.
Method Detail |
---|