First-fit-decreasing Bin Packing
   HOME

TheInfoList



OR:

First-fit-decreasing (FFD) is an algorithm for
bin packing The bin packing problem is an optimization 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 ma ...
. 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 A heuristic (; ), or heuristic technique, is any approach to problem solving or self-discovery that employs a practical method that is not guaranteed to be optimal, perfect, or rational, but is nevertheless sufficient for reaching an immediate, ...
.


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. In short: FFD orders the items by descending size, and then calls first-fit bin packing. 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. In the standard description, we loop over the items once, but keep many open bins. In the equivalent description, we loop over the items many times, but keep only a single open bin each time.


Performance analysis

The performance of FFD was analyzed in several steps. Below, FFD(S,C) 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 FFD(S,C) \leq 11/9 \mathrm(S,C) +4 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 FFD(S,C) \leq 11/9 \mathrm(S,C) +1 in 1991 and, in 1997, improved this analysis to FFD(S,C) \leq 11/9 \mathrm(S,C) + 7/9 together with Li Rongheng. * In 2007 György Dósa proved the tight bound FFD(S,C) \leq 11/9 \mathrm(S,C) +6/9 and presented an example for which FFD(S,C) = 11/9 \mathrm(S,C) +6/9.


Worst-case example

The lower bound example given in by Dósa is the following: Consider the two bin configurations: * B_1 := \ ; * B_2 := \ . If there are 4 copies of B_1 and 2 copies of B_2 in the optimal solution, FFD will compute the following bins: * 4 bins with configuration \, * 1 bin with configuration \, * 1 bin with configuration \, * 1 bin with configuration \, * 1 one final bin with configuration \, That is, 8 bins total, while the optimum has only 6 bins. Therefore, the upper bound is tight, because 11/9 \cdot 6 + 6/9 = 72/9 = 8. This example can be extended to all sizes of \text(S,C): in the optimal configuration there are 9''k''+6 bins: 6''k''+4 of type B1 and 3''k''+2 of type B2. But FFD needs at least 11''k''+8 bins, which is \frac(6k+4)+\frac.


Monotonicity properties

Contrary to intuition, FFD(S,C) is ''not'' a monotonic function of ''C''. For example, suppose the input is:
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. But with capacity 61, FFD packs 4 bins: * 44, 17; * 24, 24, 8; * 22, 21, 8, 6; * 6. This is because, with capacity 61, the 17 fits into the first bin, and thus blocks the way to the following 8, 8. As another example, suppose the inputs are: 51, 27.5, 27.5, 27.5, 27.5, 25, 12, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10. With capacity 75, FFD packs 4 bins: * 51, 12, 12 * 27.5, 27.5, 10, 10 * 27.5, 27.5, 10, 10 * 25, 10, 10, 10, 10, 10 But with capacity 76, it needs 5 bins: * 51, 25 * 27.5, 27.5, 12 * 27.5, 27.5, 12 * 10, 10, 10, 10, 10, 10, 10 * 10, 10 Similarly, FFD(S,C) 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. Consider the above example with capacity 60. If the 17 becomes 16, then the resulting packing is: *44, 16; * 24, 24, 8; * 22, 21, 8, 6; * 6. However, the FFD algorithm has an "asymptotic monotonicity" property, defined as follows. * For every instance ''S'' and integer ''m'', let MinCap(''S,m'') be the smallest capacity ''C'' such that OPT(S,C)\leq m * For every integer ''m'', let MinRatio(''m'') be the
infimum In mathematics, the infimum (abbreviated inf; plural infima) of a subset S of a partially ordered set P is a greatest element in P that is less than or equal to each element of S, if such an element exists. Consequently, the term ''greatest low ...
of the numbers ''r''≥1 such that, for all input sets ''S'', FFD(S,r\cdot \text(S,m))\leq m. 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(''m''), FFD(S,r\cdot \text(S,m))\leq m. This shows, in particular, that the infimum in the above definition can be replaced by minimum.


Modified first-fit-decreasing

Modified first fit decreasing (MFFD) 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. Then it proceeds through five phases: # 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. This algorithm was first studied by Johnson and Garey in 1985, where they proved that MFFD(S,C) \leq (71/60)\mathrm(S,C) + (31/6). This bound was improved in the year 1995 by Yue and Zhang who proved that MFFD(S,C) \leq (71/60)\mathrm{OPT}(S,C) + 1.


Other variants

Best-fit-decreasing (BFD) is very similar to FFD, except that after the list is sorted, it is processed by
best-fit bin packing Best-fit is an online 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 cap ...
. Its asymptotic approximation ratio is the same as FFD - 11/9.


Implementations

* Python: Th
prtpy package
contain
an implementation of first-fit decreasing


See also

*
Multifit algorithm The multifit algorithm is an algorithm for multiway number partitioning, originally developed for the problem of identical-machines scheduling. It was developed by Coffman, Garey and Johnson. Its novelty comes from the fact that it uses an algorithm ...
- an algorithm for
identical-machines scheduling Identical-machines scheduling is an optimization problem in computer science and operations research. We are given ''n'' jobs ''J''1, ''J''2, ..., ''Jn'' of varying processing times, which need to be scheduled on ''m'' identical machines, such that ...
, which uses FFD as a subroutine.


References

Bin packing