The 0-1 knapsack problem #
Knapsack is the decision version of the 0-1 knapsack problem: an instance x : KnapsackInstance
(Cslib.Complexity.encKnapsack) gives a list of items x.items (Cslib.Complexity.Knapsack.Item),
each with a weight and a value, a capacity x.capacity, and a goal x.goal, and asks whether some
sub-multiset of the items has total weight at most x.capacity and total value at least x.goal
[GJ79]. All numbers are encoded in binary (encNat); the verifier compares the sums in
binary (ComputableInPolyTime.binary_le).
Giving every number of a subset sum instance equal weight and value, and taking the target as
both capacity and goal, reduces SubsetSum to Knapsack. Karp's KNAPSACK [Kar72] is the
subset sum form of the problem.
Main definitions #
Cslib.Complexity.Knapsack.Item,Cslib.Complexity.Knapsack.encItem: knapsack items with weight and value, and their binary encoding.Cslib.Complexity.KnapsackInstance,Cslib.Complexity.encKnapsack: knapsack instances and their binary encoding.Cslib.Complexity.Knapsack,Cslib.Complexity.Knapsack.verifier.Cslib.Complexity.SubsetSum.toKnapsack.
Main results #
Cslib.Complexity.mem_Knapsack_iff_sublist: solutions are subsequences of the items.Cslib.Complexity.Knapsack.mem_NP:Knapsack ∈ NP encKnapsack.Cslib.Complexity.SubsetSum.toKnapsack_mem_iff: correctness of the reduction.Cslib.Complexity.polyTimeReducible_SubsetSum_Knapsack,Cslib.Complexity.Knapsack_npHard,Cslib.Complexity.Knapsack_npComplete:KnapsackisNP-complete.
References #
Instances For
Binary encoding of a Knapsack.Item as (weight, value).
Instances For
An instance of the 0-1 knapsack problem Garey and Johnson: a list of
items items, a weight capacity capacity, and a value goal goal.
- items : List Knapsack.Item
The available items, each with a weight and a value.
- capacity : ℕ
The maximum total weight allowed.
- goal : ℕ
The minimum total value required.
Instances For
Instances For
Instances For
Binary encoding of KnapsackInstance as (items, (capacity, goal)).
Instances For
The 0-1 knapsack problem: instances x : KnapsackInstance for which some sub-multiset of
x.items has total weight at most x.capacity and total value at least x.goal
Garey and Johnson.
Instances For
Knapsack asks for a subsequence of the items.
The verifier for Knapsack, a mask verifier (Cslib.Complexity.maskVerifier): the items
selected by the certificate mask fit the capacity and reach the goal.
Instances For
Knapsack.verifier verifies Knapsack with certificates as long as the encoded instance.
The Knapsack verifier is polynomial-time: the sums and comparisons are in binary.
The reduction from SubsetSum to Knapsack: each number becomes an item with equal weight
and value, and the target becomes both the capacity and the goal.
Instances For
Correctness of the reduction to Knapsack.
The reduction to Knapsack is polynomial-time.
SubsetSum reduces to Knapsack in polynomial time.
The 0-1 knapsack problem is NP-complete, with all numbers in binary Garey and Johnson.