IBM ILOG Solver User's Manual > Evolutionary Algorithms > Bin Packing Using EA > Problem representation: Model |
Problem representation: Model |
INDEX
![]() |
The model of the bin packing problem is relatively straightforward to specify and makes use of the IloPack
constraint. The two pieces of information needed to build the model are first, the bin capacity C, and second, the weights of the items to be packed into the bins. As model construction is so easy for this example, the construction of the model is embedded in the genetic algorithm solving function SolveWithGA.
The code to construct the model is provided for you and is replicated here:
The inputs are the bin capacity cap
and the vector of weights weight
. The model is based upon a table of integer variables where
which are the decision variables. The value of where[i]
contains the bin where item i is placed in any solution to the problem. Another array load
is constructed, one element of this array per available bin; load[j]
holds the total weight contained in bin j. Finally, a variable is created representing the number of bins used; this will later be used as an optimization criterion. The model assumes that all of the used bins will be those with the smallest indices, and so the number of bins used is one greater than the greatest bin index found in the where
array. The packing constraint IloPack
takes the loads, item locations, and item weights as parameters and enforces the bin capacity constraints according to the assignments of items to them.
You will notice that a maximum number of bins numBins
available for use is calculated based on a simple lower bound. The lower bound is simply the total weight divided by the capacity, rounded up. numBins
is calculated from the lower bound via a formula for the worst case performance of the decreasing first fit method, a well-known packing method that is used here. This means that, so long as decreasing first fit is used, the number of resulting bins will never be more than (lb * 11 / 9 + 5)
. However, normally the solutions found are much closer to the simple lower bound, and typically any reasonable factor above lb
is suitable as the number of bins available.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |