Definition · The 0/1 knapsack modelItems 1, …, n with values v_j and weights w_j, and a capacity W. Choose y_j ∈ {0, 1} to maximise Σ v_j y_j subject to Σ w_j y_j ≤ W. The name is the picture: one bag, a weight limit, and each item either in or out.
Definition · The set-covering modelRequirements 1, …, m and sets 1, …, n with costs c_j, where set j covers some of the requirements. Choose y_j ∈ {0, 1} to minimise Σ c_j y_j subject to, for each requirement i, the row Σ y_j ≥ 1 taken over the sets that cover i. Replacing that ≥ by = gives set partitioning, which is a different problem.
Take three items worth 60, 100 and 120 weighing 10, 20 and 30, with a capacity of 50. Their values per unit weight are 6, 5 and 4, so the relaxation loads the first two whole — thirty units of weight, 160 of value — and then takes 2/3 of the third to fill the bag, for 240. That is the bound.
Example · Three answers on one instanceThe relaxation is worth 240 and gets there by splitting the third item. Greed by value per weight takes the first two, cannot fit the third in the remaining twenty units, and stops at 160. The best whole choice, found by trying all eight subsets, is the second and third items together: weight exactly 50, value 220. So 240 ≥ 220 ≥ 160, and the middle number is the only one that is an answer.
Discrete Mathematics’ “Greedy Algorithms” closes by showing the value-per-weight rule optimal for the fractional problem and defeated by the 0/1 version, which is precisely the gap between 240 and 160 here. The rule is not a heuristic for this model; it is the exact solution to the relaxation, and the two facts are easy to confuse because the arithmetic is the same.
The covering relaxation spreads halves
Five districts in a ring, each reachable from two of five depots, every depot costing 2. Each row says “at least one of these two depots”. The relaxation satisfies all five rows by opening every depot to the extent of 1/2, and pays 5. No whole choice does: three depots are needed, costing 6. The 1 between them is the price of not being able to open half a depot.
Example · Covering is not partitioningOn that same ring, require each district to be covered exactly once instead of at least once. Nothing in the data changed and only the relation did, and now there is no feasible choice of depots at all: an odd ring cannot be partitioned by adjacent pairs. The relaxation of the partitioning version is still solvable and still worth 5, which is the cruellest part — a relaxation being feasible says nothing about whether the integer problem is.
Both atoms above were solved exactly by enumerating every subset, and that is where this lesson's method ends: 2¹² is 4096, which is instant, and 2⁵⁰ is not a number of subsets anybody enumerates. What is this lesson's own is the pair of models and the shape of their relaxations. Four results about them are used here and proved elsewhere, each by its owner.
- The exact method for 0/1 knapsack beyond enumeration is a pseudo-polynomial dynamic programme — the Algorithms path, “0/1 Knapsack and Pseudo-Polynomial Time”.
- The approximation with a proved ratio is the fully polynomial scheme of “A Fully Polynomial Approximation for Knapsack”, in the same subject.
- The ln n ratio for greedy set cover is “Greedy Set Cover and the ln n Ratio”, which proves what greed costs in the worst case rather than measuring it on one instance.
- Why both problems are hard in the technical sense belongs to Discrete Mathematics’ “P, NP and NP-Completeness”, which is also where the word “hard” acquires its meaning.
None of those four is derived here, and none of them is needed to write the models down. What is needed is the reflex of solving the relaxation first and looking at what it made fractional, because the split item and the spread halves each point at the row doing the work — which is the variable to branch on when the search lesson arrives.