A Bricklaying Best-Fit Heuristic Algorithm for the Orthogonal Rectangle Packing Problem* Wenshui Lin 1, Jinping Xu 1, Jiandong Wang 1, and Xinyou Wu 2 1 School of Information Science and Technology, Xiamen University, Xiamen, Fujian 361005, China 2 Zhangzhou Cambridge School, Zhangzhou, Fujian 363006, China w.s_lin@yahoo.com.cn Abstract. The present paper presents a novel heuristic algorithm, BBF algorithm, for the two-dimensional orthogonal rectangular packing problem. The BBF algorithm combines the main ideas of the Best-fit algorithm and the Bricklaying algorithm. Test data shows that the BBF algorithm compares with other heuristic algorithms in terms of both solution quality and efficiency. Keywords: Rectangle Packing Problem, Heuristic Algorithm, Best-fit, Reference Brick. 1 Introduction The orthogonal rectangle packing problem (also called two-dimensional orthogonal stock-cutting problem) is an important type of two-dimensional packing problems. It is to place rectangular items onto a rectangular sheet with infinite height in order to minimize the height of the nest, with restrict that all the items should have an edge orthogonal to an edge of the sheet, but rotations of 90 degrees of the items are allowed. The orthogonal rectangle packing problem has numerous applications in the area of dynamic memory allocation, multiprocessor scheduling problems, and general layout problems (see [1-4]). Since A. E. Paull [5] proposed the newsprint layout problem, the orthogonal rectangle packing problem became a hot topic, and many algorithms were obtained [6-13]. As the orthogonal rectangle packing problem is NP hard, the algorithms can be broadly categorized into three methods: exact, heuristic, and metaheuristic. Among the heuristic algorithms, the BL (Buttom-Left) algorithm [8] and BLF (Bottom-Left-Fill) algorithm [9] are most well-known, while the BF (Best-fit) algorithm [11] and the PH (Bricklaying) algorithm [12] seems to be the most outstanding. Our aim is to present a new heuristic algorithm that combines the main ideas of BF algorithm and PH algorithm. * This work is partially supported by the Natural Science Foundation of Fujian Province of China Grant #2009J05015 to W. Lin and J. Wang. D. Zeng (Ed.): ICAIC 2011, Part II, CCIS 225, pp. 638 643, 2011. Springer-Verlag Berlin Heidelberg 2011
A Bricklaying Best-Fit Heuristic Algorithm 639 2 BF Algorithm and HP Algorithm A. BF Algorithm The main idea of the BF algorithm is, at every time step of the algorithm to find the lowest gap of the sheet and seek a best-fitting item to place within the gap. An remaining item is best-fitting for the gap if among all the remaining items it can occupy the width of the gap at the most, and its area is as large as possible. Once a best-fitting item is found, the item will be placed within the gap depending on a socalled niche-placement policy. If a gap is found for which no remaining rectangle can fit, then this is waste space, and the height of the gap will be raised up to the lowest neighbor. B. HP Algorithm The HP algorithm was motivated by the bricklaying method of construction workers during building a wall with bricks. The algorithm includes two stages, the preprocessing stage and packing stage. At the first stage the items are sorted into decreasing area order. At the packing stage, first place the first item in the list in the bottom-left of the sheet, and call the brick the reference brick and call the line along the upper edge of the item the reference line. Then the sheet is separated into two parts, the lower space and upper space. Now place the former items in the list into the lower space from bottom to top and from left to right. When there is no item can be placed into the lower space, then place the first remaining item into the bottom-left of the upper space, and the item is referred to the new reference brick which gives rise to a higher reference line. Repeat the above procedure until all items are packed. 3 A New Heuristic Algorithm A. An Overview The main reason why the BF algorithm is regarded to be better than the BL and BLF algorithms is that, at every time step of packing it is not restricted to the first item encountered but to dynamically search the list for better candidate items for placement. However, in some time steps, the best-fitting items may occupy much height of the used sheet when their heights are much larger than their widths, which are expected to be rotated by 90 degrees before they are placed. On the other hand, the HP algorithm can overcomes the disadvantage of the BF algorithm by using the reference brick. Unfortunately, the HP algorithm does not adopt the best-fit strategy of the BF algorithm, i.e., at the time steps at the packing stage the HP algorithm does not dynamically select the best-fitting item for placement. We present a new heuristic algorithm called BBF (Bricklaying Best-fit) algorithm. The BBF algorithm introduces the reference brick idea into the BF algorithm in order to overcome the disadvantage of the BF algorithm. Note that in our algorithm the best-fit strategy and the niche-placement policy are slightly different from those of the BF algorithm, and the placement policy of the reference bricks is different from that of the HP algorithm. In order to avoid confusion, we descript the procedure of our BBF algorithm below, and main teminologies that used by [11] and [12] are re-defined.
640 W. Lin et al. First we rotate each item so that its width is note less than its height, and sort the items into descending area order (resolving equal areas by decreasing widths). At the beginning of the packing process there will not be any items on the sheet. Place the first item (that has largest area) onto the bottom-left of the sheet. The placed brick is referred to a reference brick, and the line along the upper edge of the reference brick is called the reference line. A reference line is indexed by y = its height from the bottom-left of the sheet. The space of the sheet below the reference line is called the lower space. Then find the lowest gap in the lower space. If there are more than one lowest gaps, we choose the widest one. If there are still more than one lowest gaps (with same width), then choose the most left one. Once a lowest gap is found, we examine the remaining items by their order in the item list to find the best-fitting item. The best-fitting item is the one that can be placed into the gap and after its placement its upper edge will not exceed the reference line, and with the largest area, and occupy the width of the lowest gap at the most. Note that, in the BF algorithm, the best-fit strategy priors to consider the width of the gap that the item occupies, instead of the area of the item. If a best-fitting item is found, then place the item within the lowest gap depending on the so-called niche-placement policy. That is, if after the placement of the item the height of the item s upper edge is more closed to that of the left neighbor s upper edge, then place the item next to the left neighbor, otherwise, place it next to the right neighbor. As the placement is restricted by the reference line, we call this a reference packing with the current reference line. If at some time step the reference packing is not available, then remove the current reference line and search the lowest gap for the placement of a new reference brick. In fact, the method to place of a new reference brick is a reference packing with reference line y =+. If a gap for which no remaining rectangle can be reference packed within, even when the reference line is y =+, then the gap is wasted space, and the relevant sheet array elements are raised up to the lower neighbour. We can now recheck for the lowest gap and continue with reference packing. B. Implementation of BBF Since floating-point data can be simply converted to integer format, we assume all the data (the widths and heights of the items, and the width of the sheet) are integers. The BBF algorithm includes two stages, the preprocessing stage and the packing stage. Preprocessing Stage: The stage is almost the same with that of BF algorithm [11]. That is, we store the sheet as a linear array that has a number of elements equal to the width of the sheet. Each element of the array holds the total height of the packing at that x coordinate of the sheet as to reflect the skyline of the sheet. Therefore, the coordinate of the lowest space of the stock sheet can be found by locating the smallest-valued entry of the array. The width of the gap can be found by examining how many consecutive array items of equal value exist. The item s data is defined as a list of rectangular items each denoted by a (width, height) pair. Note that different from the BF algorithm we sort the list of the items into decreasing area order (resolving equal area by decreasing width).
A Bricklaying Best-Fit Heuristic Algorithm 641 Packing Stage: First the reference line is y =+, and the sheet is examined to find the lowest gap (initially at x = 0, y = 0, and lasting the entire sheet width). The item list is examined and the best-fitting item (at first time step at the packing stage it will be the first reference brick) returned. Reference pack the best-fitting item within the lowest gap. The item is assigned coordinates and removed from the item list. At the meantime, the relevant sheet array elements are incremented by the item height. If the placed item is a new reference brick, then the reference line is updated, in fact, just to y = the maximum of the skyline. If a gap for which no remaining item can be reference packed within, then raise up the relevant sheet array elements to the lower neighbour, and update the reference line to be y =+. The procedure continues until all the items are placed. The maximum of the final skyline returned as the solution of the problem. Summary of Process: The whole process can be summarized by the following pseudo-code: Obtain Sheet Width W Obtain List of n items Rotate each item so that Width Height Sort Item List by Decreasing Area (resolving equal areas by decreasing widths) Initialize Skyline Array of n Elements Initialize Reference Line y =+ while Item Not Packed do Find Lowest Gap if(find Best-Fitting Item = = True) Reference Pack Best-Fitting Item Raise Array to Appropriately Reflect Skyline Update Reference Line to y = Maximum of Skyline else if(reference Line is Not y =+ ) Update Reference Line to be y =+ else Raise Gap to Lower Neighbor end if end if end while return Solution = maximum of Skyline Ο From the above pseudo-code, it is easy to see that, the time complexity is 2 ( nw). Futhermore, in order to improve the solution of the BBF algorithm we can adopt the same method with the HP algorithm [12] that change two certain items order in the item list at the preprocessing stage. Thus the time complexity is 4 Ο ( nw).
642 W. Lin et al. 4 Test Data In order to compare the relative performance of the pre-sented BBF algorithm to the BF and PH algorithms, we used several test problems from the literature. Perhaps the most extensive data sets given for this problem are found in Hopper and Turton [14], where 21 problem sets of rectangle data are presented in seven different-sized categories (each category has three problems of similar size and object dimension). Table 1 shows the test results. We also test the BBF algorithm with the ten instances with large item number n from literature [12]. The comparison of the BBF algorithm with the HP algorithm is shown in Table 2. Table 1. Comparison of BBF and BF, HP with Data from [14] Cat Ins. W N Opt BF PH BBF C11 16 21 21 21 C1 C12 20 17 20 22 21 21 C13 16 24 21 20 C21 25 16 16 16 C2 C22 40 25 15 16 16 17 C23 25 16 15 16 C31 28 32 31 32 C3 C32 60 29 30 34 32 31 C33 28 33 31 32 C41 49 63 61 62 C4 C42 60 49 60 62 62 62 C43 49 62 61 61 C51 73 93 91 92 C5 C52 60 73 90 92 91 91 C53 73 93 91 91 C61 97 123 121 121 C6 C62 80 97 120 122 122 122 C63 97 124 121 121 C71 196 247 243 243 C7 C72 160 197 240 244 243 242 C73 197 245 243 243 Table 2. Comparison of BBF and HP with Data from [12] Ins. W N Opt. PH BBF RPP1 124 346 139 140 140 RPP2 148 406 131 132 132 RPP3 122 313 125 125 126 RPP4 143 403 139 140 140 RPP5 126 327 136 137 137 RPP6 139 418 146 147 147 RPP7 125 381 138 139 139 RPP8 140 390 126 127 127 RPP9 129 350 144 145 145 RPP10 123 375 141 142 142
A Bricklaying Best-Fit Heuristic Algorithm 643 References 1. Coffman Jr., E., Garey, M., Johnson, D.: An application of bin packing to multiprocessor scheduling. SIAM Journal on Computing 7(1), 1 17 (1978) 2. Coffman, E., Garey, M., Johason, D.: Approximation algorithms for bin packing problems An update survey. In: Ausiello, G., Lucertini, M., Serafini, P. (eds.) Algorithm Design for Computer System Design, pp. 49 106. Springer, New York (1984) 3. Coffman Jr., E., Leighton, F.: A provably efficient algorithm for dynamic storage allocation. Journal of Computer and System Sciences 38(1), 2 35 (1989) 4. Dyckhoff, H.: A typology of cutting and packing problems. European Journal of Operational Research 44(2), 145 159 (1990) 5. Paull, A.: Linear programming: A key to optimum newsprint production. Pulp Paper Magazine of Canada 57, 85 90 (1956) 6. Christofides, N., Whitlock, C.: An algorithm for two-dimensional cutting problems. Operations Research 25(1), 30 44 (1977) 7. Beasley, J.: An exact two-dimensional non-guillotine cutting tree search procedure. Operations Research 33(1), 49 64 (1985) 8. Baker, B., Coffman, E., Rivest, R.L.: Orthogonal packing in two dimensions. SIAM Journal on Computing 9, 846 855 (1980) 9. Chazelle, B.: The bottom-left bin packing heuristic: An efficient implementation. IEEE Trans. Comput. 32(8), 697 707 (1983) 10. Liu, D., Teng, H.: An improved BL-algorithm for genetic algorithms of the orthogonal packing of rectangles. European Journal of Operational Reseach 112(2), 413 420 (1999) 11. Burke, E., Kendall, G., Whitwell, G.: A new placement heuristic for the orthogonal stockcutting problem. Operatations Research 52(4), 655 671 (2004) 12. Zhang, D., Han, S., Jiang, Y.: A personification heuristic algorithm for the orthogonal stock-cutting problem. Chinese Journal of Computers 31(3), 509 513 (2008) (in Chinese) 13. Chen, D., Liu, J., Shang, M.: An intelligent enumerative algorithm for solving rectangle packing problem. Journal of Chongqing University of Post and Telecommunications (Natural Science) 20(4), 379 384 (2008) (in Chinese) 14. Hopper, E., Turton, B.: An empirical investigation of meta-heuristic and heuristic algorithms for a 2D packing problem. European Journal of Operational Research 128(1), 34 57 (2001)