The knapsack dynamic program by profit #
Items of a type ι have weights w : ι → ℕ and profits p : ι → ℕ. A selection is a
subsequence of the list of items; it is feasible for a capacity B when its total weight is at
most B. The dynamic program by profit computes, for every profit q up to the total profit, a
minimum-weight subsequence of profit exactly q (Cslib.Algorithms.Lean.Knapsack.profitTable),
and then returns a most profitable feasible entry (Cslib.Algorithms.Lean.Knapsack.profitDP). The
table has (l.map p).sum + 1 entries, so the program is pseudo-polynomial: polynomial in the
number of items and the total profit Williamson and Shmoys, Section 3.1.
Williamson and Shmoys's Algorithm 3.1 keeps the non-dominated (weight, profit) pairs instead;
indexing by profit gives the same optimum with a simpler invariant.
Adding an item a maps the table T to the table whose entry q is the lighter of T[q] and
T[q - p a] extended by a (Cslib.Algorithms.Lean.Knapsack.profitStep). By induction on the
items, every entry of profit q is a subsequence of profit q, and for every subsequence s
the entry at profit p(s) weighs at most w(s) (Cslib.Algorithms.Lean.Knapsack.TableSpec).
Main definitions #
Cslib.Algorithms.Lean.Knapsack.profitTable: the table of minimum-weight selections by profit.Cslib.Algorithms.Lean.Knapsack.profitDP: the exact dynamic program.
Main results #
Cslib.Algorithms.Lean.Knapsack.tableSpec_profitTable: soundness and completeness of the table.Cslib.Algorithms.Lean.Knapsack.profitDP_sublist,Cslib.Algorithms.Lean.Knapsack.sum_map_profitDP_le: the program returns a feasible selection.Cslib.Algorithms.Lean.Knapsack.sum_map_le_profitDP: it is optimal among feasible selections.
References #
The dynamic program #
Correctness #
The invariant of the profit table of l: its length, and soundness and completeness of its
entries.
The table has an entry for every profit up to the total profit.
Every entry of profit
qis a subsequence of profitq.- complete (s : List ι) : s.Sublist l → ∃ (r : List ι), T[(List.map p s).sum]? = some (some r) ∧ (List.map w r).sum ≤ (List.map w s).sum
For every subsequence, the entry at its profit weighs at most as much.
Correctness of the profit table.
The selection scan over the profit table stays a subsequence of the items.
Every entry of the profit table is a subsequence of the items.