First-fit-decreasing bin packing
First-fit-decreasing is an algorithm for bin packing. Its input is a list of items of different sizes. Its output is a packing - a partition of the items into bins of fixed capacity, such that the sum of sizes of items in each bin is at most the capacity. Ideally, we would like to use as few bins as possible, but minimizing the number of bins is an NP-hard problem, so we use an approximately-optimal heuristic.
Description
The FFD algorithm works as follows.- Order the items from largest to smallest.
- Open a new empty bin, bin #1.
- For each item from largest to smallest, find the first bin into which the item fits, if any.
- * If such a bin is found, put the new item in it.
- * Otherwise, open a new empty bin put the new item in it.
An equivalent description of the FFD algorithm is as follows.
- Order the items from largest to smallest.
- While there are remaining items:
- * Open a new empty bin.
- * For each item from largest to smallest:
- ** If it can fit into the current bin, insert it.
Performance analysis
The performance of FFD was analyzed in several steps. Below, denotes the number of bins used by FFD for input set S and bin-capacity C.- In 1973, D.S. Johnson proved in his doctoral thesis that for any instance S and capacity C.
- In 1985, B.S. Backer gave a slightly simpler proof and showed that the additive constant is not more than 3.
- Yue Minyi proved that in 1991 and, in 1997, improved this analysis to together with Li Rongheng.
- In 2007 György Dósa proved the tight bound and presented an example for which.
Worst-case example
- ;
- .
- 4 bins with configuration,
- 1 bin with configuration,
- 1 bin with configuration,
- 1 bin with configuration,
- 1 one final bin with configuration,
This example can be extended to all sizes of : in the optimal configuration there are 9k+6 bins: 6k+4 of type B1 and 3k+2 of type B2. But FFD needs at least 11k+8 bins, which is.
Performance with divisible item sizes
An important special case of bin-packing is that which the item sizes form a divisible sequence. A special case of divisible item sizes occurs in memory allocation in computer systems, where the item sizes are all powers of 2. In this case, FFD always finds the optimal packing.Monotonicity properties
Contrary to intuition, is not a monotonic function of C. Similarly, is not a monotonic function of the sizes of items in S: it is possible that an item shrinks in size, but the number of bins increases.However, the FFD algorithm has an "asymptotic monotonicity" property, defined as follows.
- For every instance S and integer m, let MinCap be the smallest capacity C such that
- For every integer m, let MinRatio be the infimum of the numbers r≥1 such that, for all input sets S,. This is the amount by which we need to "inflate" the bins such that FFD attains the optimal number of bins.
- Then, for every input S and for every r ≥ MinRatio,. This shows, in particular, that the infimum in the above definition can be replaced by minimum.
Examples
44, 24, 24, 22, 21, 17, 8, 8, 6, 6.With capacity 60, FFD packs 3 bins:
- 44, 8, 8;
- 24, 24, 6, 6;
- 22, 21, 17.
- 44, 17;
- 24, 24, 8;
- 22, 21, 8, 6;
- 6.
As another example, suppose the inputs are: 51, 28, 28, 28, 27, 25, 12, 12, 10, 10, 10, 10, 10, 10, 10, 10. With capacity 75, FFD packs 4 bins:
- 51, 12, 12
- 28, 28, 10
- 28, 27, 10, 10
- 25, 10, 10, 10, 10, 10
- 51, 25
- 28, 28, 12
- 28, 27, 12
- 10, 10, 10, 10, 10, 10, 10
- 10
- 44, 16;
- 24, 24, 8;
- 22, 21, 8, 6;
- 6.
Modified first-fit-decreasing
- Allot a bin for each large item, ordered largest to smallest.
- Proceed forward through the bins. On each: If the smallest remaining medium item does not fit, skip this bin. Otherwise, place the largest remaining medium item that fits.
- Proceed backward through those bins that do not contain a medium item. On each: If the two smallest remaining small items do not fit, skip this bin. Otherwise, place the smallest remaining small item and the largest remaining small item that fits.
- Proceed forward through all bins. If the smallest remaining item of any size class does not fit, skip this bin. Otherwise, place the largest item that fits and stay on this bin.
- Use FFD to pack the remaining items into new bins.
Other variants
Best-fit-decreasing is very similar to FFD, except that after the list is sorted, it is processed by best-fit bin packing. Its asymptotic approximation ratio is the same as FFD - 11/9.Implementations
- Python: The contains .