Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are...

23
Rectangle Packing Investigating placement of rectangles at the edge of a container relative to the rectangle size Floris de Bruin 5772583 Bachelor thesis Credits: 18 EC Bachelor Opleiding Kunstmatige Intelligentie University of Amsterdam Faculty of Science Science Park 904 1098 XH Amsterdam Supervisor Dhr. drs. D. van den Berg Faculty of Science University of Amsterdam Science Park 904 1098 XH Amsterdam June 28th, 2013

Transcript of Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are...

Page 1: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

Rectangle PackingInvestigating placement of rectangles at the edge of a container

relative to the rectangle size

Floris de Bruin5772583

Bachelor thesisCredits: 18 EC

Bachelor Opleiding Kunstmatige Intelligentie

University of AmsterdamFaculty of ScienceScience Park 904

1098 XH Amsterdam

SupervisorDhr. drs. D. van den Berg

Faculty of ScienceUniversity of Amsterdam

Science Park 9041098 XH Amsterdam

June 28th, 2013

Page 2: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

Abstract

Rectangle packing problems are NP-complete problems, this property makes findingsolutions for a packing problem time consuming. Investigating rectangle packingproblems could lead to better understanding of the problems, better algorithms and newheuristic. This thesis investigates the assumption that large rectangles are placed at theside of a container.

Existing solved almost square rectangle packing problems where the rectangle setscan be packed perfectly, and creating new closely related rectangle packing problemsgenerates the investigated data.

The results presented indicate a strong correlation for the size of a rectangle areaan placement on the side. For the length of a side of the rectangle there is a weakercorrelation. The probability of placement on the side for a rectangle with a relative largearea in almost square rectangle packing is between 99 and 100 percent. For the closelyrelated rectangle sets this possibility is around 90 percent.

i

Page 3: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

Contents

1 Introduction 41.1 Previous Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.1.1 Depth-First . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.1.2 Branch-and-boud placement . . . . . . . . . . . . . . . . . . . . . . . . . 51.1.3 Less Flexibility First . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.1.4 Containment and Minimal Bounding Box Problems . . . . . . . . . . . . . 6

2 Methods 62.1 Almost Square Rectangle Sets and their Containers . . . . . . . . . . . . . . . . . 62.2 Creation of Closely Related Rectangle Sets . . . . . . . . . . . . . . . . . . . . . 7

2.2.1 Number of Possible Closely Related Rectangle Sets . . . . . . . . . . . . . 82.3 Rectangle Packing Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.3.1 Placing Rectangles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.3.2 Pruning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.4 Retrieving Data for Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.4.1 Almost Square Rectangle Sets Data Retrieval . . . . . . . . . . . . . . . . 102.4.2 Closely Related Rectangle Sets Data Retrieval . . . . . . . . . . . . . . . 11

2.5 Analysis of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3 Results 143.1 Almost Square Rectangle Set Analysis . . . . . . . . . . . . . . . . . . . . . . . . 143.2 Closely Related Rectangle Set Analysis . . . . . . . . . . . . . . . . . . . . . . . 14

4 Discussion 144.1 Possible Explination for Found Results . . . . . . . . . . . . . . . . . . . . . . . . 144.2 Precision of Rectangle Packer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.3 Reduction of Possible Placements . . . . . . . . . . . . . . . . . . . . . . . . . . 204.4 Low Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5 Conclusion 205.1 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

ii

Page 4: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

Acknowledgements

Foremost, I would like to express my sincerest gratitude to my supervisor Dhr. drs.D. (Daan) van den Berg for his support of my thesis and research, for his enthusiasm,motivation and time. Because of his guidance I was able to overcome the many obstaclesthis thesis research created. I thank SURFsara (www.surfsara.nl) for the support in usingthe LISA Compute Cluster and guidance in submitting the batch tasks. Finally, I wouldlike to thank everybody that was involved during the accompanying BSc. graduate projectcourse: dhr. dr. B. Bredeweg, dhr. dr. A. Visser, dhr. dr. M.W. van Someren and allstudents present at my project presentations.

iii

Page 5: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

1 Introduction

When presented with a set of rectangles anda container, is there a configuration where allrectangles can be placed within the containerwithout overlapping each other or the edge of thecontainer? This problem is know as a rectanglepacking problem. An example of a rectanglepacking problem can be seen in figure 1.

Figure 1: Rectangle Packing: 8 Almost SquareRectangles inside a 15×16 container

Rectangle packing problems are a subset ofpacking problems where the goal is to packa single container or multiple containers asefficient as possible with different shapes andsizes. Packing problems are applicable tomultiple real world problems; efficient packingof objects for transport, placing parts of acomputer chip as close to each other as possibleto reduce wire length, the efficient cutting offabric to reduce waste in the clothing industry,and reducing the file size of CSS sprites[Perdeck, 2011] for websites are some examplesof real life applications of packing problems.

Rectangle packing problems are know asNP-complete problems. The NP-completenesscharacteristic is proven by Richard Korf[Korf, 2003] by reducing the rectangle packingproblems to bin-packing problems. Bin-packing

problems are a subset of packing problemswhere objects of different shapes and sizesare packed into a finite number of containerswith a fixed volume. This is done whileminimizing the number of used containers.Because of the NP-completeness characteristicsolving rectangle packing problems is a timeconsuming task, even for the most knownefficient algorithms, and becomes exponentiallyharder when the number of rectangles increase.

In this study, multiple different techniques areused to aid the search for solutions. In section1.1 some of these techniques are mentioned.These techniques are mostly quasi-human basedheuristics and reduce the number of tries neededto find a solution for the rectangle packingproblem as often demonstrated. There isan assumption, within the family of rectanglepacking problems, that large rectangles arepersistently placed at the side of a container.However, there is not enough evidence tosupport this assumption.

The prospect of accelerating rectanglepacking solvers justifies the research conductedfor this thesis. As mentioned in the previousparagraph there is not enough evidence tosolidify the assumption of placement of largerectangles at the edge of a container. Theplacement of all rectangles in multiple solvedrectangle packing problems could be analyzed topossibly create a sound basis for future packingalgorithms. The thesis question therefore is asfollows; are large rectangles more frequentlyplaced on the side of a container?

To examine the thesis question, a substantialnumber of rectangle packing problems areneeded to create a large enough data set tosupport statistical plausibility. Thus, a packingsolver is created to generate information forstatistical analysis (section 2.3), a rectangleset creator generates rectangle sets based onalmost square rectangle sets (section 2.1), and

4

Page 6: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

a container analyzer evaluates the placement ofthe rectangles inside the container (section 2.4).

The search space is limited to perfectrectangle packing problems, perfect meansthere is no empty space between rectangles.The opposite of perfect packing is non-perfectpacking where there is empty space allowedbetween rectangles. There is also a limit on therectangle sets. Only almost square rectangle setsup 20 rectangles are considered, and rectanglesets that are closely related tot almost squarerectangle set are evaluated with up to size16. This is to restrain solving time and givesthe opportunity to utilize the characteristics ofconsecutive almost square rectangles, rectanglesset with rectangles of sizes 1× 2,2× 3, ...,n×n+ 1 where n is the size of the set (figure 1 isan example of almost square packing with eightrectangles). Sets of this kind are often denotedas AS-N, e.g. AS-8 for eight consecutivealmost squares. These sets are solvable forcertain containers, as given by Simonis and O’Sullivan [Simonis and O‘Sullivan, 2011]. Theformation of closely related sets is explainedin section 2.2 and is done to increase thedata set size for the same solvable containersof almost square rectangle packing. Becausethis thesis only involves placing rectangles ina known container the problems are specifiedas containment problems not minimal boundingbox problems (the difference is explained insection 1.1.4). Non-perfect packing problemsare not included due to the fact that solving theseproblems would need a different approach in thedevelopment of the packing algorithm.

This thesis is organized as follows. Firstprevious literature is recalled to explain thetechniques that are used in the rectangle packingsolver. Then, the methods for generating resultsare explained, e.g. the container analyzer andthe rectangle set creator. Next, the resultsare presented in detail. It is explained how

the results show a strong correlation betweenrectangle size and placement on the side. Next, apossible cause is presented for this correlation.Finally, the possible implementation of thisresults is discussed and possible improvements.

1.1 Previous Work

Rectangle packing problems are a well knownset of problems within mathematics andheuristics. In the late eighties experimentsstarted to calculate packing for given containers.The development of the packing solver for thisthesis is influenced by earlier work explained inthe next sections.

1.1.1 Depth-First

One of the earlier examples of an algorithmto solve the rectangle packing problem wasdescribed by Katheryn Dowsland (1987)[Dowsland, 1987]. She described an exactalgorithm for finding optimal layouts foridentical rectangular boxes on a rectangularpallet. The described algorithm was able tohandle cases up to 50 boxes of the same sizeper layer, but was only efficient in packing 30boxes or less. By only including same sizeboxes the problem was significantly simpler tosolve than later, more general, algorithms. Bydescribing the search space as an abstract graphit was possible to solve the problem with adepth-first search algorithm. In following yearsof research, depth-first search was used as aneffective method for solving rectangle packingproblems.

1.1.2 Branch-and-boud placement

In the article Branch-and-bound placementfor building block layout, by Onodera et al.

5

Page 7: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

[Onodera et al., 1991], a method is described forplacing different sized rectangular blocks in acontainer. The presented method searches anoptimal solution in the whole solution space.There is no differentiation between perfect ornon-perfect packing. The branch-and-boundstrategy constrains the search for the solutionby taking in the space available for placementafter a placement of each rectangle. This methodwas able to handle around six rectangles in areasonable CPU time when published in 1991.

1.1.3 Less Flexibility First

All continuing research regarding the rectanglepacking problem uses the branch-and-boundplacement pruning method for the developmentof new pruning techniques. As researchprogressed the rectangle packing problem wassolved for bigger rectangle sets in biggersolution spaces. A proposed deterministicheuristic method, introduced by Wu et al.[Wu et al., 2002], is Less Flexibility First. Itis suggested that the empty space with “lessflexibility” should be filled earlier than otherempty spaces. This algorithm can producerectangle packings with densities of around 99%for randomly generated sets of rectangles greaterthan 45. This is a method for finding the smallestcontainer for a given set of rectangles, a minimalbounding box problem. What a minimalbounding box problem is will be explained in thenext section.

1.1.4 Containment and Minimal BoundingBox Problems

In the following years the rectangle packingproblem was divided into the containmentproblem and the minimal bounding boxproblem. The divide is first described by,and accounted to, Korf [Korf, 2003] andSimonis et al. [Simonis and OSullivan, 2008].

In the containment problem a given set ofrectangles is to be packed in a given container,as opposed to the minimal bounding box wherethe smallest container is found for the givenset of rectangles. The containment problemis found to be a sub-problem for the minimalbounding box problem. In the article by Huangand Korf [Huang and Korf, 2012] the mostsuccessful methods of solving both rectanglepacking problems are evaluated and testedfor performance. In the specific example ofconsecutive almost square rectangles (rectanglesof sizes 1 × 2, 2 × 3, ..., and N × (N + 1))packing is shown to be solvable for rectanglesets up to size 29.

2 Methods

To create the results for this thesis multiplecomponents were developed. In this sectionthese components are explained in detail.

The solving program and its components weredeveloped with the Java Development Kit 1.6.To utilise the full potential of the LISA Clusterof SURFsara, that performed a large portionof the calculations on the large sets, the solveruses multi-threading for 16 cores of the Intel R©

Xeon E5-26520 v2 at 2.60 GHz. For solvingpacking of smaller sets and result analysis,Intel R© i7-3610QM with 8 cores where usedrunning at 2.30 GHz. The analysis of the resultsof the packing were done in MATLAB (versionR2013a).

2.1 Almost Square Rectangle Sets andtheir Containers

Almost square rectangle sets are sets with sizes1× 2 to n× (n+ 1). The surface area of almost

6

Page 8: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

Table 1: Almost Square Rectangle Set withcontainer sizes that can be perfectly packed

Size Container EmptyN Size Space10 17×26 0.45%11 22×26 0.00%12 21×35 0.95%13 26×35 0.00%14 32×35 0.00%

28×40 0.00%15 34×40 0.00%16 32×51 0.00%17 34×57 0.00%18 30×76 0.00%19 35×76 0.00%

38×70 0.00%20 35×88 0.00%

44×70 0.00%

square rectangles are also in increasing order.The orientation of these rectangles can be freelychosen when placing these rectangles inside acontainer. But because the goal of packing isto find an optimal solution, the orientation islimited to regular (0◦) or rotated 90◦ clockwisearound the origin.

Almost square rectangle sets are solvablefor certain containers. Huang and Korfpublished the containers given in Table 1 in2012 [Huang and Korf, 2012]. The sets AS-10and AS-12 do not appear to fit exactly intoa container, there is empty space between therectangles, and thus have not been part of thisresearch.

2.2 Creation of Closely RelatedRectangle Sets

To guarantee a large data set for a a singlecontainer from Table 1, a method for creatingpossible solvable rectangle sets was designed.By preserving the area of each rectangle andvarying the whidth and height, new rectanglesets can be created. It appeared to be possibleto pack these newly created rectangle sets in thesame container as the corrosponding AS-N set.

The creation of the closely related rectanglesets always follow the same rules. To createa new set, one rectangle from the original setis mutated by a factor. This means that onerectangle side is divided by factor x and the otherside is multiplied by the same factor x. For thisthesis a constant factor of two is chosen, this isbecause this factor is a divisor in every rectanglein one side or the other.

Consider the rectangle set AS-11 (1× 2, 2×3, ..., 11× 12), the first mutation by factor twowould result in the following set of rectangles;

{(1×2),(1×6),(3×4), ...,(11×12)}

The next mutation set would be;

{(1×2),(2×3),(6×2), ...,(11×12)}

In Figure 2 an example is given of a nonmutated rectangle of 6× 7 (Figure 2a) and itsmutated counterpart 3× 14 (Figure 2b). Bothrectangles have the same area, 42 but havedifferent widths and heights.

This creates a large number of new rectanglesets. The collection of sets that can be createdfrom AS-11 with the mutation factor of two is210(=1024). A rectangle either be mutated ornot, thus the base number 2 and because thefirst rectangle is not mutatable the power can bewritten as n− 1 where n is equal to the numberof rectangles in the set. This creates a generalrule of number of mutations as 2n−1.

7

Page 9: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

(a)

(b)

Figure 2: Example of a non mutated 6 × 7rectangle (2a) and mutated (2b) rectangle. Themutation is done by a factor of 2.

2.2.1 Number of Possible Closely RelatedRectangle Sets

Beyond the rectangle sets that are used in thisinvestigation there are even more rectangle setsthat can be created and could be used. The totalnumber of possible closely related sets is fargreater than the 2n−1 mentioned.

The creation of these sets follow a pattern andare related to the number of divisors for eachrectangle area. It is possible to find number ofdivisors for eache rectangle area via a divisorfunction;

σx(n) = ∑d|n

dx

where d|n stands for d divides n.In this case x is 0 because we only need to

know how many divisors there are. For theexample of a rectangle with sides 6×7 and areaof 42;

σ0(42) = ∑d|42

d0

= 10 +20 +30 +60 + ...

70 +140 +210 +420

= 8

Because the total number of divisors givespairs of sides, 1×42, 2×21 and so on, we needto divide the total number of divisor by two tofind the unique possible rectangles. The numberof possible mutations for the rectangle 6× 7 iseight divided by two, thus 4. This gives thegeneral function for a single rectangle N withsides n and n+1;

σ0(N(area))/2

To find the number of all the possiblemutations therefore is calculated by multiplyingthe number of possible mutations for allrectangles N in the set;

N

∏n=1

(σ0 (N (area))/2) (1)

The total number of rectangles that arepossible to create and still are closely relatedto almost square rectangle sets is now definedas mathematical function, Table 2 gives anoverview of the sets 11 to 16 where the originalAS-N problem has a perfect fit solution. InSection 5.1 it will be discussed how this can befurther used in research.

Table 2: Number of possible closely relatedrectangle sets with all mutation factor accordingto Equation 1

Size PossibleN Sets11 99532813 2388787214 19110297615 191102976016 9555148800

8

Page 10: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

(a) Begin situation with the insertion point atcoordinate (0,0).

(b) Situation after placing 8× 9 rectangle with theinsertion points at coordinates (0,8) and (9,0).

Figure 3: Example of placing a rectangle of size 8× 9 on a field and the insertion points for newrectangles marked in red for AS-8 in a 15×16 container.

2.3 Rectangle Packing Solver

For the rectangle packing solver the containeris divided into squares of 1× 1. This is tocreate a method of expressing exact placementof a rectangle in a container. Where an x andy value make up a coordinate. The coordinatesthat express the location in the container arezero indexed starting at the upper-left corner.Coordinate (0,0) is marked in red in Figure 3a.

2.3.1 Placing Rectangles

A single rectangle of size 8× 9 can be placedin 127 different ways in an empty 15 × 16container. In a row the non-rotated 8 × 9rectangle can be placed in 7 different locations.In a column the same rectangle can be placedin 9 different locations. This means that thenon-rotated rectangle has 63 different locations.If we calculate the same values for the rotatedrectangle, there are 64 different locations. Byadding these values we get the 127 differentlocations. In general, the rule for possibleplacements of all rectangles on an empty field

is;(Wcontainer−Wrectangle)

×(Hcontainer−Hrectangle)

for every rectangle and rectangle orientation,where W represents width, and H representsheight.

To reduce this number of different locationsa rectangle can be placed on an empty field, astatic coordinate is chosen, an insertion point.An insertion point is a coordinate where arectangle can be placed. By choosing insertionpoints, the number of iterations needed to find aspace for a rectangle is reduced. In the emptyfield example (Figure 3a), the insertion pointis coordinate (0,0). After the placement of arectangle at the insertion point new insertionpoints are created. These insertion points arenext to the edge of the last placed rectangle,on the down-left side and the up-right side, or(rectangle x, rectangle y + rectangle height) and(rectangle x + rectangle width, rectangle y). InFigure 3b, the insertion points are updated tocoordinates: (0,8) and (9,0). After everyplacement of a rectangle inside the containerthese points are updated.

For every rectangle there are two orientations,

9

Page 11: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

normal and 90◦ rotated clock-wise. In an AS-Nproblem this produces 2×N configurations forthe begin insertion point in an empty container.So, for an AS-8 problem the beginning state canlead to 16 new states. To find one solution inthe optimal conditions there are only N statesnecessary. Because all configurations that give asolution are needed for analysis the whole searchspace needs to be traversed, and thus

N !×2

configurations are traversed in the search space.As the N in an AS-N problem increases thenumber of possible configurations increasesexponentially.

2.3.2 Pruning

To reduce the number of nodes in the state-spacethat need to be traversed, pruning techniquesneed to be implemented. The simplestimplementation of a pruning technique is tostop going deeper into the search tree when asituation arises where it is not possible to placeany rectangle on the insertion points left in thecontainer.

The second method of pruning that isused is the Less Flexibility First algorithm[Wu et al., 2002]. An insertion point is anindicator of a packing space. By finding thewidth and the height of the space defined by theinsertion point, the least flexible space is found.In this thesis the least flexible space is chosenbased on the smallest side of the packing space.It could be argued that choosing the smallest sideas the value that defines the packing space is notaccurate enough, and what should be chosen athe defining value is the area. When testing bothmethods of calculating the less flexible value inthe research stage, the results showed that insome situations the area was a better indicatorand in other cases the smallest side was the better

criterion. The area of the least flexible space isa more difficult calculation and takes more time,and because the calculation is done repeatedlythe less complicated method was used.

In Figure 3b there are two insertion points.Coordinate (9,0) has a smallest side value of 6,equal to the width of the free space. Coordinate(0,8) has a smallest side value of 8, equalto the height of the free space. Thus, theinsertion points next to the upper right corner ofthe rectangle (Coordinate (9,0)) marks the leastflexible space and is chosen as the best insertionpoint.

When using the least flexible space toplace rectangles in, the number of possibleconfigurations is reduced. The less flexible firstalgorithm always selects the least flexible spaceand therefore reduces the possible fields that canbe created, and reduces the solution search time.

2.4 Retrieving Data for Analysis

As mentioned, the rectangle packing solverproduces solutions that fill the given container.Sets and containers have multiple configurationsthat show perfect packing. The packing analysisis done by registering if a side of a rectangletouches the edge of the container and which sidethis is (see: Figure 4). If a side is at the edge of acontainer the value of the edge is stored as wellas the total area of the rectangle. This produces astructured data set ready for processing with themethods described in section 2.5.

2.4.1 Almost Square Rectangle Sets DataRetrieval

In Table 3 an overview is given to show thenumber of different solution configurations thatare produced by the solver. The solution timeis given to show the increasing difficulty for

10

Page 12: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

Figure 4: AS-8 solved inside a 15×16 containerand the length of the rectangle sides that are atthe edge of the container visible.

finding the solutions. The AS-19 and AS-20sets that are given in Table 3 took over 12 hoursto generate all the solutions and therefore weresplit up into multiple sessions. Because thecalculation was split up into multiple sessions itwas not possible to give an exact solving time.

2.4.2 Closely Related Rectangle Sets DataRetrieval

Figure 5b shows a configuration that is asolution for a mutated AS-8 rectangle set. Thecounterpart of the mutated AS-8 rectangle setis given in Figure 5a. In both solutions eachrectangle is coloured in the same fashion to showthe analogous rectangle in the other solution.The mutated rectangle set solution generatesthe same data as a non mutated almost squarerectangle set but instead of sides in ascendingorder a larger distribution of sides is present.There also is a possibility of multiple rectangleshaving the same side size.

The number of closely related rectangle setsthat can be created is immense. In section 2.2the creation of closely related rectangle set isdescribed. Table 4 shows which closely related

Table 3: Almost Square Rectangle Set andcontainer sizes with the number of solutions intime. A dash in the column means there was notime measurement available because the solvingwas divided over multiple sessions.

Size Container Solutions TimeN Size (s)11 22×26 16 0,83613 26×35 168 10,50514 28×40 12 66,327

32×35 224 98,85815 34×40 16 378,75116 32×51 1492 698,07617 34×57 64 2990,14218 30×76 332148 3643,89519 35×76 1848 -

38×70 96 -20 44×70 96 -

35×88 5496 -

rectangle sets are tested on a given container andhow many sets were solvable.

For the AS-11 and AS-13 closely relatedrectangle sets, all mutations with a factor 2 wereanalysed. The solving of AS-16 and closelyrelated sets takes a average of 15 minutes. Toanalyse all the 32768 possible closely relatedsets of this class would take over a year tocalculate on a single processor core. Because ofthe time restraint, only 255 sets were used in thisinvestigation. As presented in Table 4, the totalnumber of new data points that were created andwere analysed with this method was 2124.

The high percentage of number of solutions inthe class of closely related sets was a positivesurprise. A preliminary survey showed thedifficulty of finding solvable sets in perfectrectangle packing problems. The possibilityof solving perfect packing for a randomlygenerated rectangle set with the same area asthe container was close to 1×10−5%. The high

11

Page 13: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

(a) Solved AS-8 Rectangle Set (b) Solved Rectangle Set Closely Related to AS-8

Figure 5: Example of Normal AS-8 Rectangle Set in a 15×16 Container and the Closely RelatedSet Created by using a mutation factor of 2 on the original AS-8 Rectangle Set in the same container.

Table 4: Almost Square Rectangle Set and theirclosely related rectangle set with container sizes,the total number of sets that was tested, thenumber of solutions and percentage solvable.Note that the problems of size 16 only a 255 ofthe total 215 possible sets with a factor of 2 weretested. Sizes 11 and 13 were all tested.

Size Container Total Number SolveN Size Sets Solved %11 22×26 1024 309 30.2%13 26×35 4096 1740 42.5%16 32×51 255 75 29.4%

percentage of solvability of the closely relatedsets ensured a large data set for analysis.

2.5 Analysis of Data

For the analysis of the data a generalrepresentation of the data is needed. Tocompare rectangle sets with different set sizesand rectangle sizes all values were normalized.The normalization is done by taking the valueof the largest rectangle side length or area anddividing all other rectangle sides lengths or

areas by this value. This generates the relativesize percentage of each rectangle in a set andcontainer. The size percentage creates thepossibility to compare different sets, containers,and combinations of the former two.

Different sized containers create a differentnumber of solutions for the same rectangle sets,as can be seen in Table 3. For example, theAS-19 packing problem has 96 solutions ina 38× 70 container and 1848 solutions for a35× 76 container. To combine the differentcontainers and sets into one diagram a generalcomparable value is needed. The comparablevalue for placement of the rectangles on theedge of a container is retrieved with a simplecalculation; the total times a rectangle is placedon the edge is divided by the total number ofconfigurations that make up a solution.

When all the processes for generating,normalizing and analysing the data is complete,the raw data is ready to be interpreted to showthe results of this thesis.

12

Page 14: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

(a) The possibility of placement on side for a side length.

(b) The average possibility of placement on side by length of side.

Figure 6: AS-14 to AS-20 in their respective containers given in Table 3 plotted to side length. Thevalues are non-normalized. Figure 6a gives all side lengths of all sets in all containers. Figure 6bgives the means of size lengths over all containers.

13

Page 15: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

3 Results

3.1 Almost Square Rectangle SetAnalysis

In Figure 6a the placement of rectangle sidelength is plotted to the probability of placementon the side of the container. There is acorrelation visible between all the data points.There are multiple data points per side length,one for each container. By taking the means ofeach data point with the same side length the datagives a more general depiction for almost squarerectangle packing problems. The taking of themeans is plotted in Figure 6b.

When normalizing (see: Section 2.5) theresults and taking the area of the rectangle intoaccount, it is possible to compare both the areaand rectangle side length. This is done inFigure 7. In Figure 7a the correlation betweenplacement and side size is show by the trendline,a linear line. In Figure 7b the fit shows more ofa sigmoid function shape with a transition pointaround 20% in relative area size.

3.2 Closely Related Rectangle SetAnalysis

Each result for rectangle sets closely relatedto the corresponding almost square rectangleset shows the same general trend line as theAS-14 to AS-20 plot (Figure 7). The results areplotted in Figure 8, 9 and, 10. All these plotsare normalized and fitted with the same trendline. All trend lines formulas and variables aregiven in the image description under the image,likewise for the confidence score (R2).

4 Discussion

The solving perfect rectangle packing problemsproved to be a time consuming task. Inprevious work, the results of Huang, Korf,Simonis and O‘Sullivan [Huang and Korf, 2012,Simonis and O‘Sullivan, 2011, Korf, 2003]showed that solving these problems could bedone in less time than the solver used for thisthesis. The results presented in this thesis dogive a good indication of all problems and moreresults would presumably confirm the foundoutcome.

The finding of the high percentage ofsolvability of closely related almost squarerectangle sets in the containers of theiralmost square rectangle packing problems wasunexpected. The result presented the opportunityto compare different rectangle sets in the samecontainer. The method of generating newrectangle sets gives a new set of problems thatcan lead to better understanding op packingproblems. In section 5.1 the possible usage ofthis information is discussed.

4.1 Possible Explination for FoundResults

A possible explanation for the placement of large(in area) rectangles at the edge of the containeris that large rectangles not in the edge create aspace that is not as flexible as the same rectangleplaced a the edge. In Figure 11 the space thatcreates a problem is marked in red. In an almostsquare rectangle set there are only two rectanglesthat have a side with size 2, rectangle 1× 2 andrectangle 2× 3. These two rectangles do notspan the total area that is marked in red, thus thisconfiguration can not lead to a solution.

When this rectangle is placed at the edge,

14

Page 16: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

(a) Plot of Placement on edge of container by Relative Lenght of Rectangle Side where a = 0.8976, b =−8.174 and with R2 of 0.6611.

(b) Plot of Placement on edge of container by Relative Area Size where b = 0.3655, c =−22.54 and with R2

of 0.9927.

Figure 7: AS-14 to AS-20, non mutated in their respective containers given in Table 3 plottedto side size and area normalized, and means over all configurations of the solutions of the AS-Nproblem

15

Page 17: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

(a) Plot of Placement on edge of container by Relative Lenght of Rectangle Side where a= 0.7504, b= 12.94and with R2 of 0.7513.

(b) Plot of Placement on edge of container by Relative Rectangle Area Size in Set where a = −0.7397,b = 16.64 and with R2 of 0.9584.

Figure 8: Mutated Rectangle Sets Closely Related to AS-11 plotted to side size (Figure 8a) and area(Figure 8b) normalized, and means over all configurations of the solutions in a 22×26 container.

16

Page 18: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

(a) Plot of Placement on edge of container by Relative Lenght of Rectangle Side where a= 0.7184, b= 12.37and with R2 of 0.7231.

(b) Plot of Placement on edge of container by Relative Rectangle Area Size in Set where a = −0.5499,b = 14.63 and with R2 of 0.9857.

Figure 9: Mutated Rectangle Sets Closely Related to AS-13 plotted to side size (Figure 9a) and area(Figure 9b) normalized, and means over all configurations of the solutions in a 26×35 container.

17

Page 19: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

(a) Plot of Placement on edge of container by Relative Lenght of Rectangle Side where a= 0.4711, b= 22.83and with R2 of 0.0.352.

(b) Plot of Placement on edge of container by Relative Rectangle Area Size in Set where a = −0.7837,b = 15.86 and with R2 of 0.8636.

Figure 10: Mutated Rectangle Sets Closely Related to AS-16 plotted to side size (Figure 10a)and area (Figure 10b) normalized, and means over all configurations of the solutions in a 32× 51container.

18

Page 20: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

Figure 11: Example of the space that need tobe filled (marked in red) when placing a largerectangle not at the edge

the remaining space will not be divided intothe problematic space in the previous example.Therefore, it is rational to put large rectangles atthe edge.

In the closely related rectangle sets thisrestraint of small spaces is less of a problem.With a mutation factor of 2, there will be morerectangles that can be packed into the remainingspace of Figure 11. A rectangle of 4×5 could bemutated into a rectangle of 2× 10 and would fitinto the small space. Therefore, the possibilityof placement at the edge of a container forlarge rectangles is not 100 percent but lower.This could explain the difference of placementin almost square rectangle packing and mutatedrectangle set packing.

What also could be an explanation for theprevalence of large rectangles at the edgeof a container is the flexibility of a smallerrectangle. When rectangles are packed the spacethat remains will become smaller, and smaller.Rectangles do not fit together perfectly, oftensmall spaces remain that needs to be filled. Thisspace is, more often than not, not at the edge.

4.2 Precision of Rectangle Packer

The precision of the rectangle packer is notconfirmed. A number of implementationsof packing algorithms showed a number ofdifferent solutions. When comparing the resultsof the rectangle packer of this thesis (Table 3with the rectangle packer of Simonis et. al.[Simonis and O‘Sullivan, 2011] in Table 5, thereare inconsistencies in the number of foundsolutions. Futhermore, a solver from a thirdindependent party yielded yet another set ofresults. This seems odd, a seemingly simplerectangle packing problem differs in outcome onthree different implementations.

Table 5: Almost Square Rectangle Setand container sizes with the number ofsolutions as given by Simonis et. al.[Simonis and O‘Sullivan, 2011]

Size Container SolutionsN Size11 22×26 413 26×35 4214 28×40 415 34×40 416 32×51 54417 34×57 1618 30×76 11028819 35×76 52620 35×88 1988

Simonis et. al. removed all rotationsand reflections from their packing solutions,therefore the results from the rectangle packerof this thesis need to be divided by four. Thesmaller AS-N problems, where N is smaller than14, the data agrees with Simonis et. al. Theinconsistencies with the thesis rectangle packerare for AS-N problems with of size 14, 16, 17,18, 19 and 20. This is not a problem for this

19

Page 21: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

investigation because the solutions that are foundwith the thesis rectangle packer are correct. It isnot needed, but desirable, to find all solutions foranalysing. It is needed to only include correctsolutions and, as many as possible. Because itis not possible to compare all solutions of thecurrent results with the results of Simonis et.al., it is not possible to decide which methodis correct. However this could mean that whenusing this packer for further research, the processof packing needs to be redesigned.

It could be helpful to design a benchmarkfor perfect packing problems that all rectanglepackers have to pass to show correct functioning.

4.3 Reduction of Possible Placements

With the strong indication that large rectanglesare frequently placed at the side of a containerthe number of locations for large rectanglescould possibly be reduced.

In Section 2.3 the number of possiblelocations a rectangle can be placed is given. Thenumber of possible placements of a rectangle inone orientation is as follows:

(Wcontainer−Wrectangle)

×(Hcontainer−Hrectangle)

This equation can now be reduced to(Wcontainer−Wrectangle)

+

(Hcontainer−Hrectangle)

×2

−4

for each rectangle with a relative large areain one orientation. The number of possibleplacements in an empty field is thus, drasticallyreduced. With this given it is possible to testif a set fits into a container. It is not possible

to definitely find all solutions for a rectangle setin a container, but the possibility that there is asolution with a large rectangle in the edge whenthere is a solution at all is very high.

4.4 Low Correlation

In the mutated rectangle sets closely related toAS-16 there is a lower correlation present forboth the rectangle side length and the rectanglearea. This could be explained by the low numberof data points available to create Figure 10. Onlythe first 255 mutated rectangle sets were used.These rectangle sets do not give a cross-cut ofthe total possible mutated rectangle sets. When alarger number of the mutated rectangle set wouldbe examined, the results will be less extreme andshow a better mean value for all rectangle areasand side lengths.

5 Conclusion

The results all indicate to the same conclusion;rectangles with a large area are predominantlyplaced on the edge of a container. In the almostsquare rectangle sets of sizes 14 to 20 (Figure7b) it is clear that rectangles from the top 50% inarea size of a set are almost exclusively placed atthe edge. The possibility of placement of theserectangles at the edge are in the range of 99 to100 percent.

When looking at the mutated sets that areclosely related to almost square rectangle setsit is evident that larger rectangles in area aremore frequently placed at the edge of a containerthan smaller rectangles in area size. Thelargest rectangles in all the evaluated mutatedrectangle sets were present at the edge of thecontainer in 90% of the solution configurations.

20

Page 22: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

The possibility of placement at the edge of acontainer for smaller rectangles drops rapidly forthe smallest rectangles.

The side length of a rectangle and placementon the edge of a container shows a weakcorrelation, but a correlation nonetheless. Alarger side has a higher chance of being placedat the edge of a container. But on average thearea of a rectangle is a stronger indication thanthe side length.

5.1 Future Work

With strong evidence for the placement ofrectangles with relative large area of a set onthe edge, it is possible to create heuristicsthat exploit this evidence. It is knownthat rectangle packing problems are time andcomputation extensive tasks. As mentioned inthe introduction it is a NP-complete problem.Instead of examining all possible placements fora large rectangle it is now possible to preferablyplace the large rectangle at the edge. This couldindicate if a rectangle set and a given containerhave solutions at all. In 90 percent of the time alarge rectangle is placed at the side thus intuitiontells us that there is only a small chance that allsolutions for the problem do not have the largerectangle at the side.

In section 2.4.2 the number of rectangle setsthat are solvable is given for AS-11, AS-13 anda selection of AS-16. This process was timeconsuming and with the new created heuristiccould reduce this time for investigating if thecreated rectangle set has a solution in thecontainer. If there is a solution found with thenew heuristic it is justified to check all possibleconfigurations for a solution.

21

Page 23: Rectangle Packing - UvA · rectangle sets. Only almost square rectangle sets up 20 rectangles are considered, and rectangle sets that are closely related tot almost square rectangle

References

[Dowsland, 1987] Dowsland, K. A. (1987). An exact algorithm for the pallet loading problem.European Journal of Operational Research, 31(1):78 – 84.

[Huang and Korf, 2012] Huang, E. and Korf, R. E. (2012). Optimal rectangle packing: an absoluteplacement approach. Journal of Artificial Intelligence Research, 46:47–87.

[Korf, 2003] Korf, R. E. (2003). Optimal rectangle packing: Initial results. In ICAPS, pages287–295.

[Onodera et al., 1991] Onodera, H., Taniguchi, Y., and Tamaru, K. (1991). Branch-and-boundplacement for building block layout. In Proceedings of the 28th ACM/IEEE Design AutomationConference, pages 433–439. ACM.

[Perdeck, 2011] Perdeck, M. (2011). Fast optimizing rectangle packing algorithm for building csssprites.

[Simonis and O‘Sullivan, 2011] Simonis, H. and O‘Sullivan, B. (2011). Almost square packing. InIntegration of AI and OR Techniques in Constraint Programming for Combinatorial OptimizationProblems, pages 196–209. Springer.

[Simonis and OSullivan, 2008] Simonis, H. and OSullivan, B. (2008). Search strategies forrectangle packing. In Principles and Practice of Constraint Programming, pages 52–66.Springer.

[Wu et al., 2002] Wu, Y.-L., Huang, W., Lau, S.-c., Wong, C., and Young, G. H. (2002). Aneffective quasi-human based heuristic for solving the rectangle packing problem. EuropeanJournal of Operational Research, 141(2):341–358.

22