10.2 An ILP model for the Bin Packing Problem¶
Part 2 · Formulations and their properties · Chapter 10 · Chapter 10: Packing problems · Lecture notes, volume 2 (PDF) · Slides · Exercises: Packing problems
The problem of this section is the Bin Packing Problem (BPP), defined in Chapter 3 «Packing problems».
-
Given an upper bound \(m \in \Z_{\ge 2}\) on the number of bins used in any optimal BPP solution, we introduce the following \(mn\) binary variables:
\[ x_{jb} = \begin{cases} 1 & \text{if item } j \text{ is packed in bin } b \\ 0 & \text{otherwise} \end{cases} \qquad \forall j \in \underbrace{\{1,2,\dots,n\}}_{=\mathscr{I}},~~ \forall b \in \underbrace{\{1,2,\dots,m\}}_{=\mathscr{B}}, \]and the following \(m\) binary variables:
\[ y_b = \begin{cases} 1 & \text{if bin } b \text{ is used} \\ 0 & \text{otherwise} \end{cases} \qquad \forall b \in \underbrace{\{1,2,\dots,m\}}_{=\mathscr{B}}. \]The number \(n\) of items is a valid upper bound on the minimum number of bins needed to pack all the items since, in the worst possible case, each item is packed in a different bin. Also the number of bins used in any feasible BPP solution is a valid upper bound.
Using these variables, an Integer Linear Programming (ILP) model for the Bin Packing Problem (BPP) reads as follows:
This ILP model is referred to as the \(\mathrm{ILP}_{\mathrm{BPP}}\) model.
-
Description of the objective function and constraints of the \(\mathrm{ILP}_{\mathrm{BPP}}\) model:
-
the linear objective function \(\eqref{obj_BPP}\) minimizes the total number of used bins;
-
constraints \(\eqref{cons1_BPP}\) ensure that each item is packed in exactly one bin, so that all items are packed (\(n\) linear constraints);
-
constraints \(\eqref{cons2_BPP}\) link the assignment variables with the activation variables and impose the capacity restrictions: if bin \(b\) is used, the weight of its items is at most \(c\); if it is not used, it contains no item (\(m\) linear constraints);
-
finally, constraints \(\eqref{cons4_BPP}\) and \(\eqref{cons3_BPP}\) define the variables of the ILP model.
-
Explanation of the link between the variables
-
If at least one item is packed in bin \(b\), then the bin is used. The logical implication is
\[ (x_{1b} {\tt ~OR~} x_{2b} {\tt ~OR~} \dots {\tt ~OR~} x_{nb}) ~~~ \Longrightarrow ~~~ y_b . \]Since \(w_j>0\), packing an item in bin \(b\) gives \(\sum_{j \in \mathscr{I}} w_j x_{jb} > 0\), and the constraint \(\sum_{j \in \mathscr{I}} w_j x_{jb} \le c\,y_b\) forces \(y_b=1\).
-
If bin \(b\) is not used, then it is empty. This is the contrapositive of the previous implication. For \(y_b=0\) the constraint reads \(\sum_{j \in \mathscr{I}} w_j x_{jb} \le 0\), and since \(w_j>0\) we obtain \(x_{jb}=0\) for every item \(j\).
-
If bin \(b\) is used, then it contains at least one item, but only in an optimal solution. The constraints do not impose it. However, if \(x_{jb}=0\) for all \(j\) and \(y_b=1\), setting \(y_b=0\) keeps all the constraints satisfied and decreases the objective value by one. Hence, in every optimal solution, empty bins are not counted as used.
Example 10.1: \(\mathrm{ILP}_{\mathrm{BPP}}\) model
We consider a bin of capacity \(c = 10\) and a set \(\mathscr{I} = \{1,2,3\}\) of \(3\) items (\(n=3\)), with the following item weights:
We refer to this BPP instance as Example 10.1.
The \(\mathrm{ILP}_{\mathrm{BPP}}\) model with \(m=3\) for this BPP instance is:
An optimal solution \({\tilde{\vet{x}}}(\mathrm{ILP}_{\mathrm{BPP}})\) is:
Another optimal solution, obtained by permuting the indices of bins \(1\) and \(2\), is:
The optimal value is:
The associated optimal solution of the BPP is given by the packing patterns
The optimal solution is not unique: also the packing patterns \(\{1\}\) and \(\{2,3\}\) use two bins.
10.3 A first Linear Programming relaxation¶
To obtain a Linear Programming (LP) relaxation of the \(\mathrm{ILP}_{\mathrm{BPP}}\) model, we relax constraints \(\eqref{cons4_BPP}\) and \(\eqref{cons3_BPP}\) with the following ones:
This LP model is referred to as the \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) model.
Example 10.2: \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) model
The \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) model for the BPP instance of Example 10.1 is:
An optimal solution \({\tilde{\vet{x}}}(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) is:
The optimal value \(z(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) is \(\frac{8}{5}\).
Accordingly, we have the lower bound:
and, since \(z(\mathrm{ILP}_{\mathrm{BPP}})\) is an integer, \(z(\mathrm{ILP}_{\mathrm{BPP}}) \ge \lceil \frac{8}{5} \rceil = 2\).
Using
-
a free dual variable \(\mu_j\) for each constraint \(\eqref{cons1_BPP}\) (\(j \in \mathscr{I}\))
-
a non-negative dual variable \(\pi_b\) for each constraint \(\eqref{cons2_BPP}\) (\(b \in \mathscr{B}\))
the dual model of the \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) model reads as follows:
This LP model is referred to as the dual \(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) model.
Example 10.3: \(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) model
The dual \(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) model for the BPP instance of Example 10.1 is:
An optimal solution \((\tilde{\vet{\mu}},\tilde{\vet{\pi}})\) of \(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) is:
The optimal value \(z(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}}))\) is \(\frac{8}{5}\).
Proposition 10.1
An optimal solution of the primal \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) model is:
and an optimal solution of the dual \(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) model is:
Corollary 10.2
The optimal value of the primal \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) and dual \(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) models is:
-
The proof proceeds in three steps:
-
We show that \(\eqref{PP}\) is a feasible solution for the primal \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) model;
-
We show that \(\eqref{DD}\) is a feasible solution for the dual \(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) model;
-
We show that both feasible solutions have the same objective function value.
Therefore, by LP Weak Duality, \(\eqref{PP}\) and \(\eqref{DD}\) are a pair of optimal primal and dual solutions.
-
Proof
-
1. For every \(j \in \mathscr{I}\), we have:
\[ \sum_{b \in \mathscr{B}} \tilde{x}_{jb} = \sum_{b \in \mathscr{B}} \frac{1}{m} = \frac{m}{m} = 1 \]thus constraints \(\eqref{cons1_BPP}\) are satisfied.
For every \(b \in \mathscr{B}\), we have:
\[ - \sum_{j \in \mathscr{I}} w_j \; \tilde{x}_{jb} + c \; \tilde{y}_b = - \sum_{j \in \mathscr{I}} w_j \; \frac{1}{m} + c \; \frac{\sum_{j \in \mathscr{I}} w_j}{m \; c} = 0 \]thus constraints \(\eqref{cons2_BPP}\) are satisfied.
We have \(\tilde{x}_{jb} \geq 0\) and \(\tilde{y}_b \geq 0\), for every \(j \in \mathscr{I}\) and every \(b \in \mathscr{B}\), thus constraints \(\eqref{cons4_BPP_LP}\) and \(\eqref{cons3_BPP_LP}\) are satisfied.
Therefore, \(\eqref{PP}\) provides a feasible solution for the primal \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) model.
-
2. For every \(b \in \mathscr{B}\) and every \(j \in \mathscr{I}\), we have:
\[ \tilde{\mu}_j - w_j \; \tilde{\pi}_b = \frac{w_j}{c} - \frac{w_j}{c} = 0 \]thus constraints \(\eqref{cons2_D}\) are satisfied.
For every \(b \in \mathscr{B}\), we have:
\[ c \; \tilde{\pi}_b = \frac{c}{c} = 1 \]thus constraints \(\eqref{cons1_D}\) are satisfied.
We have \(\tilde{\mu}_j \geq 0\) and \(\tilde{\pi}_b \geq 0\), for every \(b \in \mathscr{B}\) and every \(j \in \mathscr{I}\), thus constraints \(\eqref{cons3_D}\) and \(\eqref{cons4_D}\) are satisfied.
Therefore, \(\eqref{DD}\) provides a feasible solution for the dual \(D(\mathrm{LP}\text{-}0_{\mathrm{BPP}})\) model.
-
3. For the objective functions, we have:
\[ \sum_{b \in \mathscr{B}} \tilde{y}_b = \sum_{b \in \mathscr{B}} \frac{\sum_{j \in \mathscr{I}} w_j}{m \; c} = \frac{\sum_{j \in \mathscr{I}} w_j}{c} = \sum_{j \in \mathscr{I}} \tilde{\mu}_j \]thus the primal and dual objective function values are equal.
Therefore, by LP Weak Duality, \(\eqref{PP}\) and \(\eqref{DD}\) are a pair of optimal primal and dual solutions. □
- This is an alternative proof that does not rely on the dual formulation but instead reasons directly on the minimum objective function value imposed by the constraints.
Proposition 10.3
An optimal solution of the primal \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) model is:
and the optimal value is
Proof
Summing the capacity constraints \(\eqref{cons2_BPP}\) over all \(b\in\mathscr{B}\) gives
hence
Therefore every feasible solution of \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\) satisfies \(\eqref{eq:bpp-lb}\).
Now consider the point defined in \(\eqref{PP_alternative}\). For every \(j\in\mathscr{I}\), we have
so constraints \(\eqref{cons1_BPP}\) hold. Moreover, for every \(b\in\mathscr{B}\), we have
so constraints \(\eqref{cons2_BPP}\) hold with equality. Finally, constraints \(\eqref{cons4_BPP_LP}\) and \(\eqref{cons3_BPP_LP}\) are satisfied by construction. Hence the point defined in \(\eqref{PP_alternative}\) is a feasible solution for \(\mathrm{LP}\text{-}0_{\mathrm{BPP}}\).
The objective value of \(\eqref{PP_alternative}\) is
which matches the lower bound \(\eqref{eq:bpp-lb}\). Therefore the point \(\eqref{PP_alternative}\) is an optimal solution with objective value \(\eqref{VAL_alternative}\). □
10.4 A second Linear Programming relaxation¶
To obtain a Linear Programming (LP) relaxation of the \(\mathrm{ILP}_{\mathrm{BPP}}\) model, we relax constraints \(\eqref{cons4_BPP}\) and \(\eqref{cons3_BPP}\) with the following ones:
Example 10.4: \(\mathrm{LP}_{\mathrm{BPP}}\) model
The \(\mathrm{LP}_{\mathrm{BPP}}\) model for the BPP instance of Example 10.1 is:
An optimal solution \({\tilde{\vet{x}}}(\mathrm{LP}_{\mathrm{BPP}})\) is:
The optimal value \(z(\mathrm{LP}_{\mathrm{BPP}})\) is \(\frac{8}{5}\). Accordingly, we have the same lower bound as before.
Using
-
a free dual variable \(\mu_j\) for each constraint \(\eqref{cons1_BPP}\) (\(j \in \mathscr{I}\))
-
a non-negative dual variable \(\pi_b\) for each constraint \(\eqref{cons2_BPP}\) (\(b \in \mathscr{B}\))
-
a non-positive dual variable \(\lambda_b\) for each constraint \(\eqref{cons3_BPP_LP_LL}\) (\(b \in \mathscr{B}\))
the dual model of the \(\mathrm{LP}_{\mathrm{BPP}}\) model reads as follows:
Example 10.5: \(D(\mathrm{LP}_{\mathrm{BPP}})\) model
The \(D(\mathrm{LP}_{\mathrm{BPP}})\) model of Example 10.1 is:
The optimal value \(z(D(\mathrm{LP}_{\mathrm{BPP}}))\) is \(\frac{8}{5}\). An optimal solution \((\tilde{\vet{\mu}},\tilde{\vet{\pi}},\tilde{\vet{\lambda}})\) of \(D(\mathrm{LP}_{\mathrm{BPP}})\) is:
-
The constraints:
\[ x_{jb} \le 1, \qquad \forall j \in \mathscr{I},\; \forall b \in \mathscr{B}, \]are also valid since, for every \(j \in \mathscr{I}\) and every \(b \in \mathscr{B}\), we have:
\[ x_{jb} \in \{0,1\} ~~~~~\Rightarrow~~~~~ x_{jb} \le 1 \]but they are implied by constraints \(\eqref{cons1_BPP}\).
Proposition 10.4
An optimal solution of the primal \(\mathrm{LP}_{\mathrm{BPP}}\) model is:
and an optimal solution of the dual \(D(\mathrm{LP}_{\mathrm{BPP}})\) model is:
Corollary 10.5
The optimal value of the primal \(\mathrm{LP}_{\mathrm{BPP}}\) and dual \(D(\mathrm{LP}_{\mathrm{BPP}})\) models is:
Proof
The proof is similar to the previous one. In addition, it is necessary to observe that
since \(\sum_{j} w_j / c \le z(\mathrm{ILP}_{\mathrm{BPP}}) \le m\), where the last inequality holds because \(m\) is an upper bound on the number of bins in any optimal BPP solution. Accordingly, constraints \(\eqref{cons3_BPP_LP_LL}\) are also satisfied. □
10.4.1 Some important theoretical properties¶
- The following two propositions show that the ratio between \(z(\mathrm{LP}_{\mathrm{BPP}})\) and \(z(\mathrm{ILP}_{\mathrm{BPP}})\) is at least one half for every BPP instance (by hypothesis \(z(\mathrm{ILP}_{\mathrm{BPP}}) >1\) since not all items fit in a single bin). Furthermore, there exist instances for which the value one half can be asymptotically achieved as the capacity \(c \to +\infty\).
Proposition 10.6
For every BPP instance, we have:
Proof
Consider an optimal solution \(\tilde{\vet{x}}(\mathrm{ILP}_{\mathrm{BPP}})\) of value \(z=z(\mathrm{ILP}_{\mathrm{BPP}})\) (number of used bins). We can assume, without loss of generality, that bins \(1,2,\dots,z\) are the non-empty ones.
In an optimal solution, no two bins can have total item weight at most \(c/2\), since otherwise their contents could be merged into a single bin without exceeding the bin capacity \(c\) (contradicting optimality).
If all non-empty bins have total item weight greater than \(c/2\), then
Otherwise, suppose that there exists a bin with total item weight at most \(c/2\). Renumbering bins if necessary, let it be bin \(z\), so that
Since \(z>1\), there exists another bin say bin 1; by optimality, we must have
and, by optimality, every bin in \(\{2,3,\dots,z-1\}\) has total item weight \(>c/2\). Hence,
□
Proposition 10.7
There are BPP instances such that:
Proof
Given \(\vartheta \in \Z_{\ge 1}\), consider the BPP instance with bin capacity \(c = 2\vartheta\) and \(n\) items having the following weights:
No bin can contain more than one item, thus each item must be packed alone in its own bin. Therefore, the BPP optimal value is
For the LP relaxation we have:
It follows that:
Accordingly, we conclude that:
□
- The following two propositions show that the ratio between \(\lceil z(\mathrm{LP}_{\mathrm{BPP}}) \rceil\) and \(z(\mathrm{ILP}_{\mathrm{BPP}})\) is at least one half for every BPP instance. Furthermore, there exist instances for which the value one half can be asymptotically achieved as the number of items \(n \to +\infty\).
Proposition 10.8
For every BPP instance, we have:
Proof
Consider an optimal solution \(\tilde{\vet{x}}(\mathrm{ILP}_{\mathrm{BPP}})\) of value \(z=z(\mathrm{ILP}_{\mathrm{BPP}})\) (number of used bins). We can assume, without loss of generality, that bins \(1,2,\dots,z\) are the non-empty ones.
In an optimal solution, no two bins can have total item weight at most \(c/2\), since otherwise their contents could be merged into a single bin without exceeding the bin capacity \(c\) (contradicting optimality).
If all non-empty bins have total item weight greater than \(c/2\), then
Otherwise, suppose that there exists a bin with total item weight at most \(c/2\). Renumbering bins if necessary, let it be bin \(z\). Then we have:
Since \(z\) must be an integer, this implies:
Therefore:
□
Proposition 10.9
There are BPP instances such that:
Proof
Given \(n \in \Z_{\ge 2}\) (take \(n\) even), consider the BPP instance with bin capacity \(c=n\) and \(n\) items having the following weights:
No bin can contain more than one item, since \(w_j>c/2\) for every \(j\). Thus each item must be packed alone in its own bin. Therefore, the BPP optimal value is
For the LP relaxation we have:
hence \(\lceil z(\mathrm{LP}_{\mathrm{BPP}})\rceil=\frac{n}{2}+1\) (since \(n\) is even). It follows that:
Accordingly, we conclude that:
□