Documentation

CslibFrontier.Computability.PCP.Approximation.BinPacking

Bin packing is NP-hard to approximate within a factor below 3/2 #

A polynomial-time algorithm for bin packing that always uses fewer than 3/2 times the optimal number of bins decides Partition, so it gives P = NP Williamson and Shmoys, Theorem 3.8. Given a list l with total S, pack it into bins of capacity ⌊S / 2⌋. If l has a partition, two bins suffice, so the algorithm uses at most two bins; conversely two bins of capacity ⌊S / 2⌋ holding S hold exactly S / 2 each, and either is one side of a partition. Lists with a number larger than ⌊S / 2⌋ have no partition, and the empty list and lists of zeros always have one.

The algorithm is a function A : BinPackingInstance → List (List ℕ) from an instance ⟨items, capacity⟩ to bins, with the numbers in binary (BinPacking.encBinPacking and BinPacking.encBins). It is required to return a packing only when one exists, that is when every item fits into a bin (Cslib.Algorithms.Lean.BinPacking.exists_isPacking_iff), and its ratio is compared with every packing of a nonempty list.

Main definitions #

Main results #

References #

An instance of bin packing: a list items of natural-number item sizes and a bin capacity.

  • items : List ℕ

    The item sizes, possibly with repetitions.

  • capacity : ℕ

    The maximum total size a single bin may hold.

Instances For
    theorem Cslib.Complexity.BinPacking.encBinPacking_capacity_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → BinPackingInstance} :

    A bin-packing instance ⟨items, capacity⟩, all numbers in binary: the item sizes items as a framed list of framed entries, followed by capacity, unframed.

    theorem Cslib.Complexity.BinPacking.encBinPacking_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → List ℕ} {x1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encNat budget) :
    Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { items := x0 x, capacity := x1 x }) encIn encBinPacking budget
    @[reducible, inline]

    The tuple of the fields of encBinPacking.

    theorem Cslib.Complexity.BinPacking.encBinPacking_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List ℕ} {T0 S0 x1 T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encNat T1 S1) :
    Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { items := x0 x, capacity := x1 x }) encIn encBinPacking (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
    @[reducible, inline]

    A list of bins, such as the packing an algorithm returns: the concatenation of the framed bins, each the concatenation of its framed item sizes in binary. This is the layout encList (encList encNat) that other modules name by their own roles, such as Cslib.Complexity.KCenter.encDistMatrix; the name records the role.

    The decider for Partition built from a bin-packing algorithm A: accept lists summing to zero, and otherwise accept when every number fits into a bin of capacity ⌊S / 2⌋ and A packs the list into at most two such bins.

    The decider is correct: an algorithm that returns packings and uses fewer than 3/2 times as many bins as any packing of a nonempty list decides Partition.

    Bin packing is NP-hard to approximate within a factor below 3/2 Williamson and Shmoys, Theorem 3.8. A polynomial-time algorithm that returns a packing whenever every item fits into a bin, and on nonempty lists uses fewer than 3/2 times as many bins as any packing, gives P = NP.

    No ρ-approximation for bin packing with ρ < 3/2 unless P = NP Williamson and Shmoys, Theorem 3.8: a polynomial-time algorithm that returns a packing whenever every item fits into a bin, and on nonempty lists uses at most ρ times as many bins as any packing, gives P = NP.