You are on page 1of 16

Online Removable Square Packing

Xin Han1 Kazuo Iwama1 Guochuan Zhang2


1

School of Informatics, Kyoto University, Kyoto 606-8501, Japan, {hanxin, iwama}@kuis.kyoto-u.ac.jp, 2 Department of Mathematics, Zhejiang University, China, zgc@zju.edu.cn

Abstract. The online removable square packing problem is a two-dimensional version of the online removable Knapsack problem. For a sequence of squares with side length at most 1, we are requested to pack a subset of them into a unit square bin in an online fashion where the online player can decide whether to take the current square or not and which squares currently in the unit square to remove. The goal is to maximize the total packed area. Our results include: (i) No online algorithm can achieve a better competitive ratio than ( 5 + 3)/2 2.618. (ii) The matching upper bound is achieved by a relatively simple online algorithm if repacking is allowed. (iii) Without repacking, we can achieve an upper bound of 3 by using the concept of bricks by Januszewski and Lassak. (iv) The oine version of the problem admits a PTAS.

Introduction

The Bin Packing and Knapsack problems are both very popular in the eld of combinatorial optimization. However, the situation is quite dierent in their online versions: Bin Packing has a long history of online algorithms where important notions like competitive analysis and adversary argument already appeared in the early stage of the literature (e.g.,[16]). In contrast, the Knapsack problem has an intrinsic hostility against an online algorithm which has to decide, for each item Q sequentially given, whether it takes Q or not, i.e., whether it puts Q into the knapsack (or we will call it a bin) or not. This decision is irrevocable, which cannot cope with the following simple instance: Suppose that the online player receives a sequence of small items of size . If the player does not take any of them, then the competitive ratio gradually worsens and if the player takes one, then the adversary immediately gives an item of size 1 which cannot be taken because of the small item already in the bin. Thus one can easily see that there are no competitive algorithms. Recently, Iwama and Taketomi [8] bypassed this diculty by introducing removability. Namely, in each step, the online player can also remove one or more items currently in the bin for packing a new item. They considered the one-bin and two- or more-bin cases and showed that there exist optimal online algorithms for both cases. This is one of the successful attempts to relax the

Research supported by NSFC (10231060)

online condition, which has been popular in many elds such as scheduling (see e.g.,[14]). This paper discusses the online square packing problem. Suppose that a sequence of squares (ai , ai ) arrives one by one, where 0 < ai 1 is the side length of the square. In each step i, the online player has to decide whether or not it packs (ai , ai ) into the bin of size (1, 1) before the next square comes. We allow removing just as the one-dimensional case, namely we allow to discard one or more items already in the bin, but the items once discarded will never be considered again. It is easy to see as before that there is no competitive algorithm without this discarding rule. It should also be noted (see Sec. 2) that if each item may be a rectangle, then we cannot achieve a constant competitive ratio either. Our contribution. The basic dierence between the one-dimensional and two-dimensional packing problems is that in the latter we need to assign the item into a specic position inside the unit square. This also means that it is important whether we allow repacking in each step or not, where repacking means that we can once take out all the items that should be packed and can reassign them into the bin using some (o-line) algorithm. In the one-dimensional case, since items are naturally packed from the bottom of the bin without space, repacking is implicitly allowed. However, it turns out from the algorithm in [8] that we actually do not need repacking to obtain the optimal competitive ratio in the one-bin case. Our results are the following: (i) No online algorithm for which both removing and repacking are allowed can achieve a competitive ratio better than ( 5+3)/2 ( 2.618). (ii) The matching upper bound can be achieved by a relatively simple but a bit tricky algorithm if repacking is allowed. (iii) We give an online algorithm which achieves a competitive ratio of at most 3 without repacking. This algorithm is borrowing the interesting notion of brick by Januszewski and Lassak [10] together with a couple of new ideas for packing and removing. (iv) We also consider the oine version of the problem, which is known to be strongly NPhard [12]. And we prove the oine version admits a PTAS. (Fishkin et al.[6] independently got the same result.) Related problems and previous work. Basically there are two categories of rectangle packing problems. Let B be the set of rectangular bins and L be the set of rectangles to be packed. In the maximization category, one is asked to pack a subset X of L, without any overlap, into the bins so that f (X) is maximized, where f () is a function of rectangles. In the minimization category, all rectangles of L have to be packed, without any overlap, into a subset of B so that g(Y ) is minimized, where g() is a function of bins. In this category, the set of bins is assumed to be large enough (e.g., there are unlimited number of bins). In fact we can also name the two categories the knapsack class and the bin packing class, respectively. For the o-line version of the knapsack class, Caprara and Monaci [2] rst considered the problem of maximizing the total area of packed rectangles. They mainly focused on exact algorithms. A polynomial (3 + )-approximation algo-

rithm was also derived. Then Jansen and Zhang [9] considered a problem of maximizing the total prot of packed rectangles. In this problem the bin set contains exactly one bin and each rectangle Ri is associated with a prot pi . The objective function is f (X) = Ri X pi . The problem is to pack a subset X of L into the bin to maximize f (X). Several approximation algorithms were presented, the best of which has a worst-case ratio of at most 2 + for any given > 0. Our result (iv) claims that there exists a PTAS if input items are unweighted (i.e., pi = its area) squares. Some online problems of the knapsack class were also investigated. Januszewski and Lassak [10] proposed a novel concept brick(that is a rectangle with aspect ratio equal to 2 or 1/ 2). They partitioned the unit square bin into bricks and pack dierent squares into appropriate bricks. They showed that each list of squares with total area bounded above by 5/16 can be online packed into a unit square. Caramia et al. [3] designed an online algorithm to maximize the total area of rectangles packed into a rectangular bin, but only the experimental analysis based on implementation was given. For the bin packing class there have been many results on the two-dimensional bin packing problem. Here we only mention some results on packing squares. For the o-line case, Ferreira et al. [7] gave an approximation algorithm with asymptotic worst-case ratio bounded above by 1.988. Kohayakawa et al. [11] and Seiden and van Stee [15] independently obtained approximation algorithms with asymptotic worst-case ratio of at most 14/9 + (for any > 0). These results were recently improved by Correa and Kenyon [4], and Bansal and Sviridenko [1]. They independently proposed asymptotic PTASes for packing d-dimensional cubes into the minimum number of unit cubes. For the online case, if the number of bins is unbounded, the best known asymptotic worst case ratio is 2.245 using a computer proof [5]. Competitive Ratio: To evaluate an online algorithm, we use the standard measure called competitive ratio. For any input sequence L, let A(L) be the area packed in the bin by an online algorithm A and OP T (L) be the packed area by an optimal o-line algorithm. The competitive ratio of algorithm A is then dened as RA = sup OP T (L) . A(L)
L

Lower Bounds

We give the following facts to show that the removal condition is necessary. Fact 1 If the removal is not allowed, then no online algorithm can achieve a constant competitive ratio. Proof. The rst square is of size (1/M, 1/M ) for M > 0. The online player has to take this square since otherwise the competitive ratio becomes . Then the adversary gives a square of size (1, 1), which must be discarded since it cannot coexist with the small one always in the bin. Thus the competitive ratio is M 2 which can be arbitrarily large, as M gets large. 2

Fact 2 Even if the removal is allowed, no online algorithm can achieve a constant competitive ratio for packing rectangles. Proof. We consider the following adversary which uses two dierent kinds of rectangles, one is of size (1, 1/M ) denoted by A and the other of size (1/M, 1) denoted by B, for some integer M > 1. Note that A and B cannot coexist in the bin of size (1, 1) (under the assumption that rotation is not allowed). The adversary gives an A in the rst step, which must be taken by the online algorithm. Now suppose that in each following step 2 i 2M , the bin now holds an item X (X = A or B). Then the adversary gives an item Y which is not X (i.e., Y = A if X = B and vice versa) in that step. Obviously, the online player can hold at most one rectangle, A or B, in the bin all the time, while the oine player can hold at least M As or M Bs eventually. Thus the competitive ratio becomes arbitrarily large. 2 We give a lower bound for both repacking and removing are allowed. Theorem 1. Given an online algorithm A for packing squares, RA ( 5+3)/2 ( 2.618). Proof. Let A be any online algorithm. The adversary gives two squares of size (q 2 , q 2 ) and (q + , q + ), respectively. Here, q = ( 5 1)/2 (i.e., q + q 2 = 1) and > 0, and hence these two squares cannot coexist in the bin. If A takes (q 2 , q 2 ) (and gives up (q + , q + )), then the game is over because OP T (L)/A(L) is (q + )2 /q 4 > q 2 /q 4 = 1/q 2 = ( 5 + 3)/2. So, suppose that (q + , q + ) is now in the bin. Then the third and fourth squares given by the adversary are both (q 2 , q 2 ). For the same reason as above, the algorithm A must discard both. Then the adversary gives at most four identical squares of size (1/2, 1/2), one after the other. There are two cases: Case 1 Algorithm A takes one of those (1/2, 1/2) squares and discards (q + , q+). Then the adversary stops the game immediately and we have A(L) = 1/4 and OP T (L) 3q 4 + 1/4 > 0.6875 since OPT can pack three (q 2 , q 2 ) and one (1/2, 1/2). Thus OP T (L)/A(L) > 2.75. Case 2 Algorithm A gives up all four (1/2, 1/2)s. Then OP T (L) is obviously 1 and OP T (L)/A(L) = 1/(q + )2 which tends to ( 5 + 3)/2 as goes to zero. 2

Optimal Algorithm with Repacking

In this section, we consider online packing with repacking and give a simple algorithm called RPK, which achieves the optimal competitive ratio given in Theorem 1. RPK uses the well-known (o-line) square packing algorithm called NFDH (Next Fit Decreasing Height) [13]. NFDH packing behaves as follows: First sort all squares by their heights, then pack them in the bin from the largest one level by level as shown in Fig. 1(a). In each level, pack them by Next Fit, namely, if the current level cannot accommodate the next item, then open a new

level 3 level 2 level 2 S3 S4

S1 level 1 (a) level 1 (b)

S2

Fig. 1. NFDH packing

with height equal to the current items height. We repeat this procedure, until there is no space for a new level in the bin. Here is a key property of NFDH. Lemma 1. [13], Any set of squares with total area 1/2 can be packed into a unit square by NFDH. Denition: Let |R| be the area rectangle R, p(R) be the packed area in of rectangle R respectively. Set q = ( 5 1)/2. Let B be the unit square bin, S1 , . . . , Sn be the items currently in B and x1 , . . . , xn be their side, respectively. W.l.o.g., assume that x1 . . . xn . Let Q be the coming item with side length xn+1 . A single round of RPK can be described as follows. Algorithm RPK 1: If the packed area p(B) q 2 then discard Q and all future items, stop. 2: Else, if |Q| q 2 then remove all in the bin and pack Q. 3: Else, if possible then pack all of S1 , . . . , Sn and Q by NFDH. 4: Else, if (x1 + xn+1 ) > 1 then take the smaller one between S1 and Q, pack it together with S2 , . . . , Sn by NFDH. 5: Else nd a maximum k such that S1 , . . . , Sk and Q can be packed by NFDH. Pack all them by NFDH. Theorem 2. The competitive ratio of RPK is at most ( 5 + 3)/2 ( 2.618). Proof. The rst square is taken by RPK in step 2 or 3, therefore the competitive ratio at the end of round 1 is 1. Suppose that the competitive ratio OP Ti1 /RP Ki1 at the end of round i 1 is still at most (3 + 5)/2, where i 2. Then we show that the competitive ratio is still at most (3 + 5)/2 at the end of round i. In round i, one of the ve steps 1 5 above is executed. Case 1. Step 1 or 2 is executed, then p(B) q 2 . Case 2. Step 3 is executed. The current item Q is just added to the bin. So OP Ti1 + |Q| OP Ti1 OP Ti (3 + 5)/2. RP Ki RP Ki1 + |Q| RP Ki1 Case 3. Step 5 is executed (Step 4 will be considered next). We rst show the following property of NFDH.

Lemma 2. Suppose that squares S1 , ..., Sk can be packed by NFDH but S1 ,...,Sk+1 cannot. Then k = 1 or k 4. Proof. Suppose that k = 1. Then by assumption we can pack at least S1 and S2 . One can see that this packing needs only level 1. So, we must have a space for S3 above S1 and a space for S4 to the right of S3 , as shown in Fig. 1 (b). Thus we can pack at least up to S4 . 2 Back to case 3, S1 , . . . , Sk , Q can be packed but S1 , . . . , Sk+1 , Q cannot. Since there are at least two squares in the set of S1 . . .Sk Q (recall that at least S1 n and Q can be packed), then k 3 by lemma 2. Since i=1 |Si | < q 2 (otherwise the packing should have been ended), then
k+1

i=1

|Si | < q 2 .

Since Sk+1 is the smallest among S1 , . . . , Sk+1 and k 3, |Sk+1 | q 2 /4 < 0.1. Moreover, because S1 , . . . , Sk+1 , Q cannot be packed by NFDH, by Lemma 1, k+1 i=1 |Si | + |Q| > 1/2. It follows that the packed area in the bin B
k

p(B) =
i=1

|Si | + |Q| (1/2 0.1) > q 2 .

Case 4. Step 4 is executed. After executing Steps 1, 2 or 5 the algorithm halts since p(B) q 2 . And more in Step 3, nothing is discarded. Then we can classify all the squares received so far into two sequences G1 and G2 such that squares in G1 are in the bin and squares in G2 have been discarded only in Step 4. And when a square has a highest index in G2 , it means that the square is removed latest than others. Now we prove the following facts: (i) Given any square Y in G2 , we have 0.25 < |Y | < q 2 . Since in Step 4, we always remove the larger one of two squares which cannot coexist then |Y | > 0.25, and since if |Y | q 2 then the packing would stop at Step 1. (ii) Let X be the largest one in G1 . Then |X| q 4 . If |X| < q 4 then by (i) we need not remove any one. (iii) Let Y be the smallest one in G2 . (If there are two or more ties, then we choose the one with the highest index) Then the X dened in (ii) cannot coexist with Y in the bin. Reason: let X be the largest square in the bin when Y is removed. By the operation in step 4, we have |Y | |X |. Since Y is the smallest one in G2 , then X is still in the bin (in G1 also). Otherwise X would be the Y . Since X and Y cannot coexist in the bin and X X , X and Y cannot either. By the above analysis, we see no two squares in G2 can coexist by (i). If OPT has G1 , then it cannot have any item in G2 and we are done (the competitive ratio is 1). If OPT does not have all of G1 , then it can have at most one square in G2 , say Y , but only in this case it does not have the largest square in G1 , therefore 1 G1 |X| + |Y | G1 |X| + q 2 OP T 2. RP K G1 |X| + |X| G1 |X| + q 4 q 2

Online Algorithm without Repacking

In this section, we rst review the on-line packing algorithm by Januszewski and Lassak [10], called JS, which uses a beautiful technique based on bricks. Unfortunately this algorithm is not competitive. We then give our new ideas that make this algorithm both more ecient and competitive. A detailed description of our algorithm and its analysis follow. 4.1 Packing by using Bricks

A rectangle (w, h) is called a brick if w/h = 2 or h/w = 2. So a brick can be partitioned into two congruent bricks. Given a square Q, we use S(Q) to denote the smallest subbrick of B which can contain Q. Recall that |R| is the area of rectangle R and p(R) is the packed area in rectangle R. Fact 3 If Q is packed in a brick congruent to S(Q), then at least 1/(2 2) of this brick is occupied. Fact 4 [10] Given a square Q and S(Q), then |S(Q)|/(2 2) < |Q| |S(Q)|/ 2.

0.707

C1
0.75

C2
0.707 2/3

D1

D2

E1 E2 E3

A B

(a)

(b)

Fig. 2. Previous partition vs ours

Next we introduce a subroutine P B in the JS algorithm for packing Q into the right position of B, where B is a brick. In the following, if a brick contains a square, then it is said to be used, otherwise unused. Algorithm P B (Packing a Brick). 1. if all bricks in B are used or all unused bricks are smaller than S(Q), then give up packing Q, 2. else pack Q into B depending on the following two cases. (a) if there is an unused brick congruent to S(Q), then pack Q into it, (b) else nd a smallest brick P among all the unused ones whose area is larger than |S(Q)| and partition it into a sequence of bricks whose areas are |P | , |P | , , 2|S(Q)|, |S(Q)|, |S(Q)|, respectively. Then pack Q into 2 4 one of two bricks with area equal to |S(Q)|.

The entire JS algorithm is quite simple, which packs a sequence of items Q1 , Q2 , , Qn as follows: (i) Before packing Q1 , construct three bricks A = (1, 2/2), C1 = ( 2/4, 1/4) and C2 = ( 2/4, 1/4) within the bin (a unit square) as shown in Fig. 2 (a). (ii) For packing current item Qi , pick up the bricks one by one in the order of C1 , C2 and A and apply algorithm P B, respectively. Once Qi is packed, consider the next item; otherwise, if Qi can be packed into neither of them, stop with failure. (iii) If we can pack all of Q1 , , Qn , then stop with success. The following results related to algorithm P B are due to [10]. Lemma 3. If algorithm P B cannot pack a square Q in a brick B, then all unused bricks in B are smaller than S(Q), and there is at most one unused brick with area |S(Q)|/2i for each i = 1, 2, . . .. Proposition 1 [10]. If |Q1 |+ +|Qn | 5/16, then the above algorithm always stops with success, namely, all items are packed. 4.2 New Ideas

Although JS algorithm is a nice online algorithm, but the algorithm itself is not competitive since it does not consider removal. Our basic idea for removing items is quite natural, namely, if the current item Q cannot be packed by the JS algorithm (if it can be packed then we of course do so), then we search a (used) brick B which is congruent to S(Q), remove all items in B and pack Q into B. Note that this modication is sucient to make the algorithm competitive, but, we cannot guarantee a good competitive ratio such as 3. Thus we need more clever removing strategies, such as the strategy used in Algorithm RPK. More importantly, we improve the JS algorithm as follows: (i) We construct six bricks in the bin B as shown in Fig. 2 (b), B = (2 2/3, 2/3), D1 = D2 = ( 2/3, 1/3), E1 = E2 = E3 = (x, 2x), where x = 1 2 2/3. The point is that we need a simple relation between the size of one big brick and that of two small ones. The size ratio is 8:1 in the previous construction and 4:1 in the new construction. C1 and C2 in Fig. 2 (a) can be enlarged easily, but it does not make sense. (ii) Recall that when we pack a square in a brick, there is some space left in that brick. The original JS algorithm never uses such a space, but our algorithm does, namely, two or more items may share a single brick. (iii) Introduce two important concepts, simple brick (s-brick) and composed brick (c-brick). Given a brick, if it is not partitioned into sub-bricks then it is called simple, otherwise composed. Before packing any square, all bricks B, D1 , D2 , E1 , E2 , E3 are s-bricks. In the packing procedure, if a brick is partitioned into sub-bricks, then it becomes a c-brick. But note that a c-brick can become a s-brick again when all squares in it are removed. A square (a, a) is called small, if a 1/3, otherwise large. Moreover, if a 1 2 2/3, call it tiny. Recall p(R) is the packed area in rectangle R and the bin is B.

4.3

Competitive Algorithm RSP

The main ideas of our algorithm denoted by RSP (Removable Square Packing), are as follows: any time, if possible, rst we try to pack Q in B without removing any item. Otherwise, we have to remove some squares including Q itself to guarantee a good competitive ratio. For example, if Q is small, i.e., |Q| 1/9, we try to pack Q into a used brick with area larger than |S(Q)| or we remove some squares in the bin to make room for Q. if Q is large, then we may remove an even larger square always packed for packing the new Q. The details are given in the description of algorithm RSP. In each round, algorithm RSP receives a square Q and decides: (i) whether or not Q should be packed, (ii) if yes, which position Q should be allocated, and (iii) to do so, which items should be removed. Note that if p(B) 1/3, then our target competitive ratio (= 3) is achieved. So the algorithm can ignore (automatically discard) all the following items. For example, if any (sub)brick in B D1 D2 is used then the packed area is greater than 1/3. (To see this, note that |B| + |D1 | + |D2 | = 2 2/3. Then by Fact 3, p(B D1 D2 ) 1/3.) Algorithm RSP . Step 1. The packing stops when one of the following two cases occurs. (1.1) p(B) 1/3. (1.2) |Q| 1/3, then empty the bin and pack Q. Step 2. Pick up the bricks one by one in the order of E1 , E2 , E3 , D1 , D2 , B and apply algorithm P B to pack item Q, respectively. Otherwise (Q cannot be packed into any unused brick), goto step 3. Step 3. {There exist unused bricks and all of them are smaller than S(Q).} |Q| 1/9. Let T be the largest s-brick in D1 D2 B. (3.1) |T | 4|S(Q)|. (T is used, but as shown later, there must be room for Q within it). Then pack Q into it and halt. (3.2) |T | = 2|S(Q)|. If Q can be packed into it, then pack Q; else select a c-brick P such that |P | = |S(Q)| and the packed area in it is the smallest among all c-bricks congruent to S(Q). Empty P and pack Q into it. Halt. (3.3)|T | |S(Q)|. Find a c-brick P which is congruent to S(Q) and contains the largest unused brick. Remove all squares from P and pack Q into it. 1/9 < |Q| 2/9. Let Nl be the numbers of large squares in B. (3.4) Nl = 2. Remove all from D1 D2 if needed, pack Q like Fig. 3(a). Halt. (3.5) Nl = 1 and its area is larger than 2/9 (B is a s-brick). If possible, pack Q into the uncovered space of the bin and halt, shown as in Fig. 3 (b). Else, remove the one in B and pack Q, shown as in Fig. 3 (c) (at this point, we also get a new s-brick ( 2/3, 2/3) since B is partitioned). (3.6) Else, {some small squares in B, so at most one large item can t} 1. Nl = 0, i.e., the largest s-brick is smaller than ( 2/3, 2/3), so there are two c-bricks ( 2/3, 2/3) in B. Empty the one with the smaller area in it, pack Q into it.

2. Nl = 1. Remove all small squares from B and pack Q, shown as in Fig. 3 (d). 2/9 < |Q| < 1/3. Let Nl , Ns be the numbers of large, small squares in B, respectively. (3.7) Ns = 0. If possible, pack Q with the one in the bottom-left corner of B, shown as in Fig. 3(e), else remove all from B and Pack Q. Halt. (3.8) Nl = 1 and Ns = 0. If possible, pack Q like Fig. 3(e), halt. Else, pack the smaller one between Q and the one in B and remove the other. (3.9) Nl = 2 and Ns = 0 . Pack Q with the smaller one of two larger squares in the bin like Fig. 3(f) and remove all others. Halt. Remark: After squares are packed in the bin, we can remove them but cannot repack them later. So, it is important to give them a right position in the bin. Here, we give two key points. i) When a square is packed in a brick, we pack it at the bottom-left corner of the brick to leave room for future possible packing such as Step 3.1, 3.2 etc, shown as in Fig. 3 (c) or (d). ii) When the rst square comes to brick B, we pack it in the bottom-left corner of B (We can see the benets from Step 3.7 and 3.8).

11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 Q 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000000 1111111 1111111 0000000 0000000 11111111 00000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000 1111111 1111111 0000000 0000000
(a)

11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 Q 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000 111111 000000 1111111111 0000000000
(b)

1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 Q 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000

11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000

(c)

11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000

111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000

11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000 1111111 0000000

11111111 00000000 1111111 11111111 0000000 00000000 11111111 1111111 00000000 0000000 00000000 1111111 0000000 11111111 1111111 11111111 0000000 00000000 1111111 11111111 0000000 00000000 1111111 11111111 0000000 00000000 1111111 11111111 0000000 00000000 Q 1111111 11111111 0000000 00000000 11111111 1111111 00000000 0000000 00000000 1111111 0000000 11111111 1111111 11111111 0000000 00000000 1111111 11111111 0000000 00000000 11111111 1111111 00000000 0000000 00000000 1111111 0000000 11111111
(d)

11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 11111 00000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 Q 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000
(e)

111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 Q 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111111 000000000 111111 000000 111111111 000000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000 111111 000000
(f)

Fig. 3. Packings

4.4

Analysis of Competitive Ratio

We rst give some lemmas useful for analyzing RSPs competitive ratio. Lemma 4. Given a brick A and two squares Q1 , Q2 , if |Q1 | + |Q2 | |A|/ 2, then they can coexist in A.

Proof. For simplicity, assume A is ( 2, 1), two squares Q1 = (a, a), Q2 = (b, b). If they cannot be packed together into A, then a + b > 2 or a > 1 or b > 1. If a > 1 or b > 1, then |Q1 | + |Q2 | > If a + b > 2, then a2 + b2 (a + b)2 /2 > 1. 1. 2 In both cases, |Q1 | + |Q2 | > |A|/ 2, a contradiction. Lemma 5. If there is a tiny square packed in E3 , then p(E1 E2 E3 ) > x2 , where x = 1 2 2/3. Proof. Let Q be a tiny square in E3 . Let U1 , ..., Uk be the set of unused bricks in E1 E2 . Since Q was not packed in E1 or E2 by algorithm PB, for any i, |Ui | < |S(Q)|. Algorithm PB gurantees that there is at most one unused brick k with area |S(Q)|/2i in E1 E2 , for any i 1. Thus i=1 |Ui | < |S(Q)|. By Fact 3 and D1 = E2 = (x, 2x),
k

p(E1 E2 E3 ) |Q| + (|E1 | + |E2 |

i=1

|Ui |)/(2 2) > x2 . 2

By the similar way, we have the following lemma. Lemma 6. If there is a small square Q in D, then p(D1 D2 ) 1/18. If there is a small square Q in B, then p(D1 D2 ) + |Q| 1/9. The packing ends either by the stopping rules of algorithm RSP or by the instance itself. If RSP stops at Step 1 for some round, the competitive ratio is obviously achieved. Note that in Step 2, we do not remove any square, i.e, in the current round, the packed area by our packing is not worse than the one by an optimal packing. If we guarantee the competitive ratio is at most 3 in the previous round (Step 3), then we can say after the current round the competitive ratio is still at most 3. Therefore, to analyze the algorithm, we only need to consider Step 3. We rst consider Case (3.3). Let m be the number of times that the execution passes through Case (3.3). We have the following results. Lemma 7. In Case (3.3), i) the total area of unused bricks in D1 D2 B is at most 2m 2/9, ii) p(B) > 1/3 2m /18, iii) every time, the removed area is at most 1/18 + 2m /36. Moreover, if m = 5, then p(B) 1/3. Proof. First we show that there is a c-brick congruent to S(Q) in D1 D2 B. Since Q is a small square, if there is no c-brick congruent to S(Q), then all sbricks in D1 D2 B are congruent to S(Q) and contain squares. Therefore, by Fact 3, p(B) 1/3, which causes a contradiction. Hence, there is at least one c-brick congruent to S(Q). Let U be the largest unused brick in D1 D2 B. In this step, a small square Q cannot be packed by P B, then we nd a c-brick P containing U such that

|P | = |S(Q)|, empty P and pack Q into it. After this step, the area of the largest unused brick in D1 D2 B will decrease to at least one half. Hence one half is guaranteed by Lemma 3 (there is at most one unused brick with area |S(Q)|/2i in D1 D2 B, for any i 1). Then there is at most one unused brick with area |U|/2i in D1 D2 B, where i 0. So, the total area of all unused bricks in D1 D2 B is |U|/2i < 2|U|.
i=0

By the algorithm, every time, the area of the largest unused brick reduces at least a half. When m = 0, |U| |S(Q)|/2 2/18. After Case (3.3) occurs m times, |U| 2m 2/18. Then the total area of the unused bricks in D1 D2 B is less than 2|U| 2m 2/9. Hence, p(D1 D2 B) 1 1 2|D1 | + |B| 2|U| 2m . 3 18 2 2

Next, we estimate the removed area when a square Q is packed. Recall that |U| 2m 2/18. Except U, the total area of unused bricks in D1 D2 B is less than |U|. Recall that P is the selected c-brick. Except in P , by Fact 3, the packed area is p(B P ) 2|D1 | + |B| |P | |U| 1 |S(Q)| + |U| . = 3 2 2 2 2

Note that p(B P ) + p(P ) = p(B) < 1/3 (otherwise the packing stops). Hence, the removed area p(P ) 1 |S(Q)| + |U| 1/18 + 2m /36, p(B P ) 3 2 2

since |S(Q)| 2/9. When m = 5, U is not larger than brick ( 2/24, 1/24). Since 1/24 < 1 2 2/3, we see there is a tiny square in D1 D2 B. By Lemma 5, p(E1 E2 E3 ) > x2 . Therefore, p(B) 1/3 25 /18 + x2 > 1/3. 2 We then prove if the packing stops by algorithm RSP at Step 3, then the packed area in the bin is at least 1/3. Lemma 8. If algorithm RSP stops at Step 3, then p(B) 1 . 3 Proof. It is not dicult to see that in Cases (3.5) and (3.8), when the packing stops, p(B) > 1/9 + 2/9 = 1/3. Then we consider other cases in Step 3. Case (3.1). Recall that T is the largest s-brick. Before packing a small square Q, by Fact 3, we have 2 2 |S(Q)|)/(2 2) 1/3 |Q|. p(B) ( 3

Except the area for the selected s-brick T , the packed area is p(B T ) 1/3 (|S(Q)| + |T |)/(2 2). Again, since p(B T ) + p(T ) = p(B) < 1/3, we have p(T ) (|S(Q)| + |T |)/(2 2). Since |Q| |S(Q)|/ 2 and |T | 4|S(Q)|, |T | 3|S(Q)| + |T | . p(T ) + |Q| (|S(Q)| + |T |)/(2 2) + |Q| 2 2 2 By Lemma 4, Q can be packed in T . After packing Q, p(B) 1/3. Case (3.2). Before packing Q, p(B) 1/3 |Q|. If Q can be packed in T , after packing Q, p(B) 1/3. Otherwise, by Lemma 4, we have p(T ) + |Q| > |T |/ 2. Excepting T , before packing Q, the packed area is p(B T ) 1/3 (|S(Q)| + |T |)/(2 2). Note that there exists a c-brick congruent to S(Q) with packed area less than |S(Q)|/(2 2). (Otherwise all c-bricks congruent to S(Q) have packed area as least |S(Q)|/(2 2), and therefore the packed area in the bin will be at least 1/3.) Let P be the selected c-brick. Since the packed area in P is the smallest among all c-bricks congruent to S(Q), we have p(P ) < |S(Q)|/(2 2). So, after packing Q into P , p(B) = p(B T ) + p(T ) + |Q| p(P ) > 1 1 |S(Q)| + |T | |T | |S(Q)| + = . 3 3 2 2 2 2 2

The last equality follows from |T | = 2|S(Q)|. Case (3.7). Let P be the one in the bottom-left corner of B. Since there is a small square in B, by Lemma 6, p(D1 D2 ) + |P | 1/9. If Q can coexist with P , then p(B) 1/3. Else |Q| > 5/18, since |P | 2/9. Hence, after removing all in B and packing Q, p(B) |Q| + p(D1 D2 ) 1/3, since p(D1 D2 ) 1/18. Case (3.9). Let P be the smaller one of two large squares. Then |P | 1/6. Since |Q| 1/3, then P and Q can coexist in bin B. After packing Q, p(B) 1/3. Case (3.4). This case is similar to Case (3.9). After packing Q, p(B) 1/3. 2 Lastly we show the packing stops by the input, the competitive ratio is at most 3. Lemma 9. If there are no more squares coming, RRSP 3. Proof. Case (3.5) and Case (3.8). In both cases, before packing Q, B contains only one large square, say P . It means that Cases (3.1)-(3.3) and (3.6) have not yet occurred. In other words, no small squares have been removed so far. Note that P and Q cannot coexist in bin B. Then 1/4 < max{|P |, |Q|} 1/3, 1/6 < min{|P |, |Q|}.

Recall that the algorithm removes the larger one between P and Q. If the packing stops after this step, RSP (L) z + min{|P |, |Q|} and OP T (L) z + max{|P |, |Q|}, where z is the total area of the small squares in bin B. It follows that z + max{|P |, |Q|} OP T (L) 2. RRSP = RSP (L) z + min{|P |, |Q|} Case (3.3). In this case, we claim that neither of Cases (3.5), (3.8) and (3.6) has occurred so far. Otherwise, there is at least one large square in bin B and the packing would have stopped in Case (3.1) or Case (3.2). Therefore, no large squares have been considered so far. Let y be the total area removed in Case (3.3). Let m be the number of times that the execution passes through Case (3.3). By Lemma 7, RSP (L) = m1 1 1 i p(B) 1/3 2m /18 and y i=0 ( 18 + 36 2 ), where m 1. Since OP T (L) RSP (L) + y, RRSP OP T (L) RSP (L) + y . RSP (L) RSP (L) (1)

Case (3.6). In this case, before considering Q, there are some small squares in B. By Lemma 6, p(D1 D2 ) 1/18. And, there are two subcases, i.e., Nl = 1 and Nl = 0, where Nl is the number of large squares in B. Recall that y is the total area removed in Case (3.3) and m is the number of times that the execution passes through Case (3.3). First consider the case Nl = 0, i.e., only small squares in B. Then neither of Cases (3.5), (3.8) and the second subcase of Case (3.6) has occurred. Since the packed area p(B) < 1/3, then the execution does not pass by Cases (3.1), (3.2), (3.4), (3.9), (3.7). By Lemma 6, p(D1 D2 ) 1/18. Since before packing Q, p(B) < 1/3, the removed area in this step is less than (1/3 1/18)/2 = 5/36. By Lemma 7 i), before packing Q, the total area of unused bricks in D1 D2 B is at most 2m 2/9. And after packing Q, we do not increase any unpacked brick in B, then the total area of unused bricks is still at most 2m 2/9. Then after packing Q, by Fact 3, 2|D1 | + |B| 2m 2/9 1/3 2m /18. RSP (L) 2 2 Since OP T (L) RSP (L) + y + 5/36, RRSP OP T (L) RSP (L) + y + 5/36 . RSP (L) RSP (L) (2)

Then consider the case Nl = 1, i.e., one large square in B, say P . If Case (3.5) or Case (3.8) has occurred before, by the analysis in lemma 8, |P | 1/6. After packing Q, p(B) p(D1 D2 ) + |P | + |Q| 1/18 + 1/6 + 1/9 = 1/3.

If neither Case (3.5) nor Case (3.8) has occurred, we have not removed any large square so far. After packing Q, by the above analysis, RSP (L) 1/3 2m/18. In this case, Nl = 1, the removed area is less than 1/6, otherwise the packed area is over 1/3 = 1/18 + 1/9 + 1/6. So OP T (L) RSP (L) + y + 5/36 + 1/6. Hence, RSP (L) + y + 5/36 + 1/6 OP T (L) . (3) RRSP RSP (L) RSP (L) By inequalities (1),(2),(3), we have RRSP 1/3 2m /18 + y + 5/36 + 1/6 < 3. 1/3 2m /18 0 1 2 3 4 0 1/12 11/72 31/144 79/288 < 2.1 25/11 56/23 102/47 2.758 2 The following theorem directly follows from lemmas 8 and 9. Theorem 3. The competitive ratio of RSP is 3. Finally in this section, it should be noted that our new partition of the bin better than the one of [10]. Proposition 1 can be improved as follows (Proof is omitted). Proposition 2 Any square list with the total area at most 1/3 can be online packed into a unit square bin without removing.

The last inequality follows from the following table. m= y= RRSP

A PTAS for Oine Packing

The problem is, given a set S of n squares of side length at most one, how to pack a subset of S into a xed rectangle of size (1h) so that the packed area becomes maximum (previously h was 1, which can be generalized). The algorithm is based on the same idea as [4]: (i) Select an integer k such that k > (1 + h), which is associated with the error bound of the PTAS. (ii) The region (0,1] is divided into k + 2 sub-intervals, R0 , R1 , , Rk+1 , where Ri = (Pi , Pi1 ], R0 = (P0 , 1] i and Rk+1 = (0, Pk ] and Pi = k 3 and P0 = 1/k, 1 i k. Decompose S into S0 , , Sk+1 such that Q Si if and only if its side length is in Ri . |Si | denotes the total area of squares in Si . (iii) Pack all squares in S S0 by NFDH. If there remain one or more squares unpacked, then output that packing. (iv) Otherwise, nd an index i such that |Si | = min{|S1 |, , |Sk+1 |}. Let Xl = S0 Si1 and Xs = Si+1 Sk+1 . (Here it is important to remove Si , which makes a gap between large and small items.) (v) Obtain an optimal packing for the large items in Xl using the exhaustive method [4]. The unpacked region in the bin can be decomposed into a limited number of rectangles. Then the small items in Xs are packed into those rectangles (in an arbitrary order) by NFDH. Theorem 4. The worst case ratio of the algorithm is (1 + 6(1 + h)/k). (The proof is similar to [4] and may be omitted.)

Concluding remarks

As mentioned earlier, it is still open if we can achieve the bound of Theorem 1 without using repacking. Our algorithm RSP borrows the concept of brick. If we stay on this line, then it seems hard to obtain a better bound than 2 2. Extending to online rectangle packing with reasonable restrictions should also be nice future work. Acknowledgments The authors wish to thank the referees for their useful comments on the earlier draft of the paper. Their suggestions have helped improve the presentation of the paper.

References
1. N. Bansal and M. Sviridenko, New approximability and inapproximability results for 2-dimensional bin packing, SODA 189-196, 2004. 2. A. Caprara and M. Monaci, On the two-dimensional knapsack problem, Operations Research Letters 32:5-14,2004. 3. M. Caramia, S. Giordan, and A. Iovanella, An on-line algorithm for the rectangle packing problem with rejection, Proc. WEA, LNCS 2647:59-69, 2003. 4. J.R. Correa and C. Kenyon, Approximation schemes for multidimensional packing, SODA 179-188, 2004. 5. L. Epstein and R. van Stee, Online square and cube packing, Acta Informatica 595-606, 2005. 6. A.V. Fishkin, O. Gerber, K. Jansen, R. Solis-Oba, Packing Weighted Rectangles into a Square, MFCS 352-363, 2005. 7. C.E. Ferreira, E.K. Miyazawa, and Y. Wakabayashi, Packing squares into squares, Pesquisa Operacional, 19:223-237, 1999. 8. K. Iwama and S. Taketomi, Removable online knapsack problems, Proc. ICALP, LNCS 2380:293-305, 2002. 9. K. Jansen and G. Zhang, On rectangle packing: maximizing benets, SODA 197206, 2004. 10. J. Januszewski and M. Lassak, On-line packing sequences of cubes in the unit cube, Geometriae Dedicata, 67:285-293, 1997. 11. Y. Kohayakawa, F.K. Miyazawa, P. Raghavan, and Y. Wakabayashi, Multidimensional cube packing, Algorithmica, 40(3):173-187, 2004. 12. J.Y.-T. Leung, T.W. Tam, C.S. Wong, G.H. Young, and F.Y.L. Chin, Packing squares into a square, J. Parallel Distrib. Comput. 10:271-275, 1990. 13. A.Meir and L. Moser, On packing of squares and cubes, Journal of combinatorial theory, 5:126-134, 1968. 14. P. Sanders, N. Sivadasan, M. Skutella, Online Scheduling with Bounded Migration, ICALP 1111-1122, 2004. 15. S.S. Seiden and R. van Stee, New bounds for multidimensional packing, Algorithmica 36:261-293, 2003. 16. A.C.-C. Yao, New Algorithms for Bin Packing, J. ACM 27, 207-227, 1980.

You might also like