[ library(gfd) | Reference Manual | Alphabetic Index ]

bin_packing(+Items, ++ItemSizes, +N, +BinSize)

The one-dimensional bin packing constraint: packing M items into N bins of size BinSize.
A collection of M (domain) variables or integers (domain/value between 1 and N)
A collection of M non-negative integers
A positive Integer
A non-negative integer


This constraint is for one-dimensional bin-packing, that is, to pack M items with individual sizes into N bins, such that the sum of sizes of items in each bin does not exceed BinSize. Each element of Items and its corresponding element in ItemSizes represents an item, such that the i'th element of ItemSizes is the size of the i'th item, and the i'th element in Items is the bin this item is packed into.

This constraint can be seen as a special case of the cumulative/4 constraint, where all task durations are equal to 1, each bin represents a time point, and BinSize corresponds to the Resource.

This constraint is implemented using the more general bin_packing/3, where each bin has its own size, represented by a domain variable, as this is what is implemented by Gecode. This form of the constraint with a fixed BinSize is more common. so it is provided for convenience and compatibility. Note that this constraint uses ECLiPSe indexing -- bins are indexed starting from 1. There is no Gecode indexing version of this constraint as it is not implemented directly in Gecode.

This constraint is described in the global constraint catalog as bin_packing, but with slightly different arguments: in the catalog, N (the number of bins) is implicitly defined by the domains of the variables in Items, and the representation of item is grouped into a single argument of collection of pairs, each pair representing an item: the bin to pack the item, and its size. It is implemented using Gecode's binpacking() constraint, with the loads of all bins set to the domain 0..BinSize,i.e.. that they all have capacity of BinSize.


[eclipse 4]: bin_packing([3,1,3], [4,3,1], 3, 5).  % Succeed

[eclipse 5]: bin_packing([3,3,3], [4,3,1], 3, 5).  % Fails

See Also

bin_packing / 3, cumulative / 4, fd_global : bin_packing / 4, ic_global : bin_packing / 4