Documentation

CslibFrontier.Algorithms.Lean.BinPacking.NextFit

Next Fit #

Next Fit keeps a single open bin. It places each item into the open bin when the item fits, and otherwise closes the bin and opens a new one holding the item. Every two consecutive bins it returns are jointly overfull, since the first item of the later bin did not fit into the earlier one, so Next Fit uses fewer than twice as many bins as any packing (Cslib.Algorithms.Lean.BinPacking.length_nextFit_lt), that is at most 2 * OPT - 1 bins. Next Fit is analysed in Johnson's thesis Johnson; Williamson and Shmoys, Section 3.3 prove the bound 2 * OPT + 1 for First Fit by the same pairing argument, which by their notes to Chapter 3 is the thesis's analysis of Next Fit.

Next Fit keeps the items in their input order (flatten_nextFit), so it returns a packing whenever every item fits into a bin (isPacking_nextFit).

Main definitions #

Main results #

References #

One step of Next Fit on the bins in reverse order, the open bin first: add the item to the open bin if it fits, and otherwise open a new bin holding it.

Next Fit with bin capacity C.

@[simp]

Next Fit keeps the items in their input order.

theorem Cslib.Algorithms.Lean.BinPacking.isChain_nextFit (C : ℕ) (l : List ℕ) :
List.IsChain (fun (b b' : List ℕ) => C < b.sum + b'.sum) (nextFit C l)

Every two consecutive bins of Next Fit are jointly overfull.

theorem Cslib.Algorithms.Lean.BinPacking.isPacking_nextFit {C : ℕ} {l : List ℕ} (hl : ∀ a ∈ l, a ≤ C) :
IsPacking C l (nextFit C l)

Next Fit returns a packing whenever every item fits into a bin.

Next Fit's volume bound: (C + 1) * ⌊NF / 2⌋ ≤ l.sum.

theorem Cslib.Algorithms.Lean.BinPacking.length_nextFit_lt {C : ℕ} {l : List ℕ} {Q : List (List ℕ)} (hQ : IsPacking C l Q) (hl : l ≠ []) :
(nextFit C l).length < 2 * Q.length

Next Fit is a 2-approximation: on a nonempty list of items it uses fewer than twice as many bins as any packing, that is at most 2 * OPT - 1 bins Johnson.