Graph Coloring¶
This page explains how to solve the graph coloring problem using Amplify
The graph coloring problem is a problem of assigning colors to the vertices of a certain graph under
given constraints. The most typical problem is to color a graph so that the adjacent vertices have
different colors.
In a plane graph (map), the
four color theorem <https://en.wikipedia.org/wiki/Four_color_theorem>
_ states that
four
colors are enough to color any map so that all adjacent regions in the map have distinct colors.
However,
it is not obvious how to implement such coloring.
Several application examples are known for the graph coloring problem, such as scheduling problems
related to allocation of conference rooms, machines, tasks, etc., register allocation by a compiler,
frequency allocation in a mobile phone network. Here, we demonstrate a way to solve a graph coloring
problem using an Ising machine by coloring the prefectures in Japan.
In order to use Ising machines, we consider how to express the states of the coloring of the graph in
terms of binary variables. It can be expressed by assigning $0$ or $1$ to each region using four
variables
as follows:
Region |
Red |
Green |
Blue |
Yellow |
1 |
0 |
0 |
1 |
0 |
2 |
0 |
1 |
0 |
0 |
3 |
0 |
0 |
1 |
0 |
4 |
1 |
0 |
0 |
0 |
This example means assigning blue to region $1$, green to region $2$, blue to region $3$, and red to
region $4$. We will represent each variable in the above table as $q_{i,c}$ using the region index $i$
and
the color index $c$. Therefore, the number of variables required is $NC$ for the number of regions $N$
and
the number of colors $C$.
The following constraints are imposed on the variables accordingly to the definition of the coloring
problem.
- Paint one region with one color
- Adjacent regions must have distinct colors
When these are formulated, they are expressed as follows:
Constraints
$$
\begin{align}
\sum_{c = 0}^{C-1}{ q_{i,c} } = 1 & \quad \text{for all} \; i \\
q_{i,c} q_{j,c} = 0 & \quad \text{if Region} \; i \; \text{and Region} \; j \; \text{are adjacent}
\end{align}
$$
Here, $E$ represents a set of pairs of adjacent regions on the graph. Please note that the variable
index
starts at $0$ for the convenience of later program coding.