Bin packing #
An instance of bin packing is a list l : List ℕ of item sizes and a bin capacity C : ℕ. A
packing (Cslib.Algorithms.Lean.BinPacking.IsPacking) is a list of bins, each a list of items,
that together hold exactly the items of l, counted with multiplicity, and each hold at most C.
The number of bins is the length of the packing, and an optimal packing minimizes it. This is the
problem of Williamson and Shmoys, Section 3.3 with the sizes aᵢ ∈ (0, 1]
scaled to integers aᵢ ≤ C.
Every packing uses at least l.sum / C bins (IsPacking.sum_le_mul_length). Next Fit and First
Fit both return packings in which every two consecutive bins are jointly overfull: their
contents do not fit together into one bin. Pairing consecutive bins, such a packing with m bins
holds more than C * ⌊m / 2⌋ (add_one_mul_div_two_le_of_isChain), so it uses fewer than twice as
many bins as any packing of the same items (length_lt_two_mul_of_isChain).
Main definitions #
Cslib.Algorithms.Lean.BinPacking.IsPacking: packings of a list of items into bins of a given capacity.
Main results #
Cslib.Algorithms.Lean.BinPacking.IsPacking.sum_le_mul_length: the volume bound.Cslib.Algorithms.Lean.BinPacking.IsPacking.sum_map_le_mul_length: the volume bound for a weight bounded on every bin.Cslib.Algorithms.Lean.BinPacking.IsPacking.count_le_mul_length: the counting bound for an item of which every bin holds a bounded number of copies.Cslib.Algorithms.Lean.BinPacking.exists_isPacking_iff: a packing exists exactly when every item fits into a bin.Cslib.Algorithms.Lean.BinPacking.length_lt_two_mul_of_isChain: a packing whose consecutive bins are jointly overfull uses fewer than twice as many bins as any packing.
References #
bins packs the items l into bins of capacity C: together the bins hold exactly the items
of l, counted with multiplicity, and each bin holds at most C.
The bins hold exactly the items.
Every bin holds at most
C.
Weighted volume bound: if every list of items of total size at most C has total weight
at most K under a weight f, then the items of a packing have total weight at most K times
the number of bins.
Counting bound: if every list of items of total size at most C holds at most k copies
of an item x, then a packing holds at most k copies of x per bin.
Pairing consecutive bins: if every two consecutive bins are jointly overfull, then the bins
hold more than C for each pair, so (C + 1) * ⌊m / 2⌋ is at most their total load.
A packing of a nonempty list whose consecutive bins are jointly overfull uses fewer than twice
as many bins as any packing of the same items, that is at most 2 * OPT - 1 bins.