Suvarna Garge (Editor)

Bin packing problem

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

In the bin packing problem, objects of different volumes must be packed into a finite number of bins or containers each of volume V in a way that minimizes the number of bins used. In computational complexity theory, it is a combinatorial NP-hard problem. The decision problem (deciding if objects will fit into a specified number of bins) is NP-complete.

Contents

There are many variations of this problem, such as 2D packing, linear packing, packing by weight, packing by cost, and so on. They have many applications, such as filling up containers, loading trucks with weight capacity constraints, creating file backups in media and technology mapping in Field-programmable gate array semiconductor chip design.

The bin packing problem can also be seen as a special case of the cutting stock problem. When the number of bins is restricted to 1 and each item is characterised by both a volume and a value, the problem of maximising the value of items that can fit in the bin is known as the knapsack problem.

Despite the fact that the bin packing problem has an NP-hard computational complexity, optimal solutions to very large instances of the problem can be produced with sophisticated algorithms. In addition, many heuristics have been developed: for example, the first 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, where n is the number of elements to be packed. The algorithm can be made much more effective by first sorting the list of elements 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.

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 since when virtual machines (VMs) are packed in a server, their total memory requirement could decrease due to pages 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 the 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-called online bin packing. Here the objects 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.

Formal statement

Given a set of bins S 1 , S 2 . . . with the same size V and a list of n items with sizes a 1 , , a n to pack, find an integer number of bins B and a B -partition S 1 S B of the set { 1 , , n } such that i S k a i V for all k = 1 , , B . A solution is optimal if it has minimal B . The B -value for an optimal solution is denoted OPT below. A possible Integer Linear Programming formulation of the problem is:

where y i = 1 if bin i is used and x i j = 1 if item j is put into bin i .

First-fit algorithm

This is a very straightforward greedy approximation algorithm. The algorithm processes the items in arbitrary order. For each item, it attempts to place the item in the first bin that can accommodate the item. If no bin is found, it opens a new bin and puts the item within the new bin.

It is rather simple to show this algorithm achieves an approximation factor of 2, that is, the number of bins used by this algorithm is no more than twice the optimal number of bins. In other words, it is impossible for 2 bins to be at most half full because such a possibility implies that at some point, exactly one bin was at most half full and a new one was opened to accommodate an item of size at most V/2. But since the first one has at least a space of V / 2, the algorithm will not open a new bin for any item whose size is at most V / 2. Only after the bin fills with more than V / 2 or if an item with a size larger than V / 2 arrives, the algorithm may open a new bin.

Thus if we have B bins, at least B − 1 bins are more than half full. Therefore, i = 1 n a i > B 1 2 V . Because i = 1 n a i V is a lower bound of the optimum value OPT, we get that B − 1 < 2OPT and therefore B ≤ 2OPT. See the analysis below for better approximation results.

Analysis of approximate algorithms

The best fit decreasing and first fit decreasing strategies are among the simplest heuristic algorithms for solving the bin packing problem. They have been shown to use no more than 11/9 OPT + 1 bins (where OPT is the number of bins given by the optimal solution). The simpler of these, the First Fit Decreasing (FFD) strategy, operates by first sorting the items to be inserted in decreasing order by their sizes, and then inserting each item into the first bin in the list with sufficient remaining space. Sometimes, however, one does not have the option to sort the input, for example, when faced with an online bin packing problem. In 2007, it was proven that the bound 11/9 OPT + 6/9 for FFD is tight. MFFD (a variant of FFD) uses no more than 71/60 OPT + 1 bins (i.e. bounded by about 1.18 OPT, compared to about 1.22 OPT for FFD). In 2013, Dósa and Sgall gave a tight upper bound for the first-fit (FF) strategy, showing that it never needs more than 17/10 OPT bins for any input.

It is NP-hard to distinguish whether OPT is 2 or 3, thus for all ε > 0, bin packing is hard to approximate within 3/2 − ε. (If such an approximation exists, one could determine whether n non-negative integers can be partitioned into two sets with the same sum in polynomial time. However, this problem is known to be NP-hard.) Consequently, the bin packing problem does not have a polynomial-time approximation scheme (PTAS) unless P = NP. On the other hand, for any 0 < ε ≤ 1, it is possible to find a solution using at most (1 + ε)OPT + 1 bins in polynomial time. This approximation type is known as asymptotic PTAS.

Exact algorithm

Martello and Toth developed an exact algorithm for the 1-D bin-packing problem, called MTP. A faster alternative is the Bin Completion algorithm proposed by Korf in 2002 and later improved; this second paper reports the average time to solve one million instances with 80 items on a 440 MHz Sun Ultra 10 workstation was 31 ms.

A further improvement was presented by Schreiber and Korf in 2013. 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 less than 20 bins as the optimal solution. Which algorithm performs best depends on problem properties like number of items, optimal number of bins, unused space in the optimal solution and value precision.

References

Bin packing problem Wikipedia