Bin Packing
Bin Packing
JOURNAL
OFOPERATIONAL
RESEARCH
ELSEVIER European Journal of Operational Research 88 (1996) 165-181
Abstract
A genetic algorithm for placing polygons on a rectangular board is proposed. The algorithm is improved by
combination with deterministic methods.
Keywords: Optimization; Genetic algorithms; Mathematical programming; Adaptive processes; Packing problems
tion 4 provides the genetic algorithm in combina- the well-known makespan minimization problem
tion with a deterministic algorithm, and numeri- of combinatorial scheduling theory. Both these
cal examples are presented. In Section 5 two restricted problems are known to be NP-com-
approaches for the extension to polygons are plete [8].
proposed. The straightforward extension applies Other authors as Sleator, who did not use the
the genetic algorithm directly to the polygons. BL-condition, mentioned that the packing prob-
This method results, however, in a rather long lem can be reduced to the partition problem
computing time. An alternative to this method is [22,7].
the application of the genetic algorithm to rectan-
gles in which the polygons are embedded; subse-
quently, the use of a deterministic shrinking step 3. Data structure
moves the polygons closer to each other.
The data structure is important for the genetic
algorithm. The first genetic algorithms (shortly
2. The problem GAs) worked with bit-strings. Over the last few
years, GAs have been developed which are based
The size of the search space of the orthogonal on other data structures. In this way the differ-
packing problem is infinite, because every move- ence between GAs and the evolutionary strate-
ment of a rectangle into a packing pattern in a gies has diminished [15]. The theory about ge-
feasible direction creates a new packing pattern. netic algorithms calls the data structure a geno-
In order to effectively reduce the number of type and its decoding (here: packing pattern) is
possible orthogonal packing patterns the so called called phenotype. These technical terms are based
battom-left-condition (BL-condition) is intro- on biological terminology [9].
duced. The orthogonal packing pattern fulfills the The natural representation of a packing pat-
BL-condition if no rectangle can be shifted fur- tern is based on the placement-coordinates of
ther to the bottom or to the left. each rectangle on the board. If the left lower and
In addition, the complexity of the problem the right upper corner of all rectangles are known,
must be considered. The QPP is a natural gener- then the packing pattern can be reconstructed
alization of the one-dimensional bin-packing easily. For example see Fig. 1.
problem. Indeed, ff all rectangles are required to The advantage of the natural representation
have the same height, then the two problems lies in its easy reconstruction. But if small changes
coincide. On the other hand, the case in which all in the coordinates are made it is probable that a
rectangles have the same width corresponds to packing pattern with overlaps will be created.
i~-
a
Index of the rectangle .(ri). J = 4
height
~- = (i 1. . . . . i,) - Permutation.
= 1
The permutation represents the sequence in
which the rectangles are packed. The advantage or
r2
of this data structure is the facile creation of new
permutations by changing the sequence. A conse- .X = (3,2,4,1)
quence of the variable data structure is the fact Fig. 2. Illustration of the BL-algorithm.
that every permutation has to be assigned to a
unique packing pattern. This decoding of the
genotype needs more effort than the conversion
of the natural representation into the packing bottom or to the left. This is in contradiction to
pattern. Hence, the aim is to create a fast decod- Step i of the BL-algorithm.
ing algorithm. Some properties of the BL-algorithm are pre-
sented below. The first one is an upper bound to
3.1. BL-algorithm the possible packing patterns. Given n rectangles,
the number 2 " - n [ is an upper bound to the
Step 1. Place r~(1) into the left lower corner of
packing patterns which can be calculated by the
the board.
BL-algorithm. This is a consequence of the fact
Step i. Shift r~(i) alternately, beginning from
that the orthogonal packing problem is a permu-
the upper right corner of the board, as far as
tation problem. So there are n! sequences of
possible to the bottom and then as far as possible
rectangles. Furthermore each rectangle can be
to the left.
placed in two ways such that the edges are paral-
Fig. 2 illustrates the packing process of the BL-al- lel to the x- and y-axes. In practice, less packing
gorithm. patterns than 2 " . n! can be created by the BL-al-
It is easy to show, that the packing pattern, gorithm. For example in Fig. 3 two permutations
which is created by the BL-algorithm, fulfills the have the same packing pattern.
BL-condition, because otherwise at least one of The magnitude of the search space is larger
the rectangles could be shifted further to the than the search space in the travelling salesman
71"1 = ( 1 , 2 , 3 )
~r2 ----(1,3,2)
r2
rl
--~X
Fig. 3. TWO p e r m u t a t i o n s w i t h t h e s a m e p a c k i n g p a t t e r n .
168 S. Jakobs / European Journal of Operational Research 88 (1996) 165-181
Y Y
~1 : 71"2:
' height
r2
~X ~X
Fig. 4. Fitness-function based on the height of the packing pattern.
problem. If for example n = 25 rectangles are gorithm height and the optimal height of the
given, then packing pattern, respectively [2].
2 25. 25! > 10 7.5. ( 2 5 / e ) 25 > 10 7.5. 10 24 > 10 31 In addition, the cost of the BL-algorithm is
@(n2). This based on the fact, that each rectangle
orthogonal packing patterns exist. r i can be shifted a maximum of i times, because
An additional property of the BL-algorithm each shift is limited by one of the i - 1 placed
from Baker, Coffman and Rivest is based on the rectangles or by the corners of the board. Hence,
following special case. Let the axes-parallel rect- the cost of placing rectangle r i is ~ ( i ) and the
angles be sorted according to the width, which whole cost amounts to ~(n2).
corresponds to the x-coordinates of the rectan-
gles given by a database, i.e.
4. Genetic algorithm
width(r~(o) > width(r=(j)) for i < j .
For the G A an evaluation of the packing pat-
Then the estimation
tern is necessary. This is represented by an ap-
hBL ~ 3 • howr propriate fitness-function
holds, where hBL and hop T denote the BL-al- f : "n"--->R+
Y y
7rl: 7r2:
kl
1
ks
Fig. 5. Contiguous remainder of the packing patterns.
S. Jakobs /European Journal of Operational Research 88 (1996) 165-181 169
with the property tation '5-1. In contrast to this operation, "w2,. . . , "win
represent random permutations. Then it is guar-
f('wi) > f('wy) antee that the height of the best individual of the
if ~-i is a 'better' packing pattern than "wj. The initial population (hbest) fulfills the following in-
computation of the natural approach of the fit- equality:
ness-function is inversely proportional to the
hbest ~ 3 • howr
height of the packing pattern.
After the initialization the BL-algorithm com-
f ( T r ) = 1/hBL ('W). putes the fitness of "w1,-.., Z'm"
If twO packing patterns have the same height,
their fitness-values are equal, although one of the 4.2. Proportional selection
packings is 'better' (see Fig. 4).
For this reason a differentiated approach is The first genetic operator selects two individu-
necessary. In order to find a differentiated fit- als with the probability of
ness-function the biggest resulting contiguous re-
mainder among the packing patterns on the given
board must be considered. Fig. 5 shows the con- Pi = > O.
tiguous remainder of the packing patterns from
Fig. 4. It is evident that the contiguous remainder In practice the interval I = [0, 1) is divided into
of ,wE is greater than of ,w1. The comparison rn sub-intervals, such that each individual is as-
suggests the following fitness-function; signed a sub-interval.
f ( ~ ) = Area ( ContiguousRemainder (,w) ) A 1 ~ 11 = [0, P l ) ,
= ]~lx(1 i) -x(2i)[ • (height(board) _y(i)) A2 ~ I2= [ P l , P l + P 2 ) ,
ki
with
A,n ~ I m = [1 --Pm,1).
k i = {(x(i),y(i'),(x(i),y(i))}-
Then two random numbers Pi E [0, l ) , i = 1, 2,
are generated and the corresponding sub-inter-
4.1. Initialization vals determine the individuals.
13 16
i
19 21
18
10
17
algorithms we start with some optimal packing the dimensions 40 x height (height > 15), the op-
pattern. T o do so, a big rectangle (here: 40 x 15 timal height is 15.
units) is divided randomly into 25 rectangles (see If these rectangles are sorted according to
Fig. 6). width, the BL-algorithm generates the following
If these rectangles are packed on a board with packing pattern (see Fig. 7). For improving the
Fig. 7. Packing pattern generated by the BL-algorithm with rectangles sorted by width; height = 21.
172 S. Jakobs / European Journal of Operational Research 88 (1996) 165-181
16 ii
8
17 14 3
13
packing pattern the G A is executed in 2000 steps Fig. 8. The improvement of the height amounts to
with the following parameters: 19% and only a few small gaps exist. The progres-
n = 25. sion of the minimum and the average height
Width(board) = 40. through all steps for this special run is shown in
Height(board) = 25. Fig. 9.
m = 20. The results of the computed heights only indi-
M A X _ L O O P S = 2000. cate facts about this corresponding run. The
P m = 0.4. problem is, how do we find the result of the next
After 2000 steps the best individual is shown in run? The solution is given by the Law of Large
22
21
2O
tt
e 19
i
hg 18
t
17
16
15 I I I I I I I I I I
2OO 400 600 800 1000 1200 1400 1600 1800 2000
t
Fig. 9. Heights o f t h e bestindividuals.
S. Jakobs / European Journal of Operational Research 88 (1996) 165-181 173
22
21
20
% E*(average(height),t)
h
e 19
i
g
h18
t
17 E*(min(height),t)
16
i
15 I I I I [ I [ I I
39 41
6
42 44
5 46
32
48
and the approximated expectations of the average The following example corresponds to the
heights are shown. Both curves fall exponentially afore-mentioned case. The same rectangle used
and earlier (40 x 15) is randomly divided into 50 rect-
angles instead of 25. The optimum packing pat-
E *(min(height), 2000) = 17.48. tern is shown in Fig. 11. Fig. 12 shows the pack-
The major issue is: With a probability of over ing pattern created by the BL-algorithm based on
50% a packing pattern with the height 17 is the rectangles sorted by width. The development
computed after 2000 steps. of the approximated expectations are presented
22
21
2O
h E*(average(height),t)
e 19
i
g
h 18 ~ ~r , . . . . . ~ ::: .-: ;~-:.-:~--'~:~::.~'r-~"_-:~-.:;: ::..~'~--~.::.t :7.::::'-:~\7~.-,.- ~-;.~,:_'.~
t
17
E*(min(height),t)
16
15 I I I I I I I I I
200 400 600 800 1000 1200 1400 1600 1800 2000
t
Fig. 13. A p p r o x i m a t e d e s t i m a t i o n s o f t h e m i n i m a l a n d a v e r a g e heights.
S. Jakobs/ European Journal of Operational Research 88 (1996) 165-181 175
Fig. 14. Packing pattern computed after 2000 steps; height = 17.
in Fig. 13. The expected minimum height is The first step is to determine the embedding
greater than in the example described above. rectangles with minimum area for all polygons.
E * (min(height), 2000) = 17.28. To achieve this aim we use the following heuris-
tic. A polygon is rotated once around the centre
This result is based on the fact that smaller of gravity of all its corner points in a fixed num-
rectangles can be packed closer together. The ber o f equal angular increments. At each incre-
packing pattern computed after 2000 steps of the ment the embedding rectangle parallel to the x-
50 rectangles is shown in Fig. 14. and y-axes with minimum area is computed. Fi-
nally, a minimisation of all increments is per-
formed (see Fig. 15). Alternatively, more than
5. Extension to polygons
F]
reason it is not advisable to use this approach.
Our Embedding-Shrinking Algorithm offers a
faster alternative. It consists of three steps:
one polygon is put into a rectangle called cluster with the e m b e d d i n g rectangles. If the fitness o f
[23,16]. the best individual no longer improves, it is nec-
I n Step 2 the genetic algorithm starts packing essary to move the polygons closer together, be-
k__ I
Fig. 17. Pattern which cannot be improved by shrinking; height = 10.
a) original b) 1. reflection
c) 2. reflection d) 3. reflection
cause there might be big gaps between the poly- too (see Fig. 18). The polygon of the four possibil-
gons. ities, which can be shifted over the greatest dis-
The shrinking algorithm moves the polygons to tance, replace the original. So the improved ex-
one another as close as possible using the idea of amples are shown in Fig. 19 and Fig. 20.
the BL-heuristic. So the polygons are shifted al- In the implementation, the shifting of the poly-
ternately as far as possible to the bottom and to gons is done with some fixed increment. After
the left. More than two shifting directions are each increment it has to be tested whether over-
possible only with restriction of packing perfor- laps are generated. This is d o n e by the Polygon-
mance. The order in which the polygons are Cut-Algorithm (PCA).
shifted is given by the permutation. Given two polygons Pi, Ps, the PCA compares
The following two examples cannot be im- each edge of Pi with each edge of Ps for a point
proved by the shrinking step (see Figs. 16 and 17). of intersection. The latter can be done by solving
In order to shift the polygons closer in this a linear system of two equations (parallel edges
case, three reflections of the polygons within the have to be treated as a special case).
embedding rectangle are performed and shifted, In [14] and [21] other methods of calculating
r
Fig. 20. Improved pattern of Fig. 17; height = 10.
178 S. Jakobs / European Journal of Operational Research 88 (1996) 165-181
- 1 J
15
22
16 18 23
14
S
J
24 6 I---- I h • 13
a
Fig. 21. Packing pattern generated by the BL-algofithm; height = 22.
points of intersection of two polygons are given. algorithm creates the packing pattern shown in
These are effective under additional geometric Fig. 21. The reason that big gaps exist in Fig. 21
restrictions (e.g. convexity). comes from the fact that the embedding rectan-
gles are left out.
5.1. N u m e r i c a l examples The G A working on the embedding rectangles
has the same p a r a m e t e r s as in Section 4 about
T h e first example is based on 25 polygons rectangles. Representing a packing pattern cre-
randomly created. After the embedding the BL- ated after 1000 steps, we obtain Fig. 22.
I 9
23
Although the G A decreases the height and proved and the gaps get smaller. Rectangle 14 in
improves the fitness a lot of big gaps exist after Fig. 23 c o u l d be shifted further to the left. The
deleting the embedding rectangles. gap between rectangle 14 and polygon 12 is based
Now a shrinking step is needed. The result of on the fact that rectangle 14 is shifted earlier. A
the shrinking algorithm is shown in Fig. 23. Obvi- further shrinking step is necessary t o close the
ously the fitness of the packing pattern is im- gap. A further example with 25 polygons is pre-
222!
8 ~ 23
sented below. The results of the steps according bination of deterministic and genetic algorithtrls
to the former ones are shown in Figs. 24-26~ provides a possible escape out of local minima. A
further advantage is the easy implementation of
the combination.
6. Improvements and conclusions Any deterministic packing algorithm based on
permutation could be improved by the genetic
We addressed the problem of improving deter- algorithm presented here. The improvement of
ministic packing algorithms. In practice, the com- the BL-algorithm is the first step in this direction.
i 23
Fig: 26. Packingpattern generatedby the shrinkingalgorithm;height= 16.
S. Jakobs ~European Journal of Operational Research 88 (1996) 165-181 181
More improvements described below are possi- [6] Fogel, D.B., System Identification through Simulated Evo-
ble. lution: A Machine Learning Approach to Modeling, Ginn,
Needham Heights, MA, 1991.
Instead of embedding one polygon into one [7] Fowler, R.J., Paterson, M.S., and Tanimoto, St. L., "Op-
rectangle, the embedding of several polygons into timal packing and covering in the plane are NP-
one rectangle could be done. The computation of complete", Information Processing Letters 12/3 (1981)
optimal clusters of polygons for embedding is a 133-137.
problem of optimization which is too extensive to [8] Garey, M.R., and Johnson, D.S., Computers and In-
tractability, A Guide to the Theory of NP-Completeness,
be presented here. For more details see [10] and Freeman, New York, 1979.
[11]. [9] Goldberg, D.E., Genetic Algorithms, Addison-Wesley,
The disadvantage of the BL-algorithm is that Reading, MA, 1989.
groups of rectangles exist for which the BL-al- [10] Haims, M., "On the optimum two-dimensional allocation
gorithm cannot generate the optimal packing pat- problem", Ph.D. Dissertation, Dep. of Elec. Engrg., New
York University, 1966.
tern [3], thus making it necessary to use a greater [11] HaJms, M., and Freeman, H., "A multistage solution of
and more expensive deterministic algorithm to the template layout problem", IEEE Transactions on
transform a permutation into a packing pattern. Systems Science and Cybernetics 6 (1970).
Finally, the development of a mature mathe- [12] Holland, J., Adaptation in Natural and Artificial Systems,
matical foundation in genetic algorithms would Michigan Press, 1975.
[13] De Jong, K., "An analysis of the behavior of a class of
be a very interesting and exciting direction for genetic adaptive systems", Doctoral Dissertation, Univer-
future research. sity of Michigan, 1975.
[14] Mehlhorn, K., Data Structures and Algorithms 3, EATCS
Monographs on Theoretical Computer Science,
Acknowledgements Springer-Verlag, Berlin, 1986, 88.
[15] Michalewiez, Z., Genetic Algorithms + Data Structures =
Evolution Programs, Springer-Verlag, Berlin, 1992.
I would like to thank H.Th. Jongen and I. [16] NeliBen, J., "Die Optimierung zweidimensionaler
Schiermeyer for their helpful suggestions. The Zuschnittprobleme", Schriften zur Informatik und Ange-
author would also like to thank the anonymous wandten Mathematik Nr. 150, RWTH Aachen, 1991.
referees for their constructive comments. [17] Rechenberg, I., "Cybernetic solution path of an experi-
mental problem", Roy. Alter. Establ., Libr. Transl. 1122,
Hants, Farnborough, 1965.
[18] Rechenberg, I., Evolutionsstrategie: Optimierung Teehnis-
References cher Systeme nach Prinzipien der Biologischen Evolution,
Frommann-Holzboog, Stuttgart, 1973.
[1] Adamowicz, M., and Albano, A., "Nesting two-dimen- [19] Schwefel, H.-P., Numerische Optimierung yon Computer-
sional shapes in rectangular modules", Computer Aided Modellen mittels der Evolutions-strategic, Volume 26 of
Design 8, (1976) 27-33. Interdisciplinary Systems Research, Birkh[iuser. Basel,
[2] Baker, B.S., Coffman, E.G., and Rivest, R.L., "Orthogo- 1977.
nal packings in two dimensions", SIAM Journal on Com- [20] Schwefel, H.-P., Numerical Optimization of Computer
puting 9/4 (1980) 846-855. Models Wiley, Chichester, 1981.
[3] Brown, D.J., "An improved BL lower bound", Informa- [21] Shamos, M.I., and Hoey, D., "Geometric intersection
tion Processing Letters 11/1 (1980) 37-39. problems", in: Proe. 17th IEEE Annual Symposium Foun-
[4] Coffman, Jr., E.G., Garey, M.R., and Johnson, D.S., dation of Computer Science, 1976, 208-215.
"Approximation algorithms for bin-packing - An up- [22] Sleator, D.D.K.D B, "Times optimal algorithm for pack-
dated survey", Approximation Algorithms for Computer !ng ill tWO dimensions", Information Processing Letters
System Design, 1984, 49-106. 10/1 (1980) 37-40.
[5] Fogel, L.J., Owens, A.J., and Walsh, M.J., Artificial [23] Terno, J., Lindemann, R., and Scheithauer, G.,
Intelligence through Simulated Evolution, Wiley, New Zuschnittprobleme und ihre Praktische L6sung, Harri
York, 1966. Deutsch-Verlag, 1987.