1D bin packing "First Fit (Decreasing)" algorithm
Arguments
- x
A numeric vector of item sizes to be fit into bins. Each value represents the size of an atomic item. If a value is
NA
it is ignored and the corresponding result will also beNA
.- cap
Bin capacity in units of values in
x
. A scalar value. If an individual item size is abovecap
a single bin is reserved for this item.- sort
Determines whether the input vector should be sorted in decreasing order before applying the "First Fit" algorithm ("First Fit Decreasing").
Value
A integer vector of labels of the same length as x
. The integer
label at position i
determines the assignment of the i
th item
with size x[i]
to a bin. If the value x[i]
is NA
the result
label at position i
will also be NA
.
Details
See Wikipedia for a concise introduction or "The Art of Computer Programming Vol. 1" by Donald E. Knuth (1997, ISBN: 0201896834) for more details.