9.6 An ILP model for the Subset Sum Problem¶
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 Subset Sum Problem and its reference instance (Example 2.2) are defined in Chapter 2 «Knapsack problems», Section 2.3.
-
We introduce the following \(n\) binary variables:
\[\begin{equation*} \label{BIN_VAR_SSP} x_j = \left\{ \begin{array}{ll} 1 & \textrm{if item $j$ is selected in the subset}\\[1.5ex] 0 & \textrm{otherwise} \end{array} \qquad \forall j \in \mathscr{I}. \right. \tag{9.20} \end{equation*}\]
Using these variables, an Integer Linear Programming (ILP) model for the Subset Sum Problem (SSP) reads as follows:
This ILP model is referred to as the \(\mathrm{ILP}_{\mathrm{SSP}}\) model.
-
Description of the objective function and constraints of the \(\mathrm{ILP}_{\mathrm{SSP}}\) model:
-
the linear objective function \(\eqref{obj_SSP}\) maximizes the total weight of the items selected in the subset;
-
constraint \(\eqref{cons1_SSP}\) ensures that the total weight of the selected items does not exceed the target value (one linear constraint);
-
finally, constraints \(\eqref{cons2_SSP}\) define the variables of the ILP model.
-
-
The \(\mathrm{ILP}_{\mathrm{SSP}}\) model is the \(\mathrm{ILP}_{\mathrm{KP}}\) model with \(p_j = w_j\), for every \(j \in \mathscr{I}\): the answer to the SSP is yes if and only if \(z(\mathrm{ILP}_{\mathrm{SSP}}) = c\).
Example 9.10: \(\mathrm{ILP}_{\mathrm{SSP}}\) model
We consider a target value \(c = 9\) and a set \(\mathscr{I} = \{1,2,3,4,5,6\}\) of \(6\) items (\(n = 6\)), with the following weights:
This is the SSP instance of Example 2.2. The \(\mathrm{ILP}_{\mathrm{SSP}}\) model for this SSP instance is:
An optimal solution \(~{\tilde{\vet x}}(\mathrm{ILP}_{\mathrm{SSP}})\) is:
The optimal value \(z(\mathrm{ILP}_{\mathrm{SSP}})\) is \(9 = c\), so the answer to the SSP is yes. The associated subset is \(\tilde{S} =\{1,4\}\). The optimal solution is not unique: the subsets \(\{2,3\}\) and \(\{6\}\) also reach the target value.