Karmarkar–Karp bin packing algorithms
The Karmarkar-Karp (KK) bin packing algorithms are several related approximation algorithm for the bin packing problem.[1] The bin packing problem is a problem of packing items of different sizes into bins of identical capacity, such that the total number of bins is as small as possible. Finding the optimal solution is computationally hard. Karmarkar and Karp devised an algorithm that runs in polynomial time and finds a solution with at most bins, where OPT is the number of bins in the optimal solution. They also devised several other algorithms with slightly different approximation guarantees and run-time bounds.
The KK algorithms were considered a breakthrough in the study of bin packing: the previously-known algorithms found multiplicative approximation, where the number of bins was at most for some constants , or at most .[2] The KK algorithms were the first ones to attain an additive approximation.
Input
The input to a bin-packing problem is a set of items of different sizes, a1,...an. The following notation is used:
- n - the number of items.
- m - the number of different item sizes. For each i in 1,...,m:
- si is the i-th size;
- ni is the number of items of size si.
- B - the bin size.
High-level idea
The KK algorithms essentially solve the configuration linear program:
.
Here, A is a matrix with m rows. Each column of A represents a feasible configuration - a multiset of item-sizes, such that the sum of all these sizes is at most B. The set of configurations is C. x is a vector of size C. Each element xc of x represents the number of times configuration c is used.
- Example:[3] suppose the item sizes are 3,3,3,3,3,4,4,4,4,4, and B=12. Then there are C=10 possible configurations: 3333; 333; 33, 334; 3, 34, 344; 4, 44, 444. The martix A has two rows: [4,3,2,2,1,1,1,0,0,0] for s=3 and [0,0,0,1,0,1,2,1,2,3] for s=4. The vector n is [5,5] since there are 5 items of each size. A possible optimal solution is x=[1,0,0,0,0,0,1,0,0,1], corresponding to using three bins with configurations 3333, 344, 444.
There are two main difficulties in solving this problem. First, it is an integer linear program, which is computationally hard to solve. Second, the number of variables is C - the number of configurations, which may be enormous. The KK algorithms cope with these difficulties using several techniques, some of which were already introduced by de-la-Vega and Lueker.[2] Here is a high-level description of the algorithm (where is the original instance):
- 1-a. Let be an instance constructed from by removing small items.
- 2-a. Let be an instance constructed from by grouping items and rounding the size of items in each group to the highest item in the group.
- 3-a. Construct the configuration linear program for , without the integrality constraints.
- 4. Compute a (fractional) solution x for the relaxed linear program.
- 3-b. Round x to an integral solution for .
- 3-a. Construct the configuration linear program for , without the integrality constraints.
- 2-b. "Un-group" the items to get a solution for .
- 2-a. Let be an instance constructed from by grouping items and rounding the size of items in each group to the highest item in the group.
- 1-b. Add the small items to get a solution for .
Below, we describe each of these steps in turn.
Step 1. Removing and adding small items
The motivation for removing small items is that, when all items are large, the number of items in each bin must be small, so the number of possible configurations is (relatively) small. We pick some constant , and remove from the original instance all items smaller than . Let be the resulting instance. Note that in , each bin can contain at most items. We pack and get a packing with some bins.
Now, we add the small items into the existing bins in an arbitrary order, as long as there is room. When there is no more room in the existing bins, we open a new bin (as in next-fit bin packing). Let be the number of bins in the final packing. Then:
.
Proof. If no new bins are opened, then the number of bins remains . If a new bin is opened, then all bins except maybe the last one contain a total size of at least , so the total instance size is at least . So the optimal solution needs at least bins. Therefore, .
Step 2. Grouping and un-grouping items
The motivation for grouping items is to reduce the number of different item sizes, to reduce the number of constraints in the configuration LP. The general grouping process is:
- Order the items by descending size.
- Partition the items into groups.
- For each group, modify the size of all items in the group to the largest size in the group.
There are several different grouping methods.
Linear grouping
Let be an integer parameter. Put the largest items in group 1; the next-largest items in group 2; and so on (the last group might have fewer than items). Let be the original instance. Let be the first group (the group of the largest items), and the grouped instance without the first group. Then:
- - since group 1 in dominates group 2 in (all k items in group 1 are larger than the k items in group 2); similarly, group 2 in dominates group 3 in , etc.
- - since it is possible to pack each item in into a single bin.
Therefore, ; given a solution to with bins, we can get a solution to with at most bins.
Geometric grouping
Let be an integer parameter. Geometric grouping proceeds in two steps:
- Partition the instance into several instances such that, in each instance , all sizes are in the interval . Note that, if all items in have size at least , then the number of instances is at most .
- On each instance , perform linear rounding with paramter . Let be the resulting instances.
Alternative geometric grouping
TODO
Step 3. Constructing and rounding the LP
The main tool used by the KK algorithms is the fractional configuration linear program:
.
Here, A is a matrix with m rows. Each column of A represents a feasible configuration - a multiset of item-sizes, such that the sum of all these sizes is at most B. The set of configurations is C. x is a vector of size C. Each element xc of x represents the number of times configuration c is used. If x is integral then the solution to this problem is exactly OPT. Since x is allowed to be fractional, the solution might be smaller; denote it by LOPT. Moreover, let FOPT = (a1+...+an)/B = the theoretically-optimal number of bins, when all bins are completely filled with items or item fractions. The following relations are obvious:
- FOPT(I) ≤ LOPT(I), since FOPT(I) is the (possibly fractional) number of bins when all bins are completely filled with items or fractions of items. Clearly, no solution can be more efficient.
- LOPT(I) ≤ OPT(I), since LOPT(I) is a solution to a minimization problem with fewer constraints.
- OPT(I) < 2*FOPT(I), since in any packing with at least 2*FOPT(I) bins, the sum of the two least-full bins is at most B, so they can be combined into a single bin.
Rounding the fractional LP
Given an optimal solution to the fractional LP, it can be rounded into a solution for the integral ILP, proving that OPT(I) ≤ LOPT(I) + m/2:
- Let x be an optimal basic feasible solution of the fractional LP. By definition, the value of x is LOPT(I). Since the fractional LP has S constraints, x has at most S nonzero variables, that is, at most S different configurations are used. We construct from x an integral packing consisting of a principal part and a residual part.
- The principal part contains floor(xc) bins of each configuration c for which xc > 0.
- For the residual part (denoted by R), we construct two candidate packings:
- A single bin of each configuration c for which xc > 0; all in all S bins are needed.
- A greedy packing, with fewer than 2*FOPT(R) bins (since if there are at least 2*FOPT(R) bins, the two smallest ones can be combined).
- The smallest of these packings requires min(S, 2*FOPT(R)) ≤ average(S, 2*FOPT(R)) = FOPT(R) + S/2.
- Adding to this the rounded-down bins of the principal part yields LOPT(I) + S/2.
- The execution time of this conversion algorithm is O(n log n).
---
e - a fraction in (0,1), such that eB is the smallest size of an item.
Step 4. Solving the fractional LP
The dual LP
The dual linear program of the fractional LP is:
.
It has S variables y1,...,yS, and C constraints - one for each configuration. It has the following economic interpretation. For each size s, we should determine a nonnegative price ys. Our profit is the total price of all items. We want to maximize the profit n y subject to the constraints that the total price of items in each configuration is at most 1.
Solving the fractional LP
A linear program with no integrality constraints can be solved in time polynomial in the number of variables and constraints. The problem is that the number of variables in the fractional configuration LP is equal to the number of possible configurations, which might be huge. Karmarkar and Karp present an algorithm that, for any tolerance factor h, finds a basic feasible solution of cost at most LOPT(I) + h, and runs in time:
,
where S is the number of different sizes, n is the number of different items, and the size of the smallest item is eB. In particular, if e ≥ 1/n and h=1, the algorithm finds a solution with at most LOPT+1 bins in time: .
A randomized variant of this algorithm runs in expected time:
.
Their algorithm uses separation oracle to the dual LP.
Guarantees
Karmarkar and Karp presented four different algorithms. The run-time of all these algorithms depends on a function , which is a polynomial function describing the time it takes to solve the configuration linear program: . The algorithms attain the following guarantees:
- At most bins, with run-time in .
- At most bins, with run-time in .
- At most bins, with run-time in , where is a constant.
- At most bins, with run-time in , where is a constant.
Improvements
The KK techniques were improved later, to provide even better approximations: an algorithm by Rothvoss[4] uses at most bins, and an algorithm by Hoberg and Rothvoss[5] uses at most bins.
References
- ^ Karmarkar, Narendra; Karp, Richard M. (November 1982). "An efficient approximation scheme for the one-dimensional bin-packing problem". 23rd Annual Symposium on Foundations of Computer Science (SFCS 1982): 312–320. doi:10.1109/SFCS.1982.61. S2CID 18583908.
- ^ a b Fernandez de la Vega, W.; Lueker, G. S. (1981). "Bin packing can be solved within 1 + ε in linear time". Combinatorica. 1 (4): 349–355. doi:10.1007/BF02579456. ISSN 1439-6912. S2CID 10519631.
- ^ Claire Mathieu. "Approximation Algorithms Part I, Week 3: bin packing". Coursera.
{{cite web}}
: CS1 maint: url-status (link) - ^ Rothvoß, T. (2013-10-01). "Approximating Bin Packing within O(log OPT * Log Log OPT) Bins". 2013 IEEE 54th Annual Symposium on Foundations of Computer Science: 20–29. arXiv:1301.4010. doi:10.1109/FOCS.2013.11. ISBN 978-0-7695-5135-7. S2CID 15905063.
- ^ Hoberg, Rebecca; Rothvoss, Thomas (2017-01-01), "A Logarithmic Additive Integrality Gap for Bin Packing", Proceedings of the 2017 Annual ACM-SIAM Symposium on Discrete Algorithms, Proceedings, Society for Industrial and Applied Mathematics, pp. 2616–2625, doi:10.1137/1.9781611974782.172, ISBN 978-1-61197-478-2, S2CID 1647463, retrieved 2021-02-10