11.2 An ILP model for the Vertex Coloring Problem¶
Part 2 · Formulations and their properties · Chapter 11 · Chapter 11: Coloring problems · Lecture notes, volume 2 (PDF) · Slides · Exercises: Coloring problems
The Vertex Coloring Problem and its assumptions are defined in Chapter 4 «Coloring problems», Section 4.2.
-
Given a graph \(G=(V,E)\), for a vertex \(v \in V\) we denote by \(\delta(v)\) the set of the edges incident to \(v\).
-
Given an upper bound \(k \in \Z_{\ge 2}\) on the number of colors used in any optimal VCP solution, we introduce the following \(k\;\underbrace{|V|}_{=n}\) binary variables:
\[\begin{equation*} x_{vc} = \begin{cases} 1 & \text{if vertex } v \text{ takes color } c, \\ 0 & \text{otherwise} \end{cases} \qquad \forall v \in \underbrace{\{1,2,\dots,n\}}_{=V},~\forall c \in \underbrace{\{1,2,\dots,k\}}_{=\mathscr{C}}, \tag{11.1} \end{equation*}\]and the following \(k\) binary variables:
\[\begin{equation*} y_{c} = \begin{cases} 1 & \text{if color } c \text{ is used}, \\ 0 & \text{otherwise} \end{cases} \qquad \forall c \in \underbrace{\{1,2,\dots,k\}}_{=\mathscr{C}}. \tag{11.2} \end{equation*}\]The number \(n\) of vertices is a valid upper bound on the minimum number of colors needed to color all the vertices since, in the worst possible case, each vertex takes a different color. Also the number of colors used in any feasible VCP solution is a valid upper bound.
Using these variables, an Integer Linear Programming (ILP) model for the Vertex Coloring Problem (VCP) reads as follows:
This ILP model is referred to as the \(\mathrm{ILP}_{\mathrm{VCP}}\) model.
-
Description of the objective function and constraints of the \(\mathrm{ILP}_{\mathrm{VCP}}\) model:
-
the linear objective function \(\eqref{obj_VCP}\) minimizes the total number of used colors;
-
constraints \(\eqref{cons1_VCP}\) ensure that each vertex takes exactly one color (\(n\) linear constraints);
-
constraints \(\eqref{cons2_VCP}\) ensure that, for each color and each edge, the two adjacent vertices cannot both take that color, and that an unused color is taken by no vertex (\(k \; \underbrace{|E|}_{=m}\) linear constraints);
-
finally, constraints \(\eqref{cons4_VCP}\) and \(\eqref{cons3_VCP}\) define the variables of the ILP model.
-
Explanation of the link between the variables
-
If color \(c\) is assigned to a vertex, then it is used. The logical implication is
\[ (x_{1c} {\tt ~OR~} x_{2c} {\tt ~OR~} \dots {\tt ~OR~} x_{nc}) ~~~ \Longrightarrow ~~~ y_c . \]Every vertex has an incident edge \(\{u,v\}\), and the constraint \(x_{uc}+x_{vc} \le y_c\) forces \(y_c=1\) as soon as \(x_{vc}=1\).
-
If color \(c\) is not used, then no vertex takes it. This is the contrapositive of the previous implication. For \(y_c=0\) the edge constraint gives \(x_{uc}=x_{vc}=0\) for every edge \(\{u,v\}\in E\).
-
If color \(c\) is used, then some vertex takes it, but only in an optimal solution. The constraints do not impose it. However, if \(x_{vc}=0\) for all \(v\) and \(y_c=1\), setting \(y_c=0\) keeps all the constraints satisfied and decreases the objective value by one. Hence, in every optimal solution, unused colors are not counted.
Example 11.1: \(\mathrm{ILP}_{\mathrm{VCP}}\) model
We consider the following graph \(G = (V,E)\) with \(3\) vertices (\(n=3\)) and \(3\) edges (\(m=3\)):
The vertex set \(V\) and the edge set \(E\) are:
We refer to this VCP instance as Example 11.1.
The \(\mathrm{ILP}_{\mathrm{VCP}}\) model with \(k=3\) for this instance is:
An optimal solution \({\tilde{\vet x}}(\mathrm{ILP}_{\mathrm{VCP}})\) is:
The optimal value \(z(\mathrm{ILP}_{\mathrm{VCP}})\) is \(3\).
The associated optimal solution of the VCP is given by the color classes \(\tilde{Q}_1 =\{1\}\), \(\tilde{Q}_2 =\{2\}\) and \(\tilde{Q}_3 =\{3\}\). The optimal partition is unique, but the \(3!\) permutations of the colors give \(6\) different optimal solutions.
11.3 A first Linear Programming relaxation¶
To obtain a Linear Programming (LP) relaxation of the \(\mathrm{ILP}_{\mathrm{VCP}}\) model, we relax constraints \(\eqref{cons4_VCP}\) and \(\eqref{cons3_VCP}\) with the following ones:
Example 11.2: \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) model
The \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) model for the VCP instance of Example 11.1 is:
An optimal solution \({\tilde{\vet x}}(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) is:
The optimal value \(z(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) is \(2\).
Accordingly we have the lower bound:
Using
-
a free dual variable \(\mu_v\) for each constraint \(\eqref{cons1_VCP}\) (\(v \in V\))
-
a non-negative dual variable \(\pi_{ce}\) for each constraint \(\eqref{cons2_VCP}\) (\(c \in \mathscr{C},~e =\{u,v\} \in E\))
the dual model of the \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) model reads as follows:
Example 11.3: \(D(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) model
The dual \(D(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) model for the VCP instance of Example 11.1 is:
The optimal value \(z(D(\mathrm{LP}\text{-}0_{\mathrm{VCP}}))\) is \(2\). An optimal solution \((\tilde{\vet{\mu}},\tilde{\vet{\pi}})\) of \(D(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) is:
Proposition 11.1
An optimal solution of the primal \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) model is:
and an optimal solution of the dual \(D(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) model is:
Corollary 11.2
The optimal value of the primal \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) and dual \(D(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) models is:
-
The proof proceeds in three steps:
-
We show that (11.6) is a feasible solution for the primal \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) model;
-
We show that (11.7) is a feasible solution for the dual \(D(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) model;
-
We show that both feasible solutions have the same objective function value.
Therefore, by LP Weak Duality, (11.6) and (11.7) are a pair of optimal primal and dual solutions.
-
Proof
-
1. For every \(v \in V\), we have:
\[ {\sum_{c \in \mathscr{C}} \tilde{x}_{vc}} = \frac{1}{2}+\frac{1}{2} = 1 \]Thus constraints \(\eqref{cons1_VCP}\) are satisfied.
For \(c \in \{1,2\}\) and every \(\{u,v\} \in E\), we have:
\[ \tilde{y}_c - \tilde{x}_{uc} - \tilde{x}_{vc} = 1 -\frac{1}{2} -\frac{1}{2} = 0 \]and for \(c \in \{3,4,\dots,k\}\) we have \(\tilde{y}_c - \tilde{x}_{uc} - \tilde{x}_{vc} = 0-0-0=0\). Thus constraints \(\eqref{cons2_VCP}\) are satisfied.
We have \(\tilde{x}_{vc} \geq 0\) and \(\tilde{y}_c \geq 0\), for every \(v \in V\) and every \(c \in \mathscr{C}\), thus constraints \(\eqref{cons4_VCP_LP}\) and \(\eqref{cons3_VCP_LP}\) are satisfied.
Therefore, (11.6) provides a feasible solution for the primal \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) model.
-
2. For every \(c\in\mathscr{C}\), we have:
\[ \sum_{e \in E} \tilde{\pi}_{ce} = 1 \]Thus constraints \(\eqref{cons1_D}\) are satisfied.
For every \(c\in\mathscr{C}\) and \(w \in \{u,v\}\), we have:
\[ \tilde{\mu}_{w} - \sum_{e \in \delta(w)} \tilde{\pi}_{ce} = 1 - 1 =0 \]For every \(c\in\mathscr{C}\) and \(w \in V\setminus\{u,v\}\), we have \(\tilde{\mu}_w=0\) and \(\tilde{\pi}_{ce}=0\) for every \(e\in\delta(w)\) (since \(\tilde\pi_{ce}\) is nonzero only for \(e=\{u,v\}\), which is not incident to \(w\)), so
\[ \tilde{\mu}_{w} - \sum_{e \in \delta(w)} \tilde{\pi}_{ce} = 0 - 0 =0. \]Thus the constraints \(\eqref{cons2_D}\) are satisfied.
We have \(\tilde{\mu}_{v} \ge 0,~ \forall v \in V\) and \(\tilde{\pi}_{ce} \ge 0\) for every \(c \in \mathscr{C}\) and every \(e \in E\). Thus constraints \(\eqref{cons3_D}\) and \(\eqref{cons4_D}\) are satisfied.
Therefore, (11.7) provides a feasible solution for the dual \(D(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) model.
-
3. For the objective functions we have:
\[\begin{align*} {\sum_{c \in \mathscr{C}} \tilde{y}_c} = 1 + 1 = \sum_{v \in V} \tilde{\mu}_{v} \end{align*}\]thus the primal and dual objective function values are equal.
Therefore, by LP Weak Duality, (11.6) and (11.7) 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 11.3
An optimal solution of the primal \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) model is:
and the optimal value is
Proof
Summing the edge constraints \(\eqref{cons2_VCP}\) over all \(c\in\mathscr{C}\), for any edge \(\{u,v\}\in E\), gives
hence
Therefore every feasible solution of \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\) satisfies \(\eqref{eq:vcp-lb}\).
Now consider the point defined in (11.9). For every \(v\in V\), we have
so constraints \(\eqref{cons1_VCP}\) hold. Moreover, for every \(\{u,v\}\in E\) and \(c\in\{1,2\}\),
so constraints \(\eqref{cons2_VCP}\) hold with equality, while for all \(c\ge 3\) both sides are zero. Finally, constraints \(\eqref{cons4_VCP_LP}\) and \(\eqref{cons3_VCP_LP}\) are satisfied by construction. Hence the point defined in (11.9) is a feasible solution for \(\mathrm{LP}\text{-}0_{\mathrm{VCP}}\).
The objective value of (11.9) is
which matches the lower bound \(\eqref{eq:vcp-lb}\). Therefore the point (11.9) is an optimal solution with objective value \(\eqref{VAL_alternative}\). □
11.4 A second Linear Programming relaxation¶
To obtain a Linear Programming (LP) relaxation of the \(\mathrm{ILP}_{\mathrm{VCP}}\) model, we relax constraints \(\eqref{cons4_VCP}\) and \(\eqref{cons3_VCP}\) with the following ones:
Example 11.4: \(\mathrm{LP}_{\mathrm{VCP}}\) model
The \(\mathrm{LP}_{\mathrm{VCP}}\) model for the VCP instance of Example 11.1 is:
An optimal solution \({\tilde{\vet x}}(\mathrm{LP}_{\mathrm{VCP}})\) is:
The optimal value \(z(\mathrm{LP}_{\mathrm{VCP}})\) is \(2\). Accordingly we have the same lower bound.
Using
-
a free dual variable \(\mu_v\) for each constraint \(\eqref{cons1_VCP}\) (\(v \in V\))
-
a non-negative dual variable \(\pi_{ce}\) for each constraint \(\eqref{cons2_VCP}\) (\(c \in \mathscr{C},~e =\{u,v\} \in E\))
-
a non-positive dual variable \(\lambda_c\) for each constraint \(\eqref{cons3_VCP_LP_LL}\) (\(\forall c \in \mathscr{C}\))
the dual model of the \(\mathrm{LP}_{\mathrm{VCP}}\) model reads as follows:
Example 11.5: \(D(\mathrm{LP}_{\mathrm{VCP}})\) model
The dual \(D(\mathrm{LP}_{\mathrm{VCP}})\) model for the VCP instance of Example 11.1 is:
The optimal value \(z(D(\mathrm{LP}_{\mathrm{VCP}}))\) is \(2\). An optimal solution \((\tilde{\vet{\mu}},\tilde{\vet{\pi}},\tilde{\vet{\lambda}})\) of \(D(\mathrm{LP}_{\mathrm{VCP}})\) is:
-
The constraints:
\[ x_{vc} \le 1,\qquad \qquad \forall v \in V,\forall c \in \mathscr{C}, \]are also valid since, for every \(v \in V\) and every \(c \in \mathscr{C}\), we have:
\[ x_{vc} \in \{0,1\} ~~~~~\Rightarrow~~~~~ x_{vc} \le 1 \]but they are implied by constraints \(\eqref{cons1_VCP}\).
Proposition 11.4
An optimal solution of the primal \(\mathrm{LP}_{\mathrm{VCP}}\) model is:
and an optimal solution of the dual \(D(\mathrm{LP}_{\mathrm{VCP}})\) model is:
Proof
The proof is similar to the previous one. In addition it is necessary to observe that:
Accordingly, also constraints \(\eqref{cons3_VCP_LP_LL}\) are satisfied. □
Corollary 11.5
The optimal value of the primal \(\mathrm{LP}_{\mathrm{VCP}}\) and dual \(D(\mathrm{LP}_{\mathrm{VCP}})\) models is:
11.5 Typical mistakes¶
Warning
-
Choosing \(k\) too small. The number \(k\) of colors must be at least the chromatic number of the graph: with fewer colors the model has no feasible solution. The value \(k=n\) is always valid.
-
Trusting the LP bound. The optimal value of both relaxations is \(2\) for every graph with at least one edge, even for the complete graph on \(n\) vertices, whose optimal value is \(n\).
-
Believing that the model counts only the colors that are really used. The constraints allow \(y_c=1\) for a color that no vertex takes: it is the objective function that switches such colors off.
-
Ignoring the symmetry. Permuting the colors of an optimal solution gives another optimal solution: a coloring that uses \(q\) of the \(k\) colors has \(k!/(k-q)!\) equivalent copies in the \(\mathrm{ILP}_{\mathrm{VCP}}\) model (\(k!\) when it uses all the colors).
-
Writing the dual solution with a wrong edge. The dual values \(\tilde{\pi}_{ce}\) are non-zero only for one edge \(e=\{u,v\}\), and for every color \(c\): all the other edges have value zero.
11.6 In summary¶
In summary
-
The \(\mathrm{ILP}_{\mathrm{VCP}}\) model has \(k \cdot n\) variables \(x_{vc}\) (vertex \(v\) takes color \(c\)) and \(k\) variables \(y_c\) (color \(c\) is used); the edge constraints forbid equal colors on adjacent vertices.
-
The two LP relaxations have the same optimal value \(2\) for every graph with an edge: put \(\tfrac{1}{2}\) on two colors for all the vertices.
-
The dual solution selects one edge \(\{u,v\}\) and gives value \(1\) to \(\mu_u\), \(\mu_v\) and \(\pi_{c\{u,v\}}\) for every color.
-
The bound \(2\) is very weak: a formulation that must color graphs needs additional valid inequalities.
Dashboard of Example 11.1 (triangle). Bounds on \(z(\mathrm{ILP}_{\mathrm{VCP}})\) computed in this chapter:
| Bound | Value | From |
|---|---|---|
| First relaxation | \(2\) | \(z(\mathrm{LP}\text{-}0_{\mathrm{VCP}})\) |
| Second relaxation | \(2\) | \(z(\mathrm{LP}_{\mathrm{VCP}})\) |
| Optimal value | \(3\) | color classes \(\{1\}\), \(\{2\}\), \(\{3\}\) |
The gap between \(2\) and \(3\) is small here, but it grows with the size of the complete graph: \(2\) against \(n\).
Exercises on this chapter: Coloring problems