binPack {BBmisc} | R Documentation |
Simple bin packing.
Description
Maps numeric items in x
into groups with sum
less or equal than capacity
.
A very simple greedy algorithm is used, which is not really optimized
for speed. This is a convenience function for smaller vectors, not
a competetive solver for the real binbacking problem.
If an element of x
exceeds capacity
, an error
is thrown.
Usage
binPack(x, capacity)
Arguments
x |
[ |
capacity |
[ |
Value
[integer
]. Integer with values “1” to “n.bins”
indicating bin membership.
Examples
x = 1:10
bp = binPack(x, 11)
xs = split(x, bp)
print(xs)
print(sapply(xs, sum))
[Package BBmisc version 1.13 Index]