On-line bin packing in linear time

On-line bin packing in linear time

JOURNAL OF ALGORITHMS (1989) lo,305326 On-Line Bin Packing in Linear Time PRAKASHRAMANAN* Depurtment of Computer Science, University of Califor...

1MB Sizes 3 Downloads 94 Views

JOURNAL

OF ALGORITHMS

(1989)

lo,305326

On-Line Bin Packing

in Linear Time

PRAKASHRAMANAN* Depurtment

of Computer Science, University of California, Santa Barbara, California 93106

DONNA J. BROWN+ Coordinated

Science L&oratory,

University

of Illinois,

Urbana,

Illinois

61801

C. C. LEE AND D. T. LEE* Department

of Electrical

Engineering and Computer Science, Northwestern Evanston, Illinois 60201

University,

Received March 15,1987; accepted May 26,1988

In this paper, we study the l-dimensional on-line bin packing problem. A list of pieces, each of size between zero and unity are to be packed, in order of their arrival, into a minimum number of unit-capacity bins. We present a new linear-time algorithm, the Modified Harmonic Algorithm and show, by a novel use of weighting functions, that it has an asymptotic worst-case performance ratio less than ! + : + & = 1.(615)*. We show that for a large class of linear-time on-line algorithms including the Modified Harmonic Algorithm, the performance ratio is at least : + $ = 1.61*. Then we show how to successively construct classes of improved linear-time on-line algorithms. For any algorithm in any of these classes, the performance ratio is at least $ + & = 1.583*. We present an improved algorithm called Modified Harmonic-2 with performance ratio 1.612.. and present an approach to construct linear-time on-line algorithms with better performance ratios. The analysis of Modified Harmonic-2 is omitted because it is very similar to that of Modified Harmonic, but it is substantially more complicated. Our results extend to orthogonal packings in two dimensions. B 1989 Academic press. hc.

1. INTRODUCTION

Let L = (A, The l-dimensional

p2,.

. . , p,) be a list of pieces with sizes in the interval (0, 11. bin packing problem is to pack the pieces into

a

*Part of this author’s work was performed when he was a graduate student at the University of Illinois, Urbana, IL. His work was supported in part by an IBM Graduate Fellowship. +This author’s work was supported by the National Science Foundation under Grant NSF IST So-12240 and the Joint Services Electronics Program (U.S. Army, U.S. Navy, and U.S. Air Force) under Contract NOOO14-79-C-0424. *This author’s work was supported in part by the National Science Foundation under Grant MC’S 83-42862. 305

0196-6774/89 $3.00 Copyright Q 1989 by Academic Press. Inc. All rights of reproduction in any form reserved.

306

RAMANAN

ET AL.

minimum number of bins in such a way that the sum of the piece sizes in each bin is at most one. As this problem is known to be NP-complete [GJ79, K72], much work has been done in the study of approximation algorithms; a survey of these results is given in [CGJ84]. For any (heuristic) bin packing algorithm A, let A(L) denote the number of bins used by algorithm A in packing list L, and let OPT(L) denote the minimum (optimum) number of bins required to pack list L. We are concerned with the asymptotic worst-case performance ratio R,=

lim n-+cc orgtgn

A(L)

oPT( L) .

Thus, we would like to construct an algorithm A which has a performance ratio close to one. Intuitively, we want an algorithm that minimi~s, for large lists, the worst-case percentage of excess bins used compared to an optimal packing. In this paper we concern ourselves with algorithms for which the pieces in list L are available one at a time, and each piece must be packed in some bin before the next piece is available; such an algorithm is referred to as on-line. Previously known on-line algorithms include the O(n) Next-Fit (NF), and the O(n log n) First-Fit (FF) [J73, 574, JDUGG741, the O(n) Harmonic (H) and the O(n) Refined Harmonic (RI-I) [LL85], the O(n log n) Refined First-Fit (RFF) [Y80], and the 0( n log n) Doubly Refined First-Fit (DRFF) [B79b]. These algorithms have the following performance ratios: R w=2, 1.7, R, = 1.692 . . . . R, = 1.636.. ., R, = 1.6*, and R,,= R nRFF < 1.64. In this paper, we present a new linear-time on-line algorithm which we call Modified Harmonic (MH), and show that R,, -c 1.(615)*.’ Then we show how to successively construct classes of improved linear-time on-line algorithms. As an example of this improvement, we present an algorithm with performance ratio less than 1.612. . . . On the lower bound side, Yao [Y80] showed that for any on-line algorithm, the performance ratio is at least 1.5. This lower bound was further improved to 1.536.. . independently by Brown [B79a] and Liang [L80]. Lee and Lee [LL85] showed that for any constant-space, on-line algorithm, the performance ratio is at least 1.691. . . . It should be observed that considerably better performance ratios exist for algorithms which are not on-line (see [CGJ84]). For instance, Karmarkar and Karp [KK82] presented an algorithm that is asymptotically optimal; i.e., it has performance ratio one. In Section 2, we present our Modified Harmonic Algorithm and describe the packings produced. In Section 3, we use a novel weighting function ‘* denotes

recurring

decimals.

For example,

1.(615)*

= 1.615615615.

ON-LINE

BIN PACKING

307

scheme to analyze the algorithm. In Section 4, we show that for a large class of linear-time on-line algorithms including the Modified Harmonic Algorithm, the performance ratio is at least $ + $ = 1.61*. In Section 5, we show how to successively construct classes of improved linear-time on-line algorithms. For any algorithm in any of these classes, the performance ratio is at least 2 + & = 1.583*. As an example of this improvement, we present an algorithm called Modified Harmonic-2 (MH2), with performance ratio less than 1.612.. . . The analysis of MH2 is omitted because it is very similar to that of MH, but is substantially more complicated. In Section 6, we summarize our results and make some further observations. 2. THE MODIFIED

HARMONIC

ALGORITHM

The Modified Harmonic Algorithm (MH) is based on three previously known on-line algorithms: the Refined First-Fit Algorithm of Yao [Y80], the Next-Fit Algorithm of Johnson [J73], and the Harmonic Algorithm of Lee and Lee [LL85]. Because the latter two algorithms are needed to describe our algorithm, we first briefly describe them. The Next-Fit Algorithm operates as follows. Initially, the empty bins are indexed as bin,, bin,, . . . . Piece p1 is packed in bin,. Suppose that PI, P2, * * *9 piPI have been packed, and pi is the next piece to be packed. Let j be the largest index such that binj is nonempty. If pi will fit in binj, then pi is packed in bini; otherwise pi is packed in binj+l. The Harmonic Algonthm is based on the harmonic partition of the interval (0, 11: (Ovl]

=

CIj,

j-l

where Ii = (l/(j

+ l), l/j],

1 I j -C k, and Ik = (0,1/k],

for some k > 1. A piece p is called an I,-piece if p E Ii, 1 I j < k. Initially, the set of empty bins is divided into k infinite classes: bins of type Bj, 1 I j I k. A bin of type Bj is used to pack only I/pieces. Note that j Ij-pieces can be packed in a bin of type Bj for 1 I j -C k. Suppose that PI, P2, - *f 9pieI have been packed, and pi is the next piece to be packed. If pi is an Ij-piece for some j, 1 5 j < k, then it is packed in a nonempty bin of type Bj that contains fewer than j pieces, if one exists; if no such bin exists, then pi is packed in an empty bin of type Bj. If pi is an I,-piece, then it is packed in bins of type B, by Next-Fit. Now we are ready to describe the Modified Harmonic Algorithm. Tbis algorithm tries to utilize the space wasted by the Harmonic algorithm in bins of type B,. The algorithm is based on the following partition of the

308

RAMANAN

ET AL.

interval (0, 11: (0, l] = r, U 12 ; Ij, j=l

where

fl =(l -YA Ii = (l/(

A

j +

11 =(:,I

=(y,f],

W/A,

3
-Y],

and

r,=(;,y], Ik = (0,1/k]

>

for some y and k, $ < y < i and k 2 3 (exact values for y and k will be given in Section 3). A piece p is called an Ii-piece if p E fl, $-piece if p E f2, Ij-piece if p E Ii for some j, 1 I j I k. Initialll, t&e set of empty bins is divided into k t 2 infinite classes: bins of type B,, B,, and Bj,l I j I k. A bin of type B, is used to pack only ii-pieces, a bin of type B, is used to pack only j,-pieces, and a bin of type Bj, 2 I j I k, is used to pack only lip&es. All Ii-pieces are packed in bins of type B,. In addition, some of the I,-pieces for 2 I p I 3 or 6 I p I k 2, are also packed in bins of type B,. In particular, for each p, a fixed fraction l/m, (values for the rneP.swill be given in Section 3) of the I,-pieces are packed in bins of type B,; if there are a sufficient number of Ii-pieces, then each bin of type B, will also contain an Ii-piece. Thus, each nonempty bin of type B, will contain an II-piece and/or I,-pieces (at most max(1, ]py]) of them) for one p, 2 I p I 3 or 6 I p I k - 2. The algorithm packs a list in such a way that, at any stage in the packing: (1) each nonempty bin of type 3, contains 1 Ii-piece, (2) each nonempty bin of type 2, (except possibly the last one) contains 2 I,-pieces, (3) each nonempty bin of type Bj, 2 < j < k (except possibly the last one) contains j Ij-pieces, (4) each nonempty bin of type B, (except possibly the last one) is at least (k - 1)/k full, and (5) each nonempty bin of type B, (i) contains only an It-piece, (ii) contains only an I,-piece or an 1,-p&e, (iii) contains an 1,-p&e together with an &-piece or an 1,-p&e, (iv) contains ]~y] I,-pieces for some p, 6 I p I k - 2, (v) contains an Ii-piece, and 1py ] I,-pieces for some p, 6 I p 5 k - 2,

(vi) contains at least one, and at most ([py j - 1) I,-pieces for some p, 6 I p I k - 2, or (vii) contains an Ii-piece together with at least one, and at most (1 py ] - 1) I,-pieces for some p, 6 I p I k - 2.

ON-LINE BIN PACKING

309

Moreover, if there is a bin as in (i), then there can be no bins as in (ii), (iv), or (vi). Also, for each p, 6 I p I k - 2, the number of bins as in (vi) plus the number of bins as in (vii) is at most one. When we say harmonic pack( pi, Ii), where pi is an I,-piece, 2 I j -C k, we mean: if

there exists a nonempty bin of type Bj containing fewer than j I,-pieces then pack pi in that bin else pack pi in an empty bin of type Bj.

When pi is an &-piece, harmonic pack( pi, &) is defined similarly, corresponding bin type B,. We now give a precise statement of our algorithm.

with

MODIFIED HARMONIC ALGORITHM for i := 1 to n do begin case pi in

f,: pack pi in an empty bin of type B, I, (j = 4,5,

or k -

72: harmonicpack(pi, j,) 1): harmonicpack( p,, Z,) Z,: pack pi in bins of type Bk

by Next-Fit Z,: if there exists a nonempty bin of type B, that does not contain an II-piece then pack pi in that bin else pack pi in an empty bin of type B, Z, (2 < p I 3): ifp, is the (m,r)th I,-piece to arrive thus far for som; integer r21 then if there exists a bin of type B, containing only an II-piece then pack pi in that bin else pack pi in an empty bin of type El else harmonic

pack(

pi, Z,)

Z, (6 s p s k - 2): if pi is the (m,r)th I,-piece to arrive thus far for some integer r>_l then if there exists a bin of type B, containing at least one, and at most 1py ] - 1 IO-pieces then pack pi in that bin else if there exists a bin of type B, containing only an II-piece then pack p, in that bin else pack pi in an empty bin of type B, else harmonic

pack ( pi, Z, )

end.

It is easy to see that the Modified Harmonic Algorithm runs in linear time and uses linear space. Note that in the above algorithm, we had implicitly assumed that the m,s are integers. The values we will be specifying in Section 3 will not be integers. In this case we require that at any stage if aP

310

RAMANAN

ET AL.

is the number of If-pieces that have been packed, then ]a,/m,] of them have been packed m bins of type B,. It is easy to modify the algorithm accordingly.

3. ANALYSIS

OF THE ALGORITHM

In this section, we use weighting functions to analyze the performance of the Modified Harmonic Algorithm. Throughout this section we shall be considering only the nonempty, i.e., packed, bins. The weight of a bin is defined to be the sum of the weights of all the pieces in the bin. We shall assign weights to pieces in such a way that the average weight of all but a constant number of bins packed by our algorithm is at least one. Let i& and iCz be the weights of an ii-piece and an &-piece, respectively. Let wj be the weight of an Ij-piece, 1 ~j -C k, and let wk(s) be the weight of an I,-piece of size s. As in [LL85], a bin can contain one I,-piece, two I,-pieces, four &-pieces, five I,-pieces, or (k - 1) I,-,-pieces. So we have iCi = 1, & = i, w, = f, ws = $, and w,‘-i = l/(k - 1). Since a bin of type B, will be at least (k - 1)/k full, we assign to an I,-piece of size s the weight We = ks/ (k - 1). Recall that, for 2 < p I 3 or 6 I p I k - 2, some of the $-pieces are packed in bins of type B,. The weights we assign to the Ii-pieces and I,-pieces depend on the input list L. Let a be the number of bins in the packing of L produced by the Modified Harmonic Algorithm that contain only an Ii-piece. The weights we assign to the II-pieces and $-pieces depend on whether (Y > 0 or 01= 0. For cu> 0, there are bins containing only an It-piece; moreover, every bin of type B, contains an Ii-piece. We assign weights to the Ii-pieces and $-pieces in such a way that the average weight of all bins of types B, and BP is one: wi = 1 and wP = (1 - l/m,)/p, for 2 I p I 3 or 6 I p I k - 2. For CY= 0, not all the bins of type B, contain an Ii-piece. Again, we assign weights to the Ii-pieces and I,,-pieces in such a way that the average weight of all bins of types B, and BP is one: w, = 0, wp = (1 - l&)/P

+ l/m,

for2IpI3,

WP = (1 - l/%)/P

+ &

for 6 I p I k - 2. P

Table I summarizes the above weighting functions. We make use of these weighting functions to analyze our algorithm’s performance. Letting W(L) be the sum of the weights of all the pieces in

ON-LINE

BIN

311

PACKING

TABLE I Weighting Functions for (Y > 0 and a = 0 Weight Interval

wntaining

&:(l -y,l] I,: o/2,1 7,: (~,1/21 12: (l/3,

size s

1 --2 1 ---

ul

1 0

l/2

3

l/2

1

1

25 1

:+G1

3m3

?‘3m,

l/4 l/5

14: (l/5,1/41

I,: (l/6,1/51 1 --6

L,: U/7,1/61

1 ---

I,: W(P + 1).l/PI

P

1 (l/(k

a=0

1 1

- VI

I,: (l/4,1/31

Ik-*:

of a piece of size s

a>0

- l),l/(k

- 2)]

Ik-,: (l/k l/(k - 01 Ik: (0,WI

k-2

22

l/4 l/5 1 ---+-

1 6% ‘1

1’

6

6~

1

1’

---+P pm,

pm,

.l -

1

1

(k-2)m,-,

k-2

1

~16~1 1

qhyl

1

1

(k-2)m,-,

Mk - 1) Wk - 1)

+ m,-,[(k-2)y]

l/(k - 1) Wk - 1)

list L, we show in Lemma 1 that MH(L)

< W(L)

+ 2k - 7.

In Lemma 2, we show that for appropriate W(L)

< (3/2 + l/9

values of y, k, and the m,s,

+ 1/222)OI’T(

L).

Combining these results gives us the following bound on our algorithm’s performance: R MH -q+$+& In Lemma 3, we prove that this bound is essentially tight. The results of these three lemmas are combined to give Theorem 1. LEMMA 1.

For any list L, MH( L) < W(L) + 2k - 7.

Proof: Let b, and b, be the number of bins of type & and B,, respectively, and let bj be the number of bins of type Bj, 1 I j I k. It is

312

RAMANAN

ET

AL.

clear that MH( L) = b, + b, + E;,,b,. Let w, and ‘w2 be the sum of the weights of all the Ii-pieces and &-pieces, respectively, and let Wj be the sum of the weights of all the Ij-pieces, 1 I j I k. It is clear that W(L) = w, + iv* + cglwj. It is easy to see that we have constructed the weighting functions in such a way that each bin (except possibly the last one) of type Bi, B,, B4, B,, or B k-l, has weight precisely one. So b, = w,, b2 < w, + 1, b4 < W, + 1, b, < W, + 1, and b,-, < W,_, + 1. Since each bin of type B, (except possibly the last one) must be at least (k - 1)/k full, its total weight is at least one, and so b, < W, + 1. Let aj be the number of Ij-pieces, 1 ~j I k. To analyze the weights of bins of types B, and BP, 2 I p 5 3 or 6 5 p I k - 2, we consider separately the two weighting functions and show that the lemma holds both for cu>Oanda=O. Case 1. a > 0. Every bin of type B, has an Ii-piece, and so b, = WI. For 2 I p I 3 or 6 I p I k - 2, not all of the I,-pieces are packed in bins of type BP. In particular, we have

bP= I(%- lap/m,])/P] < a,0 - w&P + 1 = w,+1. Summing

all the inequalities

for Case 1, we get MH(L)

< W(L) + k.

Case 2. (Y = 0. A bin of type B, containing an I,-piece for some 21p13or61p1k-2,iscalledabinoftypeB,,,.Sincea=O,every bin of type B, is of one of the B,, p t yp es. Let b,, p be the number of bins t-e B,,,. Clearly b, = &,bl,p. Noting that for (Y = 0 the weight of Ii-piece is 0, the weights of the IP-pieces must “compensate.” For 2 5 p I we have

p, of an 3,

by+ b~,p = I(%- la,/m,])/pl + lap/m,] < a,(1- l&J/P + a,/m,+ 1 = a,(1 + (P - 1)&)/p + 1 = wp+ 1. For 6 I p I k - 2, each bin (except possibly the last one) of type B,, p

ON-LINE

contains lpv]

313

PACKING

I,-pieces. As above, we have

=u

1 ---

1

’l P

= w,+

Summing

BIN

all the inequalities

pm,

1

+-

+2 mplPY1

I

2.

for Case 2, we get MH( L) < W(L) + 2k - 7. !Il

LEMMA 2. Consider the weighting functions specified in Table I for a > 0 and (Y = 0. Let y = E, k = 38, mz = 9, m3 = 12, and mp = (k - 1) (p + l)/( k - p - 1) = 37(p + 1)/(37 - p) for 6 s p I k - 2 (see Table II). Then W(L) < ($ + ; + &)OPT( I,). Proof. Consider a bin B in the optimal packing, and let sr 2 s2 r . . . 2 s, be the sizes of the pieces packed in it, sr + s2 + . . . +s, I 1. Let w(si) be the weight of a piece of size si, and let w(B) be the weight of B. It is clear that w(B) = w(sJ + w(sz) + . .. +w(st). We shall prove that w(B) < i + i + A, both for cu > 0 and a! = 0. The proof is done by cases, depending on the sizes of some of the largest pieces in B. Tables III and IV summarize the cases for (Y > 0 and (Y = 0, respectively. Columns sr, s2, and s3 indicate the intervals containing the sizes of the first, second, and third largest pieces in B. For convenience, we let !j (j 2 r) denote one of the intervals I,, Ir+i, . . . , Ik, or the “interval” [O]; i.e., no piece at all. Column 5 gives an upper bound on the remaining space left in the bin after packing the pieces of sizes specified in columns sr, s2, and sg. To determine an upper bound on w(B), we find it useful to compute upper bounds on w(s)/s for each possible piece size s (see Table II). In particular, we shall make use of the fact that

i w(sj) ~2 i sj max w(s,)/s,. j-i

j=i

19rst

Column w(B) in Tables III and IV specifies an upper bound on w(si) + w(sz) + *-* + w(s~), calculated by taking w(sJ if si is specified, plus w(sz) if s2 is specified, plus w(s3) if sg is specified, plus S max,
314

RAMANAN

ET AL.

TABLE II Weight Summary for all sizes s, when y = 265/684, k = 38, m2 = 9, m 3 = 12, and mp = (k - l)( p + l)/(k - p - 1) = 37( p + 1)/(37 - p) for60 4s)

w(s)/s (upper bound)

Interval containing size s i1: (1 - y,l] II: Q/2,1 -

a=0

1 1

w(s)

w(s)/s (upper bound)

1 0

684/419 0

i2: (Y, i/21

l/2

684/419 2 342/265

12: I,: I,: I,:

4/9

11/36

4/3

11/9

5/9 7/18

l/4 l/5 38

5/4 6/5

l/4 l/5

VI

(l/3, Yl (l/4,1/31 (l/5,1/41 (l/6,1/51

16: (l/7,1/61

I,,:

IIs: (l/19,1/18]

(l/(k

38/37

3.8 19+37

38/37 38/37

3’8

- 2)l

- 1)l

342/265 5/3

14/9 5/4 6/5

107 14*37

2*37

107

52*37

4*37

177

20*37

- l),l/(k

Ik-1: (l/k, l/(k Ik: (O,l/kl

j8 13*37

38

I,.$ (l/20,1/19]

I,-,:

38/37

7*37

(l/13,1/12]

l/2

37*37

38/37

l/37

38/37 38/37

38s/37

i3

247

6*37 71

6*37 284

35*37

7*37

445

495

481* 37 l/37 38s/37

481 38/37 38/37

For a = 0, s E I,, and s’ E I,,, 6 2 j 5 j’ < k, upper bound on w(s)/s > upper bound on

Note.

w(s’)/s’.

For example, consider the case for LY> 0, with s1 E II and s2 E 12. Then S=l-(s,+s,)
;+++$y.

2

684

37

w(sJ

ON-LINE

BIN

315

PACKING

TABLE III ListofCasesProvingw(B)<~+$+&forcx>O

W(Q) Sl

4 I, or

z, or II or I1 or

II or I1 or i2

i, i, i, i, i1 iI

$3

12

-

12

-

t

I4

45

13

13

Zj (j

(j 2 5) -

1+:+g*g 1+++:*g l+g+:+$*g

1

1+ g + :*: 1+$+$+&*% 1+:+3*;

:

14

14

or Zj (j 2 2)

Y=&?i<,

:-

I, (i 2 5)

14

Ii

I

s2

t 2

5)

f

-

w(B) + w(s2) + . . . + w(s,) (upper bound)

: 1

1+

:*+ l*f

TABLE IV List of Cases Proving w(B) < t + $ + & for cx= 0 w(B) + w(s2) + . . . +W(S,) (upper bound)

w(sl) Sl

s2

$3

4

12

I 18

i,

12

Zj (j 2 19)

4

Ii (j 2 3)

-

-

-

5

y-3

‘-3x&

y - l/3

13

1+;+-

1

= 37/684 265

4

i2

i2

-

y = 265/684

1 -*2

l/2 1 l-2y=

is

or I2

i,

or

i,

or

12

13

l/12

I2

I2

Ii (j 2 4)

l/3

I2

4 (j 2 3)

-

213

-

-

1

Ii (j 2 3)

14

l+z4*9

< l/4 5

i,

38

+684*37

6*37

1

z+2+-*5

9+9+ii+-*5 9+9+-*-

5 3 154

107

684 7 5

1 3

2*37 1

177

12

4*37 107

2*37

316

RAMANAN

ET AL.

As another example, consider the case for (Y> 0, with si E 1, and s1 E Ii (j 2 5). Then si > i, and S = 1 - si -C $. The S portion of the bin has no piece larger than t, and so w( s)/s I ! for any piece in B other than si. This gives w(B) = w(sJ + i

W(Si) < 1 + : * 2 < 5 + 6.

r=2

As another example, consider the case for (Y= 0, with si E I,, s2 E Z,, and sj E 1s. Then s = 1 - (Si + s2 + S3) < 1 - (; + ; + a) = $. Thus, we know that each of sq,. . . , S, must be smaller than A, and so w(si)/si 5 177/(4*37) for 4 5 i 5 t. This gives

w(B) = w(sl) + W(Q) + w(+) + i W(Si) i=4

< 2 + ; + & + &*177/(4*37) <+++. Tables III and IV enumerate all possible cases, and it is easily checked that the values in the w(B) column are all at most + + $ + &. Thus, the result of the lemma follows. 0 Lemmas 1 and 2 guarantee that the performance ratio of MH is less than + + ; + &. We now show that this bound is essentially tight. LEMMA 3. Let y = z, k = 38, m2 = 9, m3 = 12, and mp = (k - 1) -(p + l)/(k - p - 1) = 37(p + 1)/(37 - p) for 6 I p < k - 2. Then R hmG+i+k-&-

Proof.

We shall exhibit lists L with arbitrarily MI(L) OWL)

3 1 =y+9+=--

1

large OPT(L)

such that

1 987,012 ’

Let n be a multiple of 24,675,300, and let L, = (pl, p2,. . . , p,), L, = qn), L, = ($1, t,>. . . , t,,), L, = (~1, ~2,. . . ,242,J and L, = u,), where pi = : + E, qi = y + E, ti = & + E, ui = & + E, and u. = 1 - 5q for some E, 0 < E < lo- “. Let L be the list obtained by cbncr%%ing these lists; i.e., L = L,L,L, L,L,.

ON-LINE

BIN

317

PACKING

Note that pi + qi + ti + 2ui + ui = 1. Hence, the packing in which each bin contains a pi piece, a qi piece, a ti piece, two ui pieces, and a ui piece is an optimal packing, and so OPT(L) = n. Now consider the packing produced by our algorithm. Note that mz5 =yandm 26 = 5. Since [25yl= 9 and [26y]= 10, 9 tj pieces or 10 ui pieces can be packed in the same bin with a pi piece. Thus, the packing produced by our algorithm consists of n n-p--= 9% n 9%

=

2n low6 2n

64,702n bins, each containing 64,935

bins, each containing

1 pi piece,

1 pi piece, and 9 ti pieces,

1443 9

2n lam,,

lln = 4995 bins, each containing ,

n(1 - l/m,,)/25 2n(l - l/m&/26

1 pi piece, and 10 ui pieces,

= 19n/481 bins, each containing

25 ti pieces,

= 76n/999 bins, each containing 26 ui pieces,

n/2 bins, each containing 2 qi pieces, and n/26,676 Summing,

bins, each containing 26,676 vi pieces.

we obtain

MH(L) OPT(L) Since OFT(L)

3

1

1 = z + 9 + 222 -

= n can be arbitrarily

1 987,012 ’

large, the result follows. 0

Note that 987,012 = 26,676; 37. The discrepancy of l/987,012 in our analysis is due to the weights we assigned to the I,-pieces. For the list considered in the proof of Lemma 3, bins of type B, are completely packed, instead of being only (k - 1)/k full. Lemmas 1, 2, and 3 are summarized by the following theorem. THEOREM

a( p + l)/(k

1. Lety=~,k=38,m,=9,m,=12,andmP=(k-1) - p - 1) = 37( p + 1)/(37 - p) for 6 I p I k - 2. Then

318

RAMANAN ET AL.

i.e.,

1.6156146 < R,,

< 1.(615)*.

4. A GENERAL LOWER BOUND In this section, we show that for a large class of linear-time on-line algorithms based on partitioning the interval (0, 11, including the Modified Harmonic Algorithm, the performance ratio is at least $ + t = 1.61*. Let C be the class of algorithms which behave as follows. If A E C, then A divides the interval (0, l] into disjoint subintervals, including j, =

(1 - y, 11, 4 = C:,1 - ~1, 7, = (Y, $1, I2 = (5, ~1, and IA = (0, Al, for some y and X, $ < y < $, and 0 < A I $. Pieces are classified according to the intervals to which they belong. The packing produced by A must obey the following rules: (Rl) The number of bins which contain only one &-piece (with or without pieces of other types) is a fixed fraction l/m (m need not be an integer, and if this fraction is zero, we take m to be co) of the total number of I,-pieces in the input list. (R2) No bin may contain (i) an Ii-piece and an &piece or (ii) an Ii-piece and an &-piece. (R3) -No bin may contain an IA-piece together with an I,-piece, Ii-piece, 1,-p&e, or an &-piece. For A < $, (X, :I-pieces can be packed in any manner (even with pieces of other types). Note that the Modified Harmonic Algorithm is in C. We have the following lower bound on the performance of any algorithm in C. THEOREM 2.

For any algorithm A E C, R, 2 : + $ = 1.61*.

Proof: We shall exhibit three kinds of lists L with arbitrarily large OPT(L), and show that the average value of A( L)/OPT( L) for these three kinds of lists is at least : + 6. Let n be a positive integer that is a multiple of 6m (for simplicity, we assume that m is rational), and M = [1/(6h)]. Each of these three kinds of lists will be of the form L = L,L,L,, where L, = (u,, ~2,. . . , un), L, = (u,, 4,. . . , u,,), and L, = (tl, t,, . . . , tM,,). Moreover, we will always have ui + ui + it4 ti = 1. Hence, the packing in which each bin contains a ui piece, a ui piece, and M ti pieces is an optimal packing, and so OPT(L) = n.

ON-LINE

BIN

319

PACKING

Let E be such that

(:

Q<&
-VI’ (Y - 9’ (M + 1)“’ (A4 + 1)2 I *

Instance 1. Let ui = : + M&/2, ui = : + M&/2, and ti = 1/(6M) - E. Clearly, ui E It, ui E 12, and ti E IA. Now consider the packing produced by algorithm A. By rules Rl to R3 imposed on the algorithms in class C, this packing consists of n(1 - l/m)/2 bins, each containing 2 vi pieces, n/m bins, each containing 1 ui piece (and maybe 1 ui piece), at least n(1 - l/m) bins, each containing 1 ui piece alone, and at least n/6 bins containing ti pieces. Hence A(L)

2 n(1 - l/m)/2

+ n/m + n(1 - l/m)

+ n/6

= ($ - 1/(2m))n. Since OPT(L)

= n can be arbitrarily

large, we have

R, 2 ; - 1/(2m).

0)

This inequality arises from the fact that if l/m is too small, then only few I,-pieces will be packed in bins of type B,, leading to lot of wasted space. Instance 2. Let z+ =_ 1 - y t ME/~, ui = i + ME/~, and ti = (y - :)/ M - E. Clearly, ui E II, ui E 12, and ti E I,,. Now consider the packing produced by algorithm A. This packing consists of n bins, each containing 1 ui piece, n(1 - l/m)/2 bins, each containing 2 ui pieces, n/m bins, each containing 1 ui piece, and at least [nM/\M/( y - ;)I 1 bins containing ti pieces. Hence A(L)

2 n + n(1 - l/m)/2 2 (2 +y

Since OPT(L)

+ n/m + [nM/[M/(y

- 3)]1

+ 1/(2m))n.

= n can be arbitrarily

large, we have

R, 2 z + y + 1/(2m).

(2)

RAMANAN ET AL..

320

This inequality arises from the fact that if y or l/m is too large, then when L has no I,-pieces, there will be many bins of type B, containing only an I,-piece, ieading to lot of wasted space. Instance 3. Let ui = $ + FE/~, ui = y + ME/~, and t, = ($ - y)/ M - E. Clearly, ui E Zr, ui E Z2, and ti E I,. Now consider the packing produced by algorithm A. This packing consists of n bins, each containing 1 ui piece, at least n/2 bins containing ui pieces, and at least [nM/[ M/( i - y )] 1 bins containing

ti pieces.

Hence A(L)

2 n + n/2 + [nM//M/(~

Since OF’T( L) = n can be abitrarily

-y)jl

2 (2 -y)n.

large, we have

R,22-y.

(3)

This inequality arises from the fact that pieces of size y + E are classified as I,-pieces, and packed exclusively in bins of type &; if y is too small, this will lead to lot of wasted space in bins of type B,. Adding (l), (2), and (3) we have 3R, 2 29/6, or R, 2 3/2 + l/9. 0 Note that for R, = 3/2 + l/9, the inequalities (l), (2), and (3) are satisfied by equality, if we let y = &, and m = 9. For our algorithm analyzed in Section 3, we let m2 = 9. But we let y = $$, slightly less than &. This is because the weights of the I,-pieces, 6 I p I k, were larger than their sizes, and their weights for cu= 0 were larger than their weights for 01 > 0. By choosing a suitable value for y close to &, we obtained R, < : + t + &, which is close to the lower bound result of the above theorem.

5. FURTHER IMPROVEMENTS

In this section, we first show how to successively construct classes of improved algorithms with performance ratio less than $ + $, by dividing (i, l] and (:, +] into more than two parts. For any algorithm in any of these classes, the performance ratio is at least $ + h = 1.583*. As an example of the improvement, we present a linear-time on-line algorithm with performance ratio less than 1.612.. . . We also present an approach to construct linear-time on-line algorithms with better performance ratios. We believe that this approach would lead to an algorithm with performance ratio less than 1.59.

ON-LINE

BIN

PACKING

321

For any h 2 1, consider the class C@) of algorithms which behave as follows. If A E C(l), then A divides the interval (0, l] into disjoint subintervals, including Zi = (1 - y,, 11, Zi, j = (1 - yj+i, 1 - yj], 1 I j I h, Z* = (y,,, l/2], I*, j = (yhpj, yhpj+i], 1
322

RAMANAN

MODIFIED

HARMONIC-2

ET AL.

ALGORITHM

for i := 1 to n do casep,

Zj (j

in

‘1: pack p, in an empty bin of type 3, I, : harmonic pack( pi, i2 ) = 4, 5): harmonic pack( p,, I,) Zk: pack pi in bins of type Bk by Next-Fit I,, t : if there exists a nonempty bin of type B, then pack pi in any such bin, and change the bin’s type to Bl,l else pack pi in an empty bin of type B,,, 1r.s: if there exists a nonempty bin of type B,,, that does not contain an Zl,,-ptece then pack pi in any such bin else if there exists a nonempty bin of type B, then pack pi in any such bin, and change the bin’s type to B,,, else pack pi in an empty bin of type BIT, I,.,: ifp, is the (nrs,tr)th I,,,-piece to arrive thus far for some integer r 2 1 then if there exists a bin of type B,,, containing only an I,,,-piece then pack p, in any such bin else pack pi in an empty bin of type B,,, else harmonic

I,.,: ifp,

I,: ifp,

pack(

pi, I+ 1)

is the (m,,,r)th I,,,-prece to arrive thus far for some integer r > 1 then if for some j = 1,2, there exists a bin of type B,, , containing only an Il. j-piece then pack pi in any such bin else pack p, in an empty bin of type B, else harmonic pack( p, , Z2. 2) is the (m,r)tb Is-piece to arrive thus far for some integer r >_ 1 then if for some j = 1,2, there exists a bin of type B,, , containing only

an

I,, j-piece then pack p, in any such bin else pack pi in an empty bin of type Bl else harmonic i, (6 5 p I k -

pack(

p, , I,)

1): ifp, is the (m,r)th I,-piece to arrive thus far for some integer r 2 1 then if there exists a bin of type B,, B,, r, or B,, s, containing at least one, and at most 1pyt ] - 1 I,-pieces then pack pi in that bin e/se if for some j = 1,2, there exists a bin of type B,, , containing only an I,, j-piece then pack p, in any such bin else pack pi in an empty bin of type Bl else harmonic

pack ( p, , I,)

end.

We have the following Oh).

bound on the performance

of any algorithm

THEOREM 3. For any integer h 2 1, and any algorithm R, 2 ; + 2h/6(2h+1 - 1).

in

A E Cch),

ON-LINE

BIN

323

PACKING

Proof. As in the proof of Theorem 2, we shall exhibit 2h + 1 kinds of lists L with arbitrarily large OFT(L), and show that maxL A( L)/OPT( L) for these kinds of lists is at least $ + 2k/6(2h+1 - 1). Each of these kinds of lists will be of the form L = L,L,L3, where L, = (u,, Q,. . . , un), L, = (u1, u2, * * *, u,,), and L, = (h, f,, . . . , tM,,). Moreover, we will always have ui + ui + Mti = 1. Hence, the packing in which each bin contains a ui piece, a ui piece, and M tj pieces is an optimal packing, and so OFT(L) = n. For each j, 1 I j < h, consider the list L where ui = : + ME/~, ui = yhej + M&/2, and ti = ($ - yhwj)/M - E, where E and M are chosen such - yhej)] ti pieces that ui E Ir,h, ui E 12,j, ti E IA, and exactly [M/(1/2 can be packed in a bin. Considering A( L)/OFT( L) for each of these lists, we have that (since OpT( L) = n can be arbitrarily large) R, 2 2 -

yh-j

-

1/(2m,,j). (4)

For each j, 1 I j I h, consider the list L where ui = 1 - yh-j+ 1 + ui = y,,-, + ME/~, and ti = (yhej+r - y&i)/M - E, where E and M are chosen such that ui E Ir,h-j, ui E I,, j, ti E I,, and exactly t i pieces can be packed in a bin. Considering lM/(Yh-j+l - Yh-j)] A( L)/OFT( L) for each of these lists, we have that (since OFT(L) = n can be arbitrarily large) ME/~,

R, 2 312

+

Y/z-j+1

-

Yh-j

+

1/(2m2,

j).

(5)

Consider the list L where ui = : + ME/~, ui = y,, + ME/~, and ti = ($ - y,)/M - E, where E and M are chosen such that ui E II,h, ui E j,, ti E IA, and exactly 1M/( f - yh)] ti pieces can be packed in a bin. As before, we have R, 2 2 - yh.

(6)

Considering the 2h + 1 inequalities in (4), (5), and (6) we see that the lower bound is obtained when equality holds in each of them. This happens when 2h+l

-

2j

6(2h+’ - 1)

for 1 I j I h. Substituting

and

m,,j=

6(2h+1 - 1) 2h+l

_

2h-j+l

for y, in (6) we get the lower bound R,>;+

2h 6(2h+’

- 1).

RAMANAN

324 COROLLARY

R, > : + &=

ET AL.

3.1. For any integer h 2 1, and any algorithm 1.583*.

For R, = $ + 2h/6(2h+’ - l), the inequalities satisfied by equality, if we let 1 &=2-

2h+l - 2.i

and

6(2h+’ - 1)

A E Cth),

(4), (5), and (6) are 6(2h+1 - 1)

m2,j=

2hil

_

2h-j-i-1

.

So, we can improve upon the algorithm presented in Section 2. The improvement is based on the following partition of the interval (0, 11: (0, l] = ii 6 Ii,j j-l

u 12 fi 12, 6 Ii, j

j=l

i=3

where f, = (1 - yi, 11, Ii, j = (1 - yj+r, 1 - yj], 1 I j I h, 12 = (yh, l/2], IL?, j =(Yh-jy

Ii =(l/(i

+ 1),1/i],

Yh-jtl],

3
l
I,c = (&l/k],

for some h > 1, y,, = : < yi < yz -C . *. < y, < yh+i = $, and k 2 7. All pieces with size in the interval (i, l] are packed in bins of type B,. All other subintervals have their corresponding bin types. In addition, a fixed fraction l/m,, j of the I,, /pieces are packed in bins of type B,, one piece per bin. A bin of type B, containing an Iz, j-piece can also contain an Ii, i-piece for any i > h - j. Note that since we are trying to obtain a performance ratio less than 1.6, a fixed fraction of the &pieces and a fixed fraction of the Is-pieces should also be packed in bins of type B,. For each p, 3 I p I k - 2, a fixed fraction l/m, of the I,-pieces are packed in bins of type B,. For 3 I p I 5, a bin of type B, containing an $-piece can also contain a piece with size in the interval (i, 1 - l/p]. For 6 2 p I k - 2, we can take mP = (k - l)( p + l)/( k - p - l), and pack 1pyt ] of the I,-pieces in a bin of type B,. Such a bin can also contain a piece with size in the interval (4, 1 - yr]. The analysis of the algorithm is tedious because we need to consider h + 4 weighting functions. We believe that by taking suitably large values for h and k, and appropriate values for the yjs and mjs, we can obtain a linear-time on-line algorithm with performance ratio less than 1.59. 6. CONCLUSIONS We presented a new linear-time on-line algorithm, the Modified Harmonic Algorithm, which has an asymptotic performance ratio less than

ON-LINE

BIN PACKING

325

1.(615)*. We showed that for a large class of linear-time on-line algorithms including the Modified Harmonic Algorithm, the performance ratio is at least i + + = 1.61*. Then we showed how to successively construct classes of improved linear-time on-line algorithms. For any algorithm in any of these classes, the performance ratio is at least : + & = 1.583*. We presented an improved algorithm with performance ratio 1.612.. . , and presented an approach to construct linear-time on-line algorithms with better performance ratios. Finally, we observe that our algorithms lead to improved linear-time on-line algorithms for 2dimensional bin packing. For packing rectangles in a strip, we can modify the shelf algorithm of Baker and Schwarz [BS83]. The shelf algorithm takes a parameter r, 0 < r < 1. Pieces with height h such that r k+ ’ c h I rk, for some k 2 0, are packed in shelves of height rk. The widths of the pieces determine their packing in shelves of appropriate height. Any l-dimensional on-line algorithm can be used to pack the pieces in the shelves. Baker and Schwarz studied the O(n) Next-Fit, and the O(n log n) First-Fit shelf algorithms (which use Next-Fit and First-Fit, respectively, to pack the pieces in the shelves), and showed that they have performance ratios 2/r and 1.7/r, respectively. Hence their performance ratios can be made close to that of the corresponding l-dimensional algorithm by taking r to be arbitrarily close to one. Let x be the l-dimensional algorithm with the least performance ratio R,- that we can obtain using the ideas described in Section 5. This algorithm could be used for packing the pieces in the shelves. This leads to a O(n) shelf algorithm with performance ratio R,-/r that can be made close to R,- by taking r to be arbitrarily close to one.

REFERENCES [BS83] [B79a] [B79b] [CGJ84]

[GJ79] iJ731

B. S. BAKER AND J. S. SCHWARZ,Shelf algorithms for twodimensional packing problems, SIAMJ. Compur. 12 (1983), 508-525. D. J. BROWN, “A Lower Bound for On-line One-dimensional Bin Packing Algorithms,” Technical Report R-864, Coordinated Science Laboratory, University of Ilhnois, Urbana, IL, 1979. D. J. BROWN, draft, 1980. E. G. COFFMAN, JR., M. R. GAREY, AND D. S. JOHNSON, Approximation algorithms for bin packing-An updated survey, in “Algorithm Design for Computer System Design” (G. Ausiello, M. Lucertini, and P. Serafini, Eds.), Springer-Verlag, New York, 1984. M. R. GAREY AND D. S. JOHNSON, “Computers and Intractability: A Guide to the Theory of NP-Completeness,” Freeman, San Francisco, 1979. D. S. JOHNSON, “Near-optimal Bin Packing Algorithms,” Technical Report MAC TR-109, Project MAC, Massachusetts Institute of Technology, Cambridge, MA, 1973.

326

RAMANAN

ET AL.

D. S. JOHNSON, Fast algorithms for bin packing, J. Comput. System Sci. 8 (1974), 272-314. [.IDUGG74] D. S. JOHNSON,A. DEMERS,J. D. ULLMAN, M. R. GAREY, AND R. L. GRAHAM, Worst-case performance bounds for simple one-dimensional packing algorithms, SIAM J. Comput. 3 (1974), 299-325. R. M. KARP, Reducibility among combinatorial problems, in “Complexity of w721 Computer Computations” (R. E. Miller and J. W. Thatcher, Eds.), pp. 85-103, Plenum, New York, 1972. [KK82] N. KARMARKAR AND R. M. KARP, An efficient approximation scheme for the one-dimensional bin packing problem, in “Proceedings, 23rd Armu. Symp. on Foundations of Computer Science, Nov. 1982, pp. 312-320, IEEE Computer SW., New York, 1982. [LL83] C. C. LEE AND D. T. LEE, “A New Algorithm for On-line Bin Packing,” Technical Report 83-03-FC-02, Department of Electrical Engineering and Computer Science, Northwestern University, Evanston, IL, 1983. [LL85] C. C. LEE AND D. T. LEE, A simple on-line packing algorithm, J. Assoc. Comput. Mach.32(1985), 562-572. F. M. LIANG, A lower bound for on-line bin packing, Inform. Process. L&t. 10 v-801 (1980), 76-79. [BR84] D. J. BROWN AND P. RAMANAN, On-line bin-packing in linear time, in “Proceedings 1984 Conf. on Information Sciences and Systems,” Princeton University, Princeton, NJ, March 1984, pp. 328-332. A. C. YAO, New algorithms for bin packing, J. Assoc. Comput. Much. 27 (1980), VW 207-227. v741