IBM ILOG Solver User's Manual > More on Modeling > Combining Constraints: Bin Packing > Suggested answers > Exercise 3

In the example you have just completed, you reduced symmetry in the model by ordering variables. In this exercise, change the order of the variables. Select bins of type green first, then bins of type blue, and then bins of type red. The scalar product of the new bin should still be greater than or equal to the scalar product of the previous bin. However, change the coefficients of types of components so that they are weighted in the following descending order: copper, wood, steel, plastic, and glass.

Suggested Answer

The code that has changed from binpacking.cpp follows. You can view the complete program online in the file YourSolverHome/examples/src/binpacking_ex3.cpp.

You change the array of coefficients:

    IloIntArray coef     (env, nComponents, 1, 5, 25, 125, 625);

You change how the coefficients are weighted:

      if (prevBin != 0){
        model.add(newBin->_type <= prevBin->_type);
        model.add(IloIfThen(env, prevBin->_type == newBin->_type,
                            IloScalProd(newBin->_contents, coef)
                            >= IloScalProd(prevBin->_contents, coef)  ));
      }

You should get the following results:

Search with 1
Search with 2
Search with 3
Search with 4
Search with 5
Search with 6
Search with 7
Search with 8
Type :  Green
Capacity:       4
Plastic :       1
Wood :          2
 
Type :  Green
Capacity:       4
Plastic :       1
Wood :          2
 
Type :  Green
Capacity:       4
Plastic :       2
Wood :          2
 
Type :  Green
Capacity:       4
Copper :        4
 
Type :  Blue
Capacity:       1
Steel :         1
 
Type :  Blue
Capacity:       1
Steel :         1
 
Type :  Blue
Capacity:       1
Steel :         1
 
Type :  Red
Capacity:       3
Glass :         2