The knapsack FPTAS #
An instance of the knapsack problem is a list of items (weight, value) and a capacity B; a
feasible solution is a subsequence of the items of total weight at most B, the notion of
Cslib.Complexity.Knapsack (Cslib.Complexity.mem_Knapsack_iff_sublist). The FPTAS with
accuracy 1 / k (Cslib.Algorithms.Lean.Knapsack.fptas) discards the items heavier than B,
rounds the value v of each of the n remaining items to ⌊v * n * k / P⌋, where P is their
largest value, and solves the rounded instance exactly with the dynamic program by profit
(Cslib.Algorithms.Lean.Knapsack.profitDP). The rounded values are at most n * k, so the
dynamic program runs in time polynomial in n and k
(Cslib.Algorithms.Lean.Knapsack.computableInPolyTime_fptas).
Rounding loses less than P / (n * k) per item, so less than P / k in total, and the most
valuable fitting item alone is feasible, so the returned value is at least (1 - 1 / k) times
the value of every feasible solution (Cslib.Algorithms.Lean.Knapsack.sub_one_mul_value_le_fptas)
Williamson and Shmoys, Algorithm 3.2 and Theorem 3.5, Ibarra and
Kim. Williamson and Shmoys round with μ = ε P / n and assume that every item
fits; discarding the items that do not fit removes that assumption.
Main definitions #
Cslib.Algorithms.Lean.Knapsack.fptas: the FPTAS with accuracy1 / k.
Main results #
Cslib.Algorithms.Lean.Knapsack.fptas_sublist,Cslib.Algorithms.Lean.Knapsack.sum_map_fst_fptas_le: the FPTAS returns a feasible solution.Cslib.Algorithms.Lean.Knapsack.sub_one_mul_value_le_fptas: its value is at least1 - 1 / ktimes that of every feasible solution.Cslib.Algorithms.Lean.Knapsack.one_sub_mul_value_le_fptas: for every realε > 0, withk = ⌈1 / ε⌉, its value is at least1 - εtimes that of every feasible solution.
References #
The knapsack FPTAS with accuracy 1 / k, on the items x.1 and the capacity x.2:
discard the items heavier than the capacity, round the values of the n others to
⌊v * n * k / P⌋ with P their largest value, and solve the rounded instance exactly with the
dynamic program by profit.
The rounding error of the FPTAS: k times the value of a feasible solution is at most k
times the value returned plus the largest value of a fitting item.
The FPTAS guarantee Williamson and Shmoys, Theorem 3.5: with
accuracy 1 / k, the FPTAS returns at least 1 - 1 / k times the value of every feasible
solution.
The knapsack FPTAS Williamson and Shmoys, Theorem 3.5,
Ibarra and Kim: for every real ε > 0, with k = ⌈1 / ε⌉, the FPTAS returns
a feasible solution whose value is at least 1 - ε times that of every feasible solution.