IBM ILOG Solver User's Manual > More on Modeling > Reducing Symmetry: Configuring Racks > Model > Implementing the constraints |
Implementing the constraints |
INDEX
![]() |
This section presents the implementation of the constraints of this problem according to the second model. It uses the following notation:
The first constraint states that the number of cards plugged into a rack is less than or equal to its number of connection slots.
For each rack a,
The power used by the cards plugged into rack a must be less than or equal to the maximal power it provides.
Those two constraints--number of cards and power used--are implemented directly by the functions IloSum
and IloScalProd
. These are both generic constraints predefined in the Solver library. By generic, it is meant that a single constraint applies to a number of constrained variables simultaneously. Those two constraints are added by the constructor of the class Rack
. In other words, you are using those two generic constraints as class constraints. The constructor uses the following code:
In that code,
nbRackTypes
is the number of rack types. The types of racks are represented by integers between zero and this number. The type zero indicates the unused racks.
Racks
is a two-dimensional array of integers, with the first index accessing the price, power, and number of slots of each rack.
The construction T[i] = v
(where T
is an instance of IloNumVarArray
, and i
and v
are instances of IloNumVar
) constrains the i
th element of T
to be equal to v
. The code of the Rack
constructor also shows other ways to use this element constraint.
To make sure that all cards of a given type are used, you state that the sum of all counters of this card type associated with the racks is equal to the given number of those cards:
For each card type ct,
This constraint is implemented by the function IloSum
, a predefined generic constraint that applies simultaneously to a number of constrained variables. It is added in the main
function.
// all cards must be plugged for(j = 0; j < nbCardTypes; j++){ IloIntVarArray vars(env,nbRack); for(i = 0; i < nbRack; i++) vars[i] = racks[i]->_counters[j]; model.add(IloSum(vars) == nbCards[j]); } |
This model still has a lot of symmetries: any permutation between racks gives a new "solution." You remove these symmetries by defining an order among the configurations of each rack. The idea is to state that the type of rack i-1 is greater than the type of rack i. This order constraint removes some symmetries.
That redundant constraint is stated like this in the main
function:
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |