Thebin packing problem[1][2][3][4] is anoptimization problem, in which items of different sizes must be packed into a finite number of bins or containers, each of a fixed given capacity, in a way that minimizes the number of bins used. The problem has many applications, such as filling up containers, loading trucks with weight capacity constraints, creating filebackups in media, splitting a network prefix into multiple subnets,[5] and technology mapping inFPGAsemiconductor chip design.
Computationally, the problem isNP-hard, and the correspondingdecision problem, deciding if items can fit into a specified number of bins, isNP-complete. Despite its worst-case hardness, optimal solutions to very large instances of the problem can be produced with sophisticated algorithms. In addition, manyapproximation algorithms exist. For example, thefirst fit algorithm provides a fast but often non-optimal solution, involving placing each item into the first bin in which it will fit. It requiresΘ(n log n) time, wheren is the number of items to be packed. The algorithm can be made much more effective by firstsorting the list of items into decreasing order (sometimes known as the first-fit decreasing algorithm), although this still does not guarantee an optimal solution and for longer lists may increase the running time of the algorithm. It is known, however, that there always exists at least one ordering of items that allows first-fit to produce an optimal solution.[6]
There are manyvariations of this problem, such as 2D packing, linear packing, packing by weight, packing by cost, and so on. The bin packing problem can also be seen as a special case of thecutting stock problem. When the number of bins is restricted to 1 and each item is characterized by both a volume and a value, the problem of maximizing the value of items that can fit in the bin is known as theknapsack problem.
A variant of bin packing that occurs in practice is when items can share space when packed into a bin. Specifically, a set of items could occupy less space when packed together than the sum of their individual sizes. This variant is known as VM packing[7] since whenvirtual machines (VMs) are packed in a server, their totalmemory requirement could decrease due topages shared by the VMs that need only be stored once. If items can share space in arbitrary ways, the bin packing problem is hard to even approximate. However, if space sharing fits into a hierarchy, as is the case with memory sharing in virtual machines, the bin packing problem can be efficiently approximated.
Another variant of bin packing of interest in practice is the so-calledonline bin packing. Here the items of different volume are supposed to arrive sequentially, and the decision maker has to decide whether to select and pack the currently observed item, or else to let it pass. Each decision is without recall. In contrast, offline bin packing allows rearranging the items in the hope of achieving a better packing once additional items arrive. This of course requires additional storage for holding the items to be rearranged.
InComputers and Intractability[8]: 226 Garey and Johnson list the bin packing problem under the reference [SR1]. They define its decision variant as follows.
Instance: Finite set of items, a size for each, a positive integer bin capacity, and a positive integer.
Question: Is there a partition of intodisjoint sets such that the sum of the sizes of the items in each is or less?
Note that in the literature often an alternate, but not equivalent, notation is used, where and for each. Furthermore, research is mostly interested in the optimization variant, which asks for the smallest possible value of. A solution isoptimal if it has minimal. The-value for an optimal solution for a set of items is denoted by or just if the set of items is clear from the context.
Furthermore, there can be noapproximation algorithm with absolute approximation ratio smaller than unless. This can be proven by a reduction from thepartition problem:[10] given an instance of Partition where the sum of all input numbers is, construct an instance of bin-packing in which the bin size isT. If there exists an equal partition of the inputs, then the optimal packing needs 2 bins; therefore, every algorithm with an approximation ratio smaller than3/2 must return less than 3 bins, which must be 2 bins. In contrast, if there is no equal partition of the inputs, then the optimal packing needs at least 3 bins.
On the other hand, bin packing is solvable inpseudo-polynomial time for any fixed number of binsK, and solvable in polynomial time for any fixed bin capacityB.[8]
To measure the performance of an approximation algorithm there are two approximation ratios considered in the literature. For a given list of items the number denotes the number of bins used when algorithm is applied to list, while denotes the optimum number for this list. The absolute worst-case performance ratio for an algorithm is defined as
On the other hand, the asymptotic worst-case ratio is defined as
Equivalently, is the smallest number such that there exists some constantK, such that for all listsL:[4]
.
Additionally, one can restrict the lists to those for which all items have a size of at most. For such lists, the bounded size performance ratios are denoted as and.
Approximation algorithms for bin packing can be classified into two categories:
Online heuristics, that consider the items in a given order and place them one by one inside the bins. These heuristics are also applicable to the offline version of this problem.
Offline heuristics, that modify the given list of items e.g. by sorting the items by size. These algorithms are no longer applicable to the online variant of this problem. However, they have an improved approximation guarantee while maintaining the advantage of their small time-complexity. A sub-category of offline heuristics is asymptotic approximation schemes. These algorithms have an approximation guarantee of the form for some constant that may depend on. For an arbitrarily large these algorithms get arbitrarily close to. However, this comes at the cost of a (drastically) increasedtime complexity compared to the heuristical approaches.
In theonline version of the bin packing problem, the items arrive one after another and the (irreversible) decision where to place an item has to be made before knowing the next item or even if there will be another one. A diverse set of offline and online heuristics for bin-packing have been studied byDavid S. Johnson on his Ph.D. thesis.[11]
There are many simple algorithms that use the following general scheme:
For each item in the input list:
If the item fits into one of the currently open bins, then put it in one of these bins;
Otherwise, open a new bin and put the new item in it.
The algorithms differ in the criterion by which they choose the open bin for the new item in step 1 (see the linked pages for more information):
Next Fit(NF) always keeps a single open bin. When the new item does not fit into it, it closes the current bin and opens a new bin. Its advantage is that it is a bounded-space algorithm since it only needs to keep a single open bin in memory. Its disadvantage is that its asymptotic approximation ratio is 2. In particular,, and for each there exists a listL such that and.[11] Its asymptotic approximation ratio can be somewhat improved based on the item sizes: for all and for all. For each algorithmA that is an AnyFit-algorithm it holds that.
Next-k-Fit(NkF) is a variant of Next-Fit, but instead of keeping only one bin open, the algorithm keeps the lastk bins open and chooses the first bin in which the item fits. Therefore, it is called ak-bounded space algorithm.[12] For the NkF delivers results that are improved compared to the results of NF, however, increasingk to constant values larger than2 improves the algorithm no further in its worst-case behavior. If algorithmA is an AlmostAnyFit-algorithm and then.[11]
First-Fit (FF) keeps all bins open, in the order in which they were opened. It attempts to place each new item into thefirst bin in which it fits. Its approximation ratio is, and there is a family of input listsL for which matches this bound.[13]
Best-Fit(BF), too, keeps all bins open, but attempts to place each new item into the bin with themaximum load in which it fits. Its approximation ratio is identical to that of FF, that is:, and there is a family of input listsL for which matches this bound.[14]
Worst-Fit (WF) attempts to place each new item into the bin with theminimum load. It can behave as badly as Next-Fit, and will do so on the worst-case list for that. Furthermore, it holds that. Since WF is an AnyFit-algorithm, there exists an AnyFit-algorithm such that.[11]
Almost Worst-Fit (AWF) attempts to place each new item inside thesecond most empty open bin (or emptiest bin if there are two such bins). If it does not fit, it tries the most empty one. It has an asymptotic worst-case ratio of.[11]
In order to generalize these results, Johnson introduced two classes of online heuristics calledany-fit algorithm andalmost-any-fit algorithm:[4]: 470
In anAnyFit (AF) algorithm, if the current nonempty bins areB1,...,Bj, then the current item will not be packed intoBj+1 unless it does not fit in any ofB1,...,Bj. The FF, WF, BF and AWF algorithms satisfy this condition. Johnson proved that, for any AnyFit algorithm A and any:
.
In anAlmostAnyFit (AAF) algorithm, if the current nonempty bins areB1,...,Bj, and of these bins,Bk is the unique bin with the smallest load, then the current item will not be packed intoBk, unless it does not fit into any of the bins to its left. The FF, BF and AWF algorithms satisfy this condition, but WF does not. Johnson proved that, for any AAF algorithm A and anyα:
Better approximation ratios are possible with heuristics that are not AnyFit. These heuristics usually keep several classes of open bins, devoted to items of different size ranges (see the linked pages for more information):
Refined-first-fit bin packing (RFF) partitions the item sizes into four ranges:,,, and. Similarly, the bins are categorized into four classes. The next item is first assigned to its corresponding class. Inside that class, it is assigned to a bin usingfirst-fit. Note that this algorithm is not an Any-Fit algorithm since it may open a new bin despite the fact that the current item fits inside an open bin. This algorithm was first presented by Andrew Chi-Chih Yao,[15] who proved that it has an approximation guarantee of and presented a family of lists with for.
Harmonic-k partitions the interval of sizes based on aHarmonic progression into pieces for and such that. This algorithm was first described by Lee and Lee.[16] It has a time complexity of and at each step, there are at mostk open bins that can be potentially used to place items, i.e., it is ak-bounded space algorithm. For, its approximation ratio satisfies, and it is asymptotically tight.
Refined-harmonic combines ideas from Harmonic-k with ideas fromRefined-First-Fit. It places the items larger than similar as in Refined-First-Fit, while the smaller items are placed using Harmonic-k. The intuition for this strategy is to reduce the huge waste for bins containing pieces that are just larger than. This algorithm was first described by Lee and Lee.[16] They proved that for it holds that.
Yao[15] proved in 1980 that there can be no online algorithm with an asymptotic competitive ratio smaller than. Brown[17] and Liang[18] improved this bound to1.53635. Afterward, this bound was improved to1.54014 by Vliet.[19] In 2012, this lower bound was again improved by Békési and Galambos[20] to.
In the offline version of bin packing, the algorithm can see all the items before starting to place them into bins. This allows to attain improved approximation ratios.
The simplest technique used by offline approximation schemes is the following:
Ordering the input list by descending size;
Run an online algorithm on the ordered list.
Johnson[11] proved that any AnyFit scheme A that runs on a list ordered by descending size has an asymptotic approximation ratio of
.
Some methods in this family are (see the linked pages for more information):
First-fit-decreasing (FFD) orders the items by descending size, then calls First-Fit. Its approximation ratio is, and this is tight.[23]
Next-fit-decreasing (NFD) orders the items by descending size, then callsNext-Fit. Its approximate ratio is slightly less than 1.7 in the worst case.[24] It has also been analyzed probabilistically.[25] Next-Fit packs a list and its inverse into the same number of bins. Therefore, Next-Fit-Increasing has the same performance as Next-Fit-Decreasing.[26]
Modified first-fit-decreasing (MFFD)[27], improves on FFD for items larger than half a bin by classifying items by size into four size classes large, medium, small, and tiny, corresponding to items with size > 1/2 bin, > 1/3 bin, > 1/6 bin, and smaller items respectively. Its approximation guarantee is.[28]
Fernandez de la Vega and Lueker[29] presented aPTAS for bin packing. For every, their algorithm finds a solution with size at most and runs in time, where denotes a function only dependent on. For this algorithm, they invented the method ofadaptive input rounding: the input numbers are grouped and rounded up to the value of the maximum in each group. This yields an instance with a small number of different sizes, which can be solved exactly using theconfiguration linear program.[30]
TheKarmarkar-Karp bin packing algorithm finds a solution with size at most, and runs in time polynomial inn (the polynomial has a high degree, at least 8).
Rothvoss[31] presented an algorithm that generates a solution with at most bins.
Hoberg and Rothvoss[32] improved this algorithm to generate a solution with at most bins. The algorithm is randomized, and its running-time is polynomial inn.
Martello and Toth[34] developed anexact algorithm for the 1-dimensional bin-packing problem, called MTP. A faster alternative is the Bin Completion algorithm proposed byRichard E. Korf in 2002[35] and later improved.[36]
A further improvement was presented by Schreiber and Korf in 2013.[37] The new Improved Bin Completion algorithm is shown to be up to five orders of magnitude faster than Bin Completion on non-trivial problems with 100 items, and outperforms the BCP (branch-and-cut-and-price) algorithm by Belov and Scheithauer on problems that have fewer than 20 bins as the optimal solution. Which algorithm performs best depends on problem properties like the number of items, the optimal number of bins, unused space in the optimal solution and value precision.
A special case of bin packing is when there is a small numberd of different item sizes. There can be many different items of each size. This case is also calledhigh-multiplicity bin packing, and It admits more efficient algorithms than the general problem.
Bin-packing with fragmentation orfragmentable object bin-packing is a variant of the bin packing problem in which it is allowed to break items into parts and put each part separately on a different bin. Breaking items into parts may allow for improving the overall performance, for example, minimizing the number of total bin. Moreover, thecomputational problem of finding an optimal schedule may become easier, as some of the optimization variables become continuous. On the other hand, breaking items apart might be costly. The problem was first introduced by Mandal, Chakrabarti and Ghose.[38]
In the first variant, calledbin-packing with size-increasing fragmentation (BP-SIF), each item may be fragmented; overhead units are added to the size of every fragment.
In the second variant, calledbin-packing with size-preserving fragmentation (BP-SPF) each item has a size and a cost; fragmenting an item increases its cost but does not change its size.
Mandal, Chakrabarti and Ghose[38] proved that BP-SPF isNP-hard.
Menakerman and Rom[39] showed that BP-SIF and BP-SPF are bothstrongly NP-hard. Despite the hardness, they present several algorithms and investigate their performance. Their algorithms use classic algorithms for bin-packing, likenext-fit andfirst-fit decreasing, as a basis for their algorithms.
Bertazzi, Golden and Wang[40] introduced a variant of BP-SIF with split rule: an item is allowed to be split in only one way according to its size. It is useful for thevehicle routing problem for example. In their paper, they provide the worst-case performance bound of the variant.
Shachnai, Tamir and Yehezkeli[41] developed approximation schemes for BP-SIF and BP-SPF; a dualPTAS (a PTAS for the dual version of the problem), an asymptotic PTAS called APTAS, and a dual asymptoticFPTAS called AFPTAS for both versions.
Ekici[42] introduced a variant of BP-SPF in which some items are in conflict, and it is forbidden to pack fragments of conflicted items into the same bin. They proved that this variant, too, is NP-hard.
Cassazza and Ceselli[43] introduced a variant with no cost and no overhead, and the number of bins is fixed. However, the number of fragmentations should be minimized. They present mathematical programming algorithms for both exact and approximate solutions.
The problem offractionalknapsack with penalties was introduced by Malaguti, Monaci, Paronuzzi and Pferschy.[44] They developed an FPTAS and adynamic program for the problem, and they showed an extensive computational study comparing the performance of their models. See also:Fractional job scheduling.
An important special case of bin packing is that the item sizes form adivisible sequence (also calledfactored). A special case of divisible item sizes occurs in memory allocation in computer systems, where the item sizes are all powers of 2. If the item sizes are divisible, then some of theheuristic algorithms for bin packing find an optimal solution.[45]
There is a variant of bin packing in which there arecardinality constraints on the bins: each bin can contain at mostk items, for some fixed integerk.
Krause, Shen and Schwetman[46] introduce this problem as a variant ofoptimal job scheduling: a computer has somek processors. There are somen jobs that take unit time (1), but have different memory requirements. Each time-unit is considered a single bin. The goal is to use as few bins (=time units) as possible, while ensuring that in each bin, at mostk jobs run. They present several heuristic algorithms that find a solution with at most bins.
Kellerer and Pferschy[47] present an algorithm with run-time, that finds a solution with at most bins. Their algorithm performs abinary search for OPT. For every searched valuem, it tries to pack the items into 3m/2 bins.
There are various ways to extend the bin-packing model to more general cost and load functions:
Anily, Bramel and Simchi-Levi[48] study a setting where the cost of a bin is aconcave function of the number of items in the bin. The objective is to minimize the totalcost rather than the number of bins. They show thatnext-fit-increasing bin packing attains an absolute worst-case approximation ratio of at most 7/4, and an asymptotic worst-case ratio of 1.691 for any concave and monotone cost function.
Cohen, Keller, Mirrokni and Zadimoghaddam[49] study a setting where the size of the items is not known in advance, but it is arandom variable. This is particularly common incloud computing environments. While there is an upper bound on the amount of resources a certain user needs, most users use much less than the capacity. Therefore, the cloud manager may gain a lot by slightovercommitment. This induces a variant of bin packing withchance constraints: the probability that the sum of sizes in each bin is at mostB should be at leastp, wherep is a fixed constant (standard bin packing corresponds top=1). They show that, under mild assumptions, this problem is equivalent to asubmodular bin packing problem, in which the "load" in each bin is not equal to the sum of items, but to a certainsubmodular function of it.
In the bin packing problem, thesize of the bins is fixed and theirnumber can be enlarged (but should be as small as possible).
In contrast, in themultiway number partitioning problem, thenumber of bins is fixed and theirsize can be enlarged. The objective is to find a partition in which the bin sizes are as nearly equal is possible (in the variant calledmultiprocessor scheduling problem orminimummakespan problem, the goal is specifically to minimize the size of the largest bin).
In thevector bin packing problem, each item is a vector, and the size of each bin is also a vector. Let a bin has size, and the sum of vectors in the bin be, then the requirement is that.[50]
In theinverse bin packing problem,[51] both the number of bins and their sizes are fixed, but the item sizes can be changed. The objective is to achieve the minimum perturbation to the item size vector so that all the items can be packed into the prescribed number of bins.
In themaximum resource bin packing problem,[52] the goal is tomaximize the number of bins used, such that, for some ordering of the bins, no item in a later bin fits in an earlier bin. In a dual problem, the number of bins is fixed, and the goal is to minimize the total number or the total size of items placed into the bins, such that no remaining item fits into an unfilled bin.
In thebin covering problem, the bin size is boundedfrom below: the goal is tomaximize the number of bins used such that the total size in each bin is at least a given threshold.
In thefair indivisible chore allocation problem (a variant offair item allocation), the items represent chores, and there are different people each of whom attributes a different difficulty-value to each chore. The goal is to allocate to each person a set of chores with an upper bound on its total difficulty-value (thus, each person corresponds to a bin). Many techniques from bin packing are used in this problem too.[53]
In theguillotine cutting problem, both the items and the "bins" are two-dimensional rectangles rather than one-dimensional numbers, and the items have to be cut from the bin using end-to-end cuts.
In theselfish bin packing problem, each item is a player who wants to minimize its cost.[54]
There is also a variant of bin packing in which the cost that should be minimized is not the number of bins, but rather a certainconcave function of the number of items in each bin.[48]
Inlogistics and e-commerce, three-dimensional bin packing underlies “cartonization,” where software selects a shipping carton and a feasible packing arrangement for a set of items; closely related industrial problems include container and pallet loading.[55]
Other variants aretwo-dimensional bin packing,[56]three-dimensional bin packing,[57]bin packing with delivery,[58]
^Gonzalez, Teofilo F. (23 May 2018).Handbook of approximation algorithms and metaheuristics. Volume 2 Contemporary and emerging applications. Taylor & Francis Incorporated.ISBN9781498770156.
^abcGyörgy, Dósa; Sgall, Jirí (2014). "Optimal Analysis of Best Fit Bin Packing".Automata, Languages, and Programming. Lecture Notes in Computer Science. Vol. 8572. pp. 429–441.doi:10.1007/978-3-662-43948-7_36.ISBN978-3-662-43947-0.
^abRamanan, Prakash; Brown, Donna J; Lee, C.C; Lee, D.T (September 1989). "On-line bin packing in linear time".Journal of Algorithms.10 (3):305–326.doi:10.1016/0196-6774(89)90031-X.hdl:2142/74206.
^abcDósa, György (2007). "The Tight Bound of First Fit Decreasing Bin-Packing Algorithm Is FFD(I) ≤ 11/9\mathrm{OPT}(I) + 6/9".Combinatorics, Algorithms, Probabilistic and Experimental Methodologies. ESCAPE.doi:10.1007/978-3-540-74450-4_1.
^abYue, Minyi; Zhang, Lei (July 1995). "A simple proof of the inequality MFFD(L) ≤ 71/60 OPT(L) + 1,L for the MFFD bin-packing algorithm".Acta Mathematicae Applicatae Sinica.11 (3):318–330.doi:10.1007/BF02011198.S2CID118263129.
^Nir Menakerman and Raphael Rom "Bin Packing with Item Fragmentation". Algorithms and Data Structures, 7th International Workshop, WADS 2001, Providence, RI, USA, August 8-10, 2001, Proceedings.
^Lodi A., Martello S., Monaci, M., Vigo, D. (2010) "Two-Dimensional Bin Packing Problems". In V.Th. Paschos (Ed.),Paradigms of Combinatorial Optimization, Wiley/ISTE, pp. 107–129