Skip to main content
FRAMES NO FRAMES

Class IloDistribute

Definition file: ilconcert/ilomodel.h
Map of IloDistributeIloDistributeIloDistributeIloConstraintIloIntExprArgIloNumExprArgIloExtractable
For constraint programming:: a counting constraint in a model.

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 argument), 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.

Note: This constraint cannot be used in a logical constraint.

See Also:

Method Summary
public IloDistributeI *getImpl() const
public IloDistribute()
public IloDistribute(IloDistributeI * impl)
public IloDistribute(const IloEnv env, const IloIntExprArray cards, const IloIntArray values, const IloIntExprArray vars, const char * name=0)
public IloDistribute(const IloEnv env, const IloIntExprArray cards, const IloIntExprArray vars, const char * name=0)
Inherited Methods from IloConstraint
getImpl, IloConstraint, IloConstraint
Inherited Methods from IloIntExprArg
getImpl, IloIntExprArg, IloIntExprArg
Inherited Methods from IloNumExprArg
getImpl, IloNumExprArg, IloNumExprArg
Inherited Methods from IloExtractable
asConstraint, asIntExpr, asModel, asNumExpr, asObjective, asVariable, end, getEnv, getId, getImpl, getName, getObject, IloExtractable, isConstraint, isIntExpr, isModel, isNumExpr, isObjective, isVariable, removeFromAll, setLocation, setName, setObject
Method Detail

IloDistribute

public IloDistribute()
This constructor creates an empty handle. You must initialize it before you use it.

IloDistribute

public IloDistribute(IloDistributeI * impl)
This constructor creates a handle object from a pointer to an implementation object.

IloDistribute

public IloDistribute(const IloEnv env, const IloIntExprArray cards, const IloIntArray values, const IloIntExprArray vars, const char * name=0)

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.


IloDistribute

public IloDistribute(const IloEnv env, const IloIntExprArray cards, const IloIntExprArray vars, const char * name=0)

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.


getImpl

public IloDistributeI * getImpl() const
This member function returns a pointer to the implementation object of the invoking handle.