Below, let $N$ be the number of vertices in the graph $G$. Also, recall that the number of colors was
$K$.
Decision variables¶
Let us use a $N \times K$ binary decision variable table $q$, where 0 and 1 denote which color to
paint
each vertex with. That is, $q_{v, k} = 1$ when vertex $v$ is painted with color $k$.
For example, when painting a vertex as follows, the corresponding binary variable table $q$ will look
like the table below.
Index of vertex |
0 |
1 |
2 |
3 |
4 |
5 |
Index of color |
0 |
1 |
2 |
0 |
1 |
2 |
$q$ |
Color 0 |
Color 1 |
Color 2 |
Vertex 0 |
1 |
0 |
0 |
Vertex 1 |
0 |
1 |
0 |
Vertex 2 |
0 |
0 |
1 |
Vertex 3 |
1 |
0 |
0 |
Vertex 4 |
0 |
1 |
0 |
Vertex 5 |
0 |
0 |
1 |
Objective function¶
In this problem, we only need one solution that satisfies the condition, so we do not consider
objective
function.
Constraints¶
For $q$ to correspond to painting colors that satisfy the painting rule, the following conditions
must be
satisfied.
- Condition 1: Each vertex is painted with exactly one color. That is, each row of $q$ has exactly
one
$1$.
- Condition 2: Two vertices connected by an edge are not painted with the same color.
Condition 1 is a one-hot constraint on each row of $q$, so,
$$
\sum_{k = 0}^{K - 1} q_{v, k} = 1 \quad\text{for}\quad v \in V.
$$
Here, $V$ is the vertex set of $G$.
The condition 2 is that the two vertices $(u, v)$ comprising the edge $E$ of $G$ have different
colors,
and written as
$$
q_{u, k} q_{v, k} = 0 \quad\text{for}\quad (u, v) \in E, \ k \in \{0, 1, \ldots, K-1\}.
$$
Here, $E$ is the edge set of $G$.
If $q$ satisfies conditions 1 and 2, then $q$ corresponds to how to color the graph that satisfies
the
conditions.