0% found this document useful (0 votes)
29 views7 pages

Bin Packing Can Be Solved Within in Linear Time

1) The document presents a theorem showing that bin packing can be solved within 1+e for any positive e in linear time. 2) It describes reducing the general bin packing problem to a restricted version where the number of distinct item values and minimum value are bounded, reducing the number of possible bin types. 3) For the restricted problem, it formulates it as a linear program with a bounded number of variables and constraints, which can be solved in time independent of the input size to give a packing within a constant of optimal.

Uploaded by

FRANCISCO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views7 pages

Bin Packing Can Be Solved Within in Linear Time

1) The document presents a theorem showing that bin packing can be solved within 1+e for any positive e in linear time. 2) It describes reducing the general bin packing problem to a restricted version where the number of distinct item values and minimum value are bounded, reducing the number of possible bin types. 3) For the restricted problem, it formulates it as a linear program with a bounded number of variables and constraints, which can be solved in time independent of the input size to give a packing within a constant of optimal.

Uploaded by

FRANCISCO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

COMBINArORICA1(4) (1981) 349--355

BIN PACKING CAN BE SOLVED WITHIN 1+5


IN LINEAR TIME

W, F E R N A N D E Z de la V E G A
c. N. R, S., 54 Bd. Raspail
Paris 75 006, France*
and
G. S. L U E K E R * *
Dept. Info. Comp. Sci., Univ. of California
Irvine, CA 92 717 U.S.A.
Received 22 May 1981

For any list L of n numbers in (0, 1] let L* denote the minimum number of unit capacity
bins needed to pack the elements of L. We prove that, for every positive e, there exists an O(n)-time
algorithm S such that, if S(L) denotes the number of bins used by S for L, then S(L)/L*~_I+e
for any L provided L* is sufficiently large.

1. Introduction

In the bin-packing problem, we are given a list L of real numbers between


0 and 1 which we wish to assign to unit capacity bins in such a way that no bin
receives numbers totalling more t h a n ' l and a minimum number of bins is used.
Let us denote this minimm'n by L*. For any (heuristic) bin-packing algorithm S,
let S(L) denote the number of bins used for the input list L and Rs(k) the maximum
ratio S(L)/L* for any list with L*=k. The asymptotic performance ratio of S,
denoted by R~', is defined as 1-~ Rs(k). The problem of finding an optimal packing
k~
can involve the solution of the NP-complete partition problem [8] (see also [3,
p. 226]) and hence is likely to be computationally intractable. Many papers have
been devoted to the study of heuristic algorithms with guaranteed bounds on
performance [4, 5, 6, ll]. For a long time the best polynomial algorithm was the
so-called First-Fit-Decreasing algorithm which has asymptotic performance ratio
11/9. Only quite recently an improved algorithm was found by A. C. Yao [11].
Even more recently, Garey and Johnson [4] have announced their "Modified First-
Fit-Decreasing" algorithm which is stated to have performance ratio -~ 71/60. A.
C. Yao asks if there exists a limit to the best asymptotic performance ratio for a
polynomial algorithm. In this paper we answer this question in the negative,
showing that, for every positive e, there is a linear time algorithm S for which
R ~ _ l + e . We also obtain a linear time algorithm for a generalization of bin-
packing, namely the d-dimensional bin-packing problem of [2], again for every e,
with asymptotic performance ratio <=d+e. The best algorithm described in [2]

* Mailing address: 4 bis rue Wulfran Puget, Marseille 13 008, France


** The work of this author was supported by NSF Grant MCS 79---04997.
AMS subject classification (1980): 68 C 25; 68 E 05, 90 C 10
350 W. F E R N A N D E Z D E LA VEGA, G . S . L U E K E R

for this problem, which is a generalization of the First-Fit-Decreasing algorithm,


has guaranteed performance ratio d+(1/3) for every input. Hence, choosing
sufficiently small e, our algorithm brings an improvement for large inputs. We refer
to ([l 1], theorem 7) for a result, too long to be stated here, concerning lower bounds
for the complexity in a particular model of computation of obtaining any perfor-
mance ratio better than d.

2. Terminology

Besides the usual format of the data in a bin-packing problem which is assumed
to be presented as a list L = x l x 2 . . . x n of numbers in (0, I] (we shall represent
lists as words in the one dimensional case since we use concatenation), we shall
use also the notion of a multiset in which some elements may appear more than
once. For instance, to a list L whose elements achieve m distinct values Yl . . . . , ym,
we shall associate the multiset M z denoted as in [9]
M r = {nl" Yl . . . . , n~. ym},
with the meaning that, for each i, ni denotes the number of terms of L equal to Yi.
We shall say that n~ is the multiplicity of yl in ML.
For any list L we denote its length by IL[. We denote by V(L) the sum of
the elements of L.
Let X be a bin used in a packing. By the type of X we shall mean the multi-
set of numbers which are assigned to X. For a given packing problem, determined
by a list L whose elements take m distinct values y~<y2< ... <Ym, we can represent
m
the types by vectors in N m, the vector T = ( t l , ..., t,,) with ~ hy~<=1, representing
t=1
the type of a bin which contains, for each i, exactly h numbers equal to y~. We
shall say that the type T is saturated if we have y~+ ~ h y i > 1.
,=1
We note that to each packing of a list L there corresponds in an obvious way a
multiset of types of bins. I f ~ ' is a multiset of types of bins corresponding to a pack-
ing of L and M = M ~ . is the multiset of numbers corresponding to L, we shall say,
with a slight abuse of language, that J [ is a packing of M.

3. The main theorem

Theorem 1. For any positive e there is a bin-packing algorithm S with asymptotic


performance ratio R~<= 1 +e, working in thne C , + C n log (l/e), where C~ depends
only on e and C is an absolute constant.
The essential idea of the proof is to reduce (in linear time) bin-packing within
1 + e to a restricted problem in which the number of distinct values of the numbers
to be packed is bounded and moreover these values are bounded from below. Hence
the number of possible types of bins is bounded. We describe a nearly optimal
algorithm for the restricted problem in section 3.1 and perform the reduction
in section 3.2.
BIN PACKING WITHIN 1 +e 351

3.1. A restricted version of bin-packing.


For ~C(0, 1] and any positive integer m, let RBP (q, m) denote the following
problem.
I N P U T : A multiset M = { n l . x x .... , nm.x,~ } with values x~, ..., x,, in [r/, 1].
m
We define the size of the input to be n = Z n~.
i=1
O U T P U T : A multiset of types of bins corresponding to an optimal packing
of M.
Let M* denote the cardinality of this multiset (taking into account the multi-
plicities). Hence M * = L * where L is any list for which M L = M . We observe
that given such a multiset, it is trivial to define a packing of any such list L using
a set of bins with types given by this rnultiset and that this can be done in linear time.
We shall say that an algorithm solves RBP (r/, m) within an additive con-
stant C if, when applied to any admissible input M, it finds a multiset of types of
bins corresponding to a packing of M and with cardinality not exceeding M * ÷ C .
We shall now prove the following
Fact. For any given q and m, RBP (q, m) can be solved within an additive constant
in time independent of n.
Proof. Let t/ and m be given. We note first that, for any admissible input M for
RBP (q, m), the number of possible types of bins is bounded by a function z(t/, m).
In fact, setting wo can take

which is the number of ways one can choose m + 1 nonnegative integers which
add to k. (The first m numbers are item counts and the last one is for padding
the sum out to k.)
Let q=q(M)<=z(q, m) denote the actual number of types. Let these types
be arranged in some order and let T~=(t~ .... , t,~) denote the vector representing
the ith type. Consider the following linear integer program, to which we shall refer
as program P1.
q
Minimize ~ ai
i=1

subject to
q
(1) ~ a ~ t j i >. .n j . j. =. 1. m
i=l
and
ai -~0 i : 1, ..., q.
From a solution of this program, we can, by deflating perhaps some types, obtain
a solution (a[' ..... a~) for which the constraints (1) become equalities. Hence
converting the constraints into equalities does not change the value of the program
(it certainly can't increase it) and (a~'..... a~) defines in an obvious way an optimal
multiset of types. Now if (~1 .... , c~q) is a solution of the ordinary linear program
352 W. F E R N A N D E Z D E LA V E G A , G . S . L U E K E R

P2 corresponding to P1 then (:~[..... c~;), where c d = F ~ - l , i = 1 . . . . . q, satisfies


the constraints of P1. F r o m the nmltiset defined by (el, ..., ~q) we can again obtain,
by deflating perhaps some types, a multiset of types {a~*- 1"1, ..., a'~*. Tq} corre-
sponding to a packing of M and we have
q q q q
Z a** <= Xc~" <= Zc~i+q <- Xa~[+q.
i=1 i=1 i=1 i=1

The inequality between the first and last expressions means that the multiset of
types {a~*- 7'1, ..., a~*- Tq} solves RBP (q, m) on the instance M within the addi-
tive constant* q. To find (a~*, ..., a~*) amounts essentially to solving the ordinary
linear program P2.
Since both the number of variables and the number of constraints of P2
have bounds depending only on r/ and m, this can be done in time depending only
on these parameters. II
3.2. Converting bin-packing within 1+ e into restricted bin-packing.
Let e > 0 be given and let ~ = e / ( e + 2 ) denote the root of (1 + e a ) ( 1 - ~ l ) - ~ =
= 1 +e. We set m=Fefz-J. Let L=x~ ... x, be the list to be packed and let l denote
the number of x~'s smaller than e~. We define h by n - l = m h + r , r<=m-1, and
suppose first h > 0 . Let L,=KoY~K~...ymKmR be anylist obtained by rearranging
L in such a way that:
(i) 32o contains the l terms <51,
(ii) IKII=IK21. . . . . I K m [ = h - 1,
(iii) for i = 1 , ..., m - 1 each term x in K~ satisfies yi~x<=y~+~,
(iv) each term x in KmR satisfies x>=ym.
These conditions amount exactly to saying that, if L ' is the list obtained by sorting
L in non-decreasing order, then yi is the term of rank l + ( i - 1 ) h + l in L ' and,
writing L'=YoytY~...y,,Y~, that the sub-lists Ko, K~ ..... K,,R are arbitrary
rearrangements of Y0, II1, ..., Y,, respectively. Hence to find a list L~ fulfilling
the forementioned conditions amounts essentially to finding the y~'s.
Using the fact that the "selection problem" which consists in finding the
kth largest term of a list of length l can be solved in time O(l) [1], it can be shown
that all the yi's can be found in time O(n log~ m), hence in time Cn log (I/z) where
C is an absolute constant.
We require now the following definition. For any two lists of same length
L=x~...x, and K = y , . . . y , we shall say that L d o m i n a t e s K a n d write L ~ - K or
K.<L if we have a~=>y~, i = 1 , ..., n. It is clear that L>-.K implies L*>=K*.
Consider the lists L~=Koy~...y~R and L3-- -- KoY2...y,,,
h h lhR. Clearly we
have IL2]= lL31=n and Lz..<Lt-.<L3. Since from a packing of L3 we can get imme-
diately a packing of L~ (hence a packing of L) using the same number of bins, if
we show on one hand that we can indeed obtain in linear time a packing of L3 using
no more than (I-~;1)-IL~-b-C bins and, on the other hand, that the inequality
= L z ( l + a ~ ) holds, then it follows that our packing of L uses less than

* D. J o h n s o n pointed out to us that we can replace here q by m since P2 will always have
a solution with at m o s t m n o n - z e r o e~'s.
BIN PACKING WITHIN l+e 353

(1 +el)(1 --eO-IL~+C<-(I + e ) L * + C which is asymptotic to (1 + e ) L * by the defi-


nition of ~t and the trivial inequality L~ =<L*, and we shall be done.
N o w the lists L2 and La, thought of as multisets, differ only in that, in going
from L2 to L 3, we change h terms equal to )'1 into as many terms equal to 1. Hence,
given a packing of L 2, we can get in an obvious way a packing of La using no more
h
than h additional bins. This implies L 3* = < L z*+ h and, since L~>-mhe~>=- , we
get L~<=L[(I + e 0 which was the second assertion to be proved.
To prove the first put Q=y~...y],l h so that La=KoQR. We begin
by putting each element of R in a bin using [Rl_<-ei-~ bins. Next, our RBP algo-
rithm with parameters r/and m, applied to the multiset MQ, will find in time _<-C,
(since q and m depend only on e) a multiset of types of bins of total cardinality
<=Q*+z(q, m) into which we can pack Q in linear time. Moreover, there is room
left in these bins for any multiset of numbers each <e~ whose sum does not exceed
the quantity S = Q * ( 1 - e O - V ( Q ) . Now we argue according to the relative values
of S and of the sum V(Ko) of the elements which remain to be packed.
If V(Ko) <=S, no extra bin is needed. In this case we have obtained a packing
of La in at most Q*+z(q, m)+ef2<=L]+C bins, with C=r(r/, m ) + e i -~.
If V(K0)> S, then we first fill up the bins used for Q with elements of K0
totalling at least S and we are left with elements totalling at most V(Ko)- S which
can be packed in no more than ( V ( K o ) - S ) ( 1 - e 0 -~ extra bins. In this case the
total number of bins used is at most
Q* + C + ( V ( K o ) - S ) ( I - ~ 0 -~ = (V(Ko)+V(Q))(1-el)-1+ C ~ L ~ ( 1 - t ~ ) - ~ + C
using the trivial inequality L~ >-V (Ko) + V (Q).
Hence in both cases we found, as desired, a packing of L3 using at most
L ~ ( 1 - ~ a ) - I + C bins. In the case h = 0 that we have left aside, the list L has at
most m - 1 terms greater than e~ and packs trivially in no more than
m + V ( L ) ( 1 - e l ) -1 ~ L*(1 +~)
bins for sufficiently large L*. This concludes the reduction and the proof of Theo-
rem 1. ]

4. An application to the d-dimensional case

In the generalized bin-packing problem discussed in [2] and [11], L = (xl . . . . , 2 , )


is a list of d-dimensional vectors (d_-> I), with each component of the vectors in the
interval (0, 1]. It is required to pack these vectors into a minimum number of bins,
which we again denote by L*, in such a way that the sum ~ of vectors in any bin
has each component v~_<-l. We have not succeeded in extending our p r o o f for
the one dimensional case to any higher dimension. A basic obstruction comes
here from the fact that there is no natural order defined on [0, 1]d for any d > 1.
We can only obtain, by a rather direct use of our one dimensional algorithm, the
following result
Theorem 2. For any ~>0 there is a linear time algorithm which solves the generalized
d-dimensional bin-packing problem within d + ~.
354 w . F E R N A N D E Z D E L A VEGA, G. S. L U E K E R

Proof. Let J~ denote the set of indexes of the vectors in L for each of which the
largest component is the ith one (in case of ties, an arbitrary choice is made within
the set of indexes of the largest components of the considered vector). Let L~ denote
the list of the values of the ith component of the vectors with indexes in J~. Clearly
a packing of L i defines a generalized packing of these vectors. Now, for any flied
e, we can, using our one dimensional packing algorithm, pack L~ within 1 + e in
d
linear time. Hence we can pack L in a number of bins not greater than (1 -I-e) ~ L*
i=1
also in linear time. On the other hand the vectors with indexes in J~ do not pack
in less than L* bins and this implies
d
L* _-> max {L~ ..... L~} => d -~ ~ ' L~.
i=i

Hence our packing achieves an accuracy ratio _-<(1 +e)d<=d+e"which is what we


wanted. I

5. Concluding remarks

We list some problems for future research.


(1) We have not given any evaluation for the constant C~ in the expression
of the time required by our algorithm but we remark that it is certainly huge. The
numberoftypescanexceed[kn) withk=L1/ellandm=I-ef~7 so that C, cannot
be bounded by a polynomial in I/e. We ask: does there exist a family (S~) of bin-
packing algorithms indexed by the parameter e, such that R~_-__1 + e and the time
complexity of S, is bounded by a polynomial function of the two variables n and l/e?
(2) Does there exist an O(n)-time bin-packing algorithm S with R ~ ' = I ?
(3) Turning now to lower bounds for the best achievable accuracy, it is
not known, as pointed out in [3], if there exists a polynomial time algorithm S with
]S(L)-L*I bounded by a constant independent of L*. Of course a negative answer
to this question can only be conditional on P ~ N P .
(4) What is the best possibIe asymptotic performance ratio for a polynomial
algorithm tort he d-dimensional case? A more modest question is: can we improve
at all over R ~ ' = d in polynomial time? Let's mention that it is not possible to
improve over the ratio d in linear time using the computational model of Yao (see
[11, theorem 7]).
Acknowledgement. We are pleased to express our thanks to Jean Francois Maurras
for valuable information concerning linear programming algorithms.
Note added in proof. It is worth noting that a number of pieces of our analysis
have been employed in earlier papers, though it does not seem to have been noticed
earlier that a bound of the type obtained here was possible. For example, in [14]
the method of bucketing items according to some measure of size, and treating
small items specially, was used to obtain approximations for the knapsack problem ;
see [3, 16] for a survey of methods for approximation algorithms. In [17] a method
of attempting to make buckets have about the same number of items by using
BIN PACK[NGWITHIN 1+e 355

s a m p l i n g was used in a sorting algorithm with good expected behavior; see [12]
for a survey of algorithms with good expected behavior. [13, 15] considered the
application o f linear p r o g r a m m i n g to bin packing in a m a n n e r similar to that
employed here; [13] observes that a linear p r o g r a m m i n g solution.
We are very grateful to D a v i d J o h n s o n for b r i n g i n g some of the earlier
research to our a t t e n t i o n , a n d for also m a k i n g other helpful r e m a r k s on a n early
manuscript.

References
[1] M. BLUM,R. W. Ft.OVD, V. PRATT, R. L. RIVESTand R. E. TARJAN, Time bounds for selec-
tion, J. Comput. Sys. Sci., 7 (1973), 4 4 8 4 6 1 .
[2] M. R. GAREY, R. L. GRAHAM,D. S. JOHNSON and A. C. YAO, Multiprocessor scheduling
as generalized bin-packing, J. Combinatorial Theory A 21 (1976), 257--298.
[3] M. R. GAREY and D. S. JOHNSON, Computers and Intractability, Freeman, San Francisco,
1979.
[4] M. R. GAREYand D. S. JOHNSON, Approximation algorithms for bin packing problems: a
survey, preprint 1980.
[5] D. S. JOHNSON,.Near optimal bh7 packing algorithms, Ph.D. Th., HIT, Cambridge, Mass., June
1973.
[6] D. S. JOHNSON, Fast algorithms for bin packing, J. Comptr. Syst. Sci. 8 (1974), 272--314.
[7] D. S. JOHNSON, A. DEMERS, J. D. UI-LMAN,M. R. GAREY and R. L. GRAHAM, Worst case
bounds for simple one-dimensional packing algorithms, SIAM J. Comptg. 3 (1974), 299--
325.
[8] R. M. KARl:', Reducibility among combinatorial problems, in: Complexity of Computer calcula-
tions. (R+ E+ MilIer and J. W. Thatcher, Eds.) Plenum Press, New York, 1972, 85--103.
[9] D. E. KNUTH, The Art of Computer Progratnmb~g, Vol. 3, Sorting and Searching, Addison-
Wesley, Reading, Mass., I973.
[10] A. SCHONHAQE,M. S. PATERSONand N. PIPPENGER, Finding the median, J. Cornput. Sys.
Sci. 13 (1976), 184--199.
[11] A. C. Yao, New algorithms for bin packing. J. A C M 27, 2 (Apr. 1980).
[12] J. L. BENTLEY, Probabilistic analysis of algorithms, Applied Probabilit)~Computer Science,
the hTterface, Boca Raton, Florida, January 1981.
[13] P. C. GILMORE and R. E. Go~,tORY, A linear programming approach to the cutting-stock
problem, Operations Research 9 (1961), 849--859.
[14] O. H. IBARRAand C. E. KIM, Fast approximation aleorithms for the knapsack and sum of
subset problems, Journal of the A C M 22 (1975), 463--468.
[15] L. V. KANTOROWCH,Mathematical methods of organizing and planning production, Manage-
ment Science 6, 4 (July 1960), 366--422.
[16] S. SAHNI, General techniques for combinatorial approximation, Operatiotls Research 25, 6
(1977). 920--936.
[17] B. W. WEIBE, Statistical Methods in Algorithm Design and Analysis, Ph.D. Thesis, Carnegie-
Mellon University, Pittsburgh, Pennsylvania (August 1978); appeared as CMU Computer
Science Report CMU--CS--78--142.

You might also like