9.12 An ILP model for the Knapsack Problem with Setups¶
Part 2 · Formulations and their properties · Chapter 9 · Chapter 9: Knapsack problems · Lecture notes, volume 2 (PDF) · Slides · Exercises: Knapsack problems · App: LP relaxation and upper bounds for the 0/1 KP
The Knapsack Problem with Setups and its reference instance (Example 2.8) are defined in Chapter 2 «Knapsack problems», Section 2.9.
-
We introduce the following \(n\) binary variables:
\[\begin{equation*} \label{BIN_VAR_KPS} x_j = \left\{ \begin{array}{ll} 1 & \textrm{if item $j$ is selected in the knapsack}\\[1.5ex] 0 & \textrm{otherwise} \end{array} \qquad \forall j \in \mathscr{I}. \right. \tag{9.32} \end{equation*}\] -
We introduce the following \(q\) binary variables:
\[\begin{equation*} \label{BIN_VAR_KPS_Y} y_h = \left\{ \begin{array}{ll} 1 & \textrm{if class $h$ is activated (its setup is paid)}\\[1.5ex] 0 & \textrm{otherwise} \end{array} \qquad \forall h \in \{1,2,\dots,q\}. \right. \tag{9.33} \end{equation*}\]
Using these variables, an Integer Linear Programming (ILP) model for the Knapsack Problem with Setups (KPS) reads as follows:
This ILP model is referred to as the \(\mathrm{ILP}_{\mathrm{KPS}}\) model.
-
Description of the objective function and constraints of the \(\mathrm{ILP}_{\mathrm{KPS}}\) model:
-
the linear objective function \(\eqref{obj_KPS}\) maximizes the total revenue of the selected items minus the setup costs of the activated classes;
-
constraint \(\eqref{cons1_KPS}\) ensures that the total weight of the selected items plus the setup weights of the activated classes does not exceed the knapsack capacity (one linear constraint);
-
constraints \(\eqref{cons2_KPS}\) ensure that an item can be selected only if its class is activated (\(n\) linear constraints, one for each item);
-
finally, constraints \(\eqref{cons3_KPS}\) and \(\eqref{cons4_KPS}\) define the variables of the ILP model.
-
Example 9.16: \(\mathrm{ILP}_{\mathrm{KPS}}\) model
We consider a knapsack of capacity \(c = 20\) and a set \(\mathscr{I} = \{1,2,3,4,5,6\}\) of \(6\) items (\(n = 6\)), partitioned into \(q = 2\) classes \(\mathscr{J}_1 = \{1,2,3\}\) and \(\mathscr{J}_2 = \{4,5,6\}\), with setup costs \(f_1 = 3\), \(f_2 = 4\), setup weights \(s_1 = 2\), \(s_2 = 3\), and the following revenues and weights:
This is the KPS instance of Example 2.8. The \(\mathrm{ILP}_{\mathrm{KPS}}\) model for this KPS instance is:
An optimal solution \(~{\tilde{\vet x}}(\mathrm{ILP}_{\mathrm{KPS}})\), \(~{\tilde{\vet y}}(\mathrm{ILP}_{\mathrm{KPS}})\) is:
The optimal value \(z(\mathrm{ILP}_{\mathrm{KPS}})\) is \(16\). The associated optimal solution of the KPS is \(\tilde{S} =\{1,2,3,6\}\). The optimal solution is not unique: the subsets \(\{1,2,3\}\) and \(\{4,5,6\}\) have the same value.
9.13 Typical mistakes¶
Warning
-
Forgetting to sort the items. The formulas (9.13), (9.14) and the bounds hold only if the items are sorted by non-increasing efficiency: with another order the vector (9.13) is feasible but not optimal.
-
Using \(z(\mathrm{LP}\text{-}0_{\mathrm{KP}})\) as the bound. The first relaxation has no upper bounds on the variables, and it is much weaker: in Example 9.1 it gives \(27\), against \(\tfrac{49}{3}\) for the second relaxation.
-
Rounding when the profits are not integer. The bounds \(\UB_{\mathrm{D}}\) and \(\UB_{\mathrm{MT}}\) round down the fractional part: this is valid only because all the profits are integer.
-
Confusing the split item with the last selected item. The split item \(s\) is the first item that does not fit: in Example 9.1 it is \(s=3\), while the items \(1\) and \(2\) are selected entirely.
-
Assuming that the LP optimum is unique. With items of equal efficiency the \(\mathrm{LP}_{\mathrm{KP}}\) problem has other optimal solutions; the formulas (9.13) give one of them.
-
Copying the \(\mathrm{ILP}_{\mathrm{KP}}\) model to the variants. In the BKP and in the UKP the variables are integer, not binary; in the MCKP the class constraints (9.31c) are equalities; in the KPS, without the constraints \(\eqref{cons2_KPS}\) the model selects items with \(y_h = 0\) and never pays a setup.
9.14 In summary¶
In summary
-
The \(\mathrm{ILP}_{\mathrm{KP}}\) model has one binary variable per item, one capacity constraint and the objective of maximizing the total profit.
-
The relaxation \(\mathrm{LP}_{\mathrm{KP}}\) is solved by sorting the items by non-increasing efficiency: the items before the split item are selected, the split item is taken fractionally, the others are discarded.
-
The dual of \(\mathrm{LP}_{\mathrm{KP}}\) has the optimal solution \(\tilde{\pi} = p_s/w_s\), and \(z(\mathrm{LP}_{\mathrm{KP}})\) is never larger than twice \(z(\mathrm{ILP}_{\mathrm{KP}})\).
-
Rounding down \(z(\mathrm{LP}_{\mathrm{KP}})\) gives the Dantzig bound; the Martello-Toth bound considers separately the split item out and in.
-
Each variant of Chapter 2 «Knapsack problems» changes one ingredient of the \(\mathrm{ILP}_{\mathrm{KP}}\) model: integer variables (BKP, UKP), one capacity constraint per dimension (MDKP), one variable per item and knapsack (MKP), one equality per class (MCKP), setup variables \(y_h\) with \(x_j \le y_h\) (KPS); the SSP is the KP with \(p_j = w_j\).
Dashboard of Example 9.1. Upper bounds on \(z(\mathrm{ILP}_{\mathrm{KP}})\) computed in this chapter:
| Bound | Value | From |
|---|---|---|
| First relaxation | \(27\) | \(z(\mathrm{LP}\text{-}0_{\mathrm{KP}})\), item \(1\) with \(\tfrac{9}{2}\) copies |
| Second relaxation | \(\tfrac{49}{3}\) | \(z(\mathrm{LP}_{\mathrm{KP}})\), split item \(s=3\) |
| Dantzig bound | \(16\) | \(\lfloor \tfrac{49}{3} \rfloor\) |
| Martello-Toth bound | \(16\) | \(\max\{16, 15\}\) |
| Optimal value | \(15\) | solution \(\{1,4\}\) of the \(\mathrm{ILP}_{\mathrm{KP}}\) model |
The gap between the best upper bound (\(16\)) and the optimal value (\(15\)) is closed by the exact algorithms of the following chapters.
Exercises on this chapter: Knapsack problems