Generating a Graph Colouring Heuristic with Deep Q-Learning and Graph
  Neural Networks
The graph colouring problem consists of assigning labels, or colours, to the
vertices of a graph such that no two adjacent vertices share the same colour.
In this work we investigate whether deep reinforcement learning can be used to
discover a competitive construction heuristic for graph colouring. Our proposed
approach, ReLCol, uses deep Q-learning together with a graph neural network for
feature extraction, and employs a novel way of parameterising the graph that
results in improved performance. Using standard benchmark graphs with varied
topologies, we empirically evaluate the benefits and limitations of the
heuristic learned by ReLCol relative to existing construction algorithms, and
demonstrate that reinforcement learning is a promising direction for further
research on the graph colouring problem.
George Watkins, Giovanni Montana, Juergen Branke
# Generating a Graph Colouring Heuristic with Deep Q-Learning and Graph Neural Networks

###### Abstract

The graph colouring problem consists of assigning labels, or colours, to the vertices of a graph such that no two adjacent vertices share the same colour. In this work we investigate whether deep reinforcement learning can be used to discover a competitive construction heuristic for graph colouring. Our proposed approach, ReLCol, uses deep Q-learning together with a graph neural network for feature extraction, and employs a novel way of parameterising the graph that results in improved performance. Using standard benchmark graphs with varied topologies, we empirically evaluate the benefits and limitations of the heuristic learned by ReLCol relative to existing construction algorithms, and demonstrate that reinforcement learning is a promising direction for further research on the graph colouring problem.

Keywords:Graph Colouring Deep Reinforcement Learning Graph Neural Networks

## 1 Introduction

The Graph Colouring Problem (GCP) is among the most well-known and widely studied problems in graph theory [12]. Given a graph \(G\), a solution to GCP is an assignment of colours to vertices such that adjacent vertices have different colours; the objective is to find an assignment that uses the minimum number of colours. This value is called the _chromatic number_ of \(G\), and denoted \(\chi(G)\). GCP is one of the most important and relevant problems in discrete mathematics, with wide-ranging applications from trivial tasks like sudoku through to vital logistical challenges like scheduling and frequency assignment [1]. Given that GCP has been proven to be NP-Complete for general graphs [15], no method currently exists that can optimally colour any graph in polynomial time. Indeed it is hard to find even approximate solutions to GCP efficiently [28] and currently no algorithm with reasonable performance guarantees exists [22].

Many existing methods for GCP fall into the category of _construction heuristics_, which build a solution incrementally. Designing an effective construction heuristic is challenging and time-consuming and thus there has been a lot of interest in ways to generate heuristics _automatically_. This has previously been very successful in, for example, job shop scheduling [8]. Among the simplest
construction methods for GCP are _greedy algorithms_[25], in which vertices are selected one by one and assigned the 'lowest' permissible colour based on some pre-defined ordering of colours.

In this work we investigate the use of reinforcement learning (RL) to learn a greedy construction heuristic for GCP by framing the selection of vertices as a sequential decision-making problem. Our proposed algorithm, ReLCol, uses deep Q-learning (DQN) [30] together with a graph neural network (GNN) [33, 5] to learn a policy that selects the vertices for our greedy algorithm. Using existing benchmark graphs, we compare the performance of the ReLCol heuristic against several existing greedy algorithms, notably Largest First, Smallest Last and DSATUR. Our results indicate that the solutions generated by our heuristic are competitive with, and in some cases better than, these methods. As part of ReLCol, we also present an alternative way of parameterising the graph within the GNN, and show that our approach significantly improves performance compared to the standard representation.

## 2 Related Work

#### 2.0.1 Graph Colouring

Methods for GCP, as with other combinatorial optimisation (CO) problems, can be separated into exact solvers and heuristic methods. Exact solvers must process an exponentially large number of solutions to guarantee optimality; as such, they quickly become computationally intractable as the size of the problem grows [26]. Indeed exact algorithms are generally not able to solve GCP in reasonable time when the number of vertices exceeds 100 [31].

When assurances of optimality are not required, heuristic methods offer a compromise between good-quality solutions and reasonable computation time. Heuristics may in some cases produce optimal solutions, but offer no guarantees for general graphs. Considering their simplicity, greedy algorithms are very effective: even ordering the vertices at random can yield a good solution. And crucially, for every graph there exists a vertex sequence such that greedily colouring the vertices in that order will yield an optimal colouring [25].

Largest-First (LF), Smallest-Last (SL) and DSATUR [9] are the three most popular such algorithms [20], among which DSATUR has become the de facto standard for GCP [32]. As such, we have chosen these three heuristics as the basis for our comparisons. Both LF and SL are _static_ methods, meaning the vertex order they yield is fixed at the outset. LF chooses the vertices in decreasing order by degree; SL also uses degrees, but selects the vertex \(v\) with smallest degree to go last, and then repeats this process with the vertex \(v\) (and all its incident edges) removed. Conversely, DSATUR is a _dynamic_ algorithm: at a given moment the choice of vertex depends on the previously coloured vertices. DSATUR selects the vertex with maximum _saturation_, where saturation is the number of distinct colours assigned to its neighbours. Similarly, the Recursive Largest First algorithm [23] is dynamic. At each step it finds a maximal independent set and assigns the same colour to the constituent vertices. The coloured vertices are then removed from the graph and the process repeats.
_Improvement algorithms_ take a different approach: given a (possibly invalid) colour assignment, these methods use local search to make small adjustments in an effort to improve the colouring, either by reducing the number of colours used or eliminating conflicts between adjacent vertices. Examples include TabuCol [17], simulated annealing [2] and evolutionary algorithms [14].

#### 2.0.2 Machine Learning methods for CO problems

Given how difficult it is to solve CO problems exactly, and the reliance on heuristics for computationally tractable methods, machine learning appears to be a natural candidate for addressing problems like GCP. Indeed there are many examples of methods for CO problems that use RL [29, 4, 19] or other machine learning techniques [35, 6].

For GCP, supervised learning has been used to predict the chromatic number of a graph [24] but this is dependent on having a labelled training dataset. Given the computational challenges inherent in finding exact solutions, this imposes limitations on the graphs that can be used for training. Conversely, RL does not require a labelled dataset for training. In [41], RL is used to support the local search component of a hybrid method for the related \(k\)-GCP problem by learning the probabilities with which each vertex should be assigned to each colour. While iteratively solving \(k\)-GCP for decreasing values of \(k\) is a valid (and reasonably common) method for solving GCP [27, 14], it is inefficient.

On the other hand, [18] addresses GCP directly with a method inspired by the success of AlphaGo Zero [34]. In contrast to greedy algorithms, this approach uses a pre-determined vertex order and learns the mechanism for deciding the _colours_. During training they use a computationally demanding Monte Carlo Tree Search using 300 GPUs; due to the computational overhead and lack of available code we were unable to include this algorithm in our study.

Our proposed algorithm is most closely related to [16], in which the authors present a greedy construction heuristic that uses RL with an attention mechanism [37] to select the vertices. There are, however, several key differences between the two methods. Their approach uses the REINFORCE algorithm [40] whereas we choose DQN [30] because the action space is discrete; they incorporate spatial and temporal locality biases; and finally, we use a novel state parameterisation, which we show improves the performance of our algorithm.

## 3 Problem Definition

A _\(k\)-colouring_ of a graph \(G=(V,E)\) is a partition of the vertices \(V\) into \(k\) disjoint subsets such that, for any edge \((u,v)\in E\), the vertices \(u\) and \(v\) are in different subsets. The subsets are typically referred to as _colours_. GCP then consists of identifying, for a given graph \(G\), the minimum number of colours for which a \(k\)-colouring exists and the corresponding colour assignment. This number is known as the _chromatic number_ of \(G\), denoted \(\chi(G)\).

Given any graph, a greedy construction heuristic determines the order in which vertices are to be coloured, sequentially assigning to them the lowest permissible colour according to some pre-defined ordering of colours. In this
work we address the problem of automatically deriving a greedy construction heuristic that colours general graphs using as few colours as possible.

## 4 Preliminaries

#### 4.0.1 Markov Decision Processes

A Markov Decision Process (MDP) is a discrete-time stochastic process for modelling the decisions taken by an agent in an environment. An MDP is specified by the tuple \((\mathcal{S},\mathcal{A},\mathcal{P},\mathcal{R},\gamma)\), where \(\mathcal{S}\) and \(\mathcal{A}\) represent the state and action spaces; \(\mathcal{P}\) describes the environment's transition dynamics; \(\mathcal{R}\) is the reward function; and \(\gamma\) is the discount factor. The goal of reinforcement learning is to learn a decision policy \(\pi:\mathcal{S}\rightarrow\mathcal{A}\) that maximises the expected sum of discounted rewards, \(\mathbb{E}\left[\sum_{t=1}^{\infty}\gamma^{t}R_{t}\right]\).

#### 4.0.2 Deep Q-Learning

Q-learning [38] is a model-free RL algorithm that learns \(Q^{*}(s,a)\), the value of taking action \(a\) in a state \(s\) and subsequently behaving optimally. Known as the _optimal action value function_, \(Q^{*}(s,a)\) is defined as

\[Q^{*}(s,a)=\mathbb{E}\left[\sum_{i=1}^{\infty}\gamma^{i}R_{t+i}\ \middle|\ S_{t}=s,A_{t}=a\right] \tag{1}\]

where \(S_{t},A_{t}\) and \(R_{t}\) are random variables representing respectively the state, action and reward at timestep \(t\). _Deep_ Q-learning (DQN) [30] employs a Q-network parameterised by weights \(\theta\) to approximate \(Q^{*}(s,a)\). Actions are chosen greedily with respect to their values with probability \(1-\epsilon\), and a random action is taken otherwise to facilitate exploration. Transitions \((s,a,r,s^{\prime})\) - respectively the state, action, reward and next state - are added to a buffer and the Q-network is trained by randomly sampling transitions, backpropagating the loss

\[L(\theta)=\left(\left[r+\gamma\max_{a^{\prime}}Q_{\hat{\theta}}(s^{\prime},a^{ \prime})\right]-Q_{\theta}(s,a)\right)^{2} \tag{2}\]

and updating the weights using stochastic gradient descent. Here \(Q_{\theta}(s,a)\) and \(Q_{\hat{\theta}}(s,a)\) are estimates of the value of state-action pair \((s,a)\) using the Q-network and a _target network_ respectively. The target network is a copy of the Q-network, with weights that are updated via periodic soft updates, \(\hat{\theta}\leftarrow\tau\theta+(1-\tau)\hat{\theta}\). Using the target network in the loss helps to stabilise learning [30].

#### 4.0.3 Graph Neural Networks

Graph neural networks (GNNs) [33, 5] support learning over graph-structured data. GNNs consist of blocks; the most general GNN block takes a graph \(G\) with vertex-, edge- and graph-level features, and outputs a new graph \(G^{\prime}\) with the same topology as \(G\) but with the features replaced by vertex-, edge- and graph-level embeddings [5]. The embeddings are generated via a message-passing and aggregation mechanism whereby information flows between pairs of neighbouring vertices. Stacking multiple GNN blocks allows for more complex dependencies to be captured. The steps within a single GNN block are demonstrated in Figure 1; in our method we do not use graph-level features so for simplicity these have been omitted.
## 5 Methodology

### Graph colouring as a Markov Decision Process

#### 5.1.1 States

A state \(s\in\mathcal{S}\) for graph \(G=(V,E)\) is a vertex partition of \(V\) into subsets \(P_{i}\), \(i\in\{-1,0,1,2,...\}\). For \(i\neq-1\), the partition \(P_{i}\) contains the vertices currently assigned colour \(i\), and \(P_{-1}\) represents the set of currently un-coloured vertices. States in which \(P_{-1}=\emptyset\) are terminal. Our method for parameterising the state, which results in improved performance, is described in Section 5.2.

#### 5.1.2 Actions

An action \(a\in\mathcal{A}\) is an un-coloured vertex (i.e. \(a\in P_{-1}\)) indicating the next vertex to be coloured. The complete mechanism by which ReLCol chooses actions is described in Section 5.4.

#### 5.1.3 Transition function

Given an action \(a\), the transition function \(\mathcal{P}:\mathcal{S}\times\mathcal{A}\to\mathcal{S}\) updates the state \(s\) of the environment to \(s^{\prime}\) by assigning the lowest permissible colour to vertex \(a\). Note that choosing colours in this way does not preclude finding an optimal colouring [25] as every graph admits a sequence that will yield an optimal colouring. The transition function \(\mathcal{P}\) is deterministic: given a state \(s\) and an action \(a\), there is no uncertainty in the next state \(s^{\prime}\).

#### 5.1.4 Reward function

For GCP, the reward function should encourage the use of fewer colours. As such our reward function for the transition \((s,s^{\prime})\) is defined as

\[\mathcal{R}(s,s^{\prime})=-1(C(s^{\prime})-C(s))\]

where \(C(s)\) indicates the number of colours used in state \(s\).

Figure 1: Demonstration of how a GNN block generates edge and vertex embeddings. Blue indicates the element that is updated in that step. _i)_ The input graph with edge and vertex features; _ii)_ For each edge \(e\), concatenate the features of \(e\) with the features of the vertices it connects, and pass the resulting vector through a small neural network to generate the edge embedding \(emb_{e}\); _iii)_ For each vertex \(v\), aggregate the embeddings of the incident edges using an elementwise operation like _sum_ or _max_ to generate the edge aggregation \(agg_{v}\); _iv)_ For each vertex \(v\), concatenate the features of \(v\) with the associated edge aggregation \(agg_{v}\), and pass the resulting vector through a small neural network to generate the vertex embedding \(emb_{v}\). Blocks can be stacked by repeating this process with the previous block’s edge and vertex embeddings used as the features.
#### 5.1.2 Discount factor

GCP is an episodic task, with an episode corresponding to colouring a single graph \(G\). Given that each episode is guaranteed to terminate after \(n\) steps, where \(n\) is the number of vertices in \(G\), we set \(\gamma=1\). Using \(\gamma<1\) would bias the heuristic towards deferring the introduction of new colours, which may be undesirable.

### Parameterising the state

Recall that for the graph \(G=(V,E)\), a state \(s\in\mathcal{S}\) is a partition of \(V\) into subsets \(P_{i}\), \(i\in\{-1,0,1,2,...\}\). We represent the state using a _state graph_\(G_{s}=(V,E_{s},F_{s}^{v},F_{s}^{e})\): respectively the vertices and edges of \(G_{s}\), together with the associated vertex and edge features.

#### 5.2.1 State graph vertices

Note that the vertices in \(G_{s}\) are the same as the vertices in the original graph \(G\). Then, given a state \(s\), the feature \(f_{s}^{v}\) of vertex \(v\) is a 2-tuple containing: i) A vertex name \(\in\{0,1,2,...,n-1\}\) and ii) The current vertex colour \(c_{v}\in\{-1,0,1,2,...\}\) (where \(c_{v}=-1\) if and only if \(v\) has not yet been assigned a colour).

#### 5.2.2 State graph edges

In the standard GNN implementation, messages are only passed between vertices that are joined by an edge. In our implementation we choose to represent the state as a complete graph on \(V\) to allow information to flow between all pairs of vertices. We use a binary edge feature \(f_{s}^{e}\) to indicate whether the corresponding edge was in the original graph \(G\):

\[f_{s}^{e}=\begin{cases}-1&\text{if }e=(v_{i},v_{j})\in E\\ 0&\text{otherwise}\end{cases}\]

Our state parameterisation, which is the input to the Q-network, allows messages to be passed between all pairs of vertices, including those that are not connected; in Section 6.4 we show that this representation results in improved performance.

### Q-network architecture

Our Q-network is composed of several stacked GNN blocks followed by a feed-forward neural network of fully connected layers with ReLU activations. Within the aggregation steps in the GNN we employ an adaptation of Principal Neighbourhood Aggregation [10] which has been shown to mitigate information loss. The GNN takes the state graph \(G_{s}\) as input, and returns a set of vertex embeddings. For each vertex \(v\), the corresponding embedding is passed through the fully connected layers to obtain the value for the action of choosing \(v\) next.
### Selecting actions

In general actions are selected using an \(\epsilon\)-greedy policy with respect to the vertices' values. However using the Q-network is (relatively) computationally expensive. As such, where it has no negative effect - in terms of the ultimate number of colours used - we employ alternative mechanisms to select vertices.

#### 5.4.1 First Vertex rule

The first vertex to be coloured is selected at random. By Proposition 1, this does not prevent an optimal colouring being found.

Proposition 1: _An optimal colouring remains possible regardless of the first vertex to be coloured._

**Proof.** Let \(G=(V,E)\) be a graph with \(\chi(G)=k^{*}\), and \(\mathcal{P}^{*}=P_{0}^{*},P_{1}^{*},...,P_{k^{*}-1}^{*}\) an optimal colouring of \(G\), where the vertices in \(P_{i}^{*}\) are all assigned colour \(i\). Suppose vertex \(v\) is the first to be selected, and \(j\) is the colour of \(v\) in \(\mathcal{P}^{*}\) (i.e. \(v\in P_{j}^{*}\), where \(0\leq j\leq k^{*}-1\)). Simply swap the labels \(P_{0}^{*}\) and \(P_{j}^{*}\) so that the colour assigned to \(v\) is the 'first' colour. Now, using this new partition, we can use the construction described in [25] to generate an optimal colouring. \(\blacksquare\)

#### 5.4.2 Isolated Vertices rule

We define a vertex to be _isolated_ if all of its neighbours have been coloured. By Proposition 2, we can immediately colour any such vertices without affecting the number of colours required.

Proposition 2: _Immediately colouring isolated vertices has no effect on the number of colours required to colour the graph._

**Proof.** Let \(G=(V,E)\) be a graph with \(\chi(G)=k^{*}\). Suppose also that \(\mathcal{P}=P_{-1},P_{0},P_{1},...,P_{k^{*}-1}\) is a partial colouring of \(G\) (with \(P_{-1}\) the non-empty set of un-coloured vertices). Let \(v\in P_{-1}\) be an un-coloured, isolated vertex (i.e. it has no neighbours in \(P_{-1}\)). No matter when \(v\) is selected, its colour will be the first that is different from all its neighbours. Also, given that \(v\) has no un-coloured neighbours, it has no influence on the colours assigned to subsequent vertices. Therefore \(v\) can be chosen at any moment (including immediately) without affecting the ultimate number of colours used. \(\blacksquare\)

### The ReLCol algorithm

Fig. 2 demonstrates how the state graph is constructed, and how it evolves as the graph is coloured. The full ReLCol algorithm is presented in Algorithm 1.

```
1:\(G=(V,E)\), \(\mathcal{P}=P_{0}^{*},P_{1}^{*},...,P_{k^{*}-1}^{*}\), \(P_{0}^{*},P_{1}^{*},.
#### 6.0.1 Architecture and hyperparameters

Our Q-network consists of 5 GNN blocks and 3 fully connected layers with weights initialised at random. Our GNN blocks use only edge and vertex features; we experimented with including global features but found no evidence of performance improvement. The vertex and edge embeddings, as well as the hidden layers in all fully connected neural networks, have 64 dimensions. We use the Adam optimiser [21] with learning rate 0.001 and batch size 64, \(\tau=0.001\), and an \(\epsilon\)-greedy policy for exploration, where \(\epsilon\) decays exponentially from 0.9 to 0.01 through 25000 episodes of training.

#### 6.0.2 Training data

We have constructed a dataset of 1000 training graphs of size \(n\in[15,50]\), composed of 7 different graph types: Leighton graphs [23], Queen graphs [13], Erdos-Renyi graphs [11], Watts-Strogatz graphs [39], Barabasi-Albert graphs [3], Gaussian Random Partition graphs [7] and graphs generated by our own method which constructs graphs with known upper bound on the chromatic number. Each training graph was constructed by choosing its type and size uniformly at random. Where the generating process of the chosen graph type has its own parameters these too were chosen at random to ensure as much diversity as possible amongst the training graphs. Our datasets, together with our code, are available on GitHub1.

Footnote 1: [https://github.com/gpdwatkins/graph_colouring_with_RL](https://github.com/gpdwatkins/graph_colouring_with_RL)

### Comparison with existing algorithms

We first compare ReLCol to existing construction algorithms, including Largest First, Smallest Last, DSATUR and Random (which selects the vertices in a random order). We also compare to the similar RL-based method presented in

Figure 2: Example of graph parameterisation and colouring rules, where \(v_{t}=j\) indicates the vertex with name \(j\) is selected at step _t. i)_ Initial parameterisation of the original graph; _ii)_ First vertex \(v_{0}=0\) is selected at random and assigned colour 0; _iii)_ Vertex \(v_{1}=4\) can also be assigned colour 0; _iv)_ Vertex \(v_{2}=3\) cannot be assigned colour 0 so takes colour 1; _v)_ Vertex \(v_{3}=2\) cannot be assigned colour 0 or 1 so takes colour 2, leaving vertex 1 isolated; vertex 1 cannot be assigned colour 0 so takes colour 1.
Gianinazzi et al. [16]. Using their implementation we generate 12 heuristics with different random seeds and report the average result. Note that in their paper the authors present both a deterministic and a stochastic heuristic, with the stochastic version generated by taking a softmax over the action weights. At test time their stochastic heuristic is run 100 times and the best colouring is returned. Given that with enough attempts even a random algorithm will eventually find an optimal solution, we consider heuristics that return a colouring in a single pass to be more interesting. As such we consider only the deterministic versions of the Gianinazzi et al. algorithm and ReLCol.

Each heuristic is applied to the benchmark graphs used in [24] and [16], which represent a subset of the graphs specified in the _COLOR02: Graph Colouring and its Generalizations_ series2. For these graphs the chromatic number is known; as such we report the _excess_ number of colours used by an algorithm (i.e. 0 would mean the algorithm has found an optimal colouring for a graph). The results are summarised in Table 6.1.

Footnote 2: [https://mat.tepper.cmu.edu/COLOR02/](https://mat.tepper.cmu.edu/COLOR02/)

On average over all the graphs DSATUR was the best performing algorithm, using 1.2 excess colours, closely followed by our heuristic with 1.35 excess colours. The other tested algorithms perform significantly worse on these graphs, even slightly worse than ordering the vertices at random. The test set contains a mix of easier graphs - all algorithms manage to find the chromatic number for huck - as well as harder ones - even the best algorithm uses four excess colours on queen13_13. DSATUR and ReLCol each outperform all other methods on 4 of the graphs.
### A class of graphs on which ReLCol outperforms DSATUR

Although the previous results suggest that ReLCol does not outperform DSATUR on general graphs, there do exist classes of graphs on which DSATUR is known to perform poorly. One such class is presented in [36]; these graphs, which we refer to as _Spinrad graphs_, are constructed as follows:

1. Fix the number of vertices \(n\) such that \(n\pmod{7}=3\), and let \(m=\frac{n+4}{7}\).
2. Partition the vertices into \(5\) disjoint sets as follows: \[A=\{a_{1},a_{2},\cdots,a_{m-2}\} B=\{b_{1},b_{2},\cdots,b_{m-1}\} C=\{c_{2},c_{3},\cdots,c_{m}\}\] \[B^{\prime}=\{b^{\prime}_{1},b^{\prime}_{2},\cdots,b^{\prime}_{2m }\} C^{\prime}=\{c^{\prime}_{1},c^{\prime}_{2},\cdots,c^{\prime}_{2m}\}\]
3. Add the following sets of edges: \[E^{B}_{A}=\{(a_{i},b_{j})\colon i\neq j\} E^{C}_{A}=\{(a_{i},c_{j})\colon i<j\} E^{C}_{B}=\{(b_{i-1},c_{i})\colon 2<i<m\}\] Plus: * \(\forall b\in B\), add edges to vertices in \(B^{\prime}\) such that the degree of \(b\) is \(2m\). * \(\forall c\in C\), add edges to vertices in \(C^{\prime}\) such that the degree of \(c\) is \(2m\).

\begin{table}
\begin{tabular}{|c c c c c c c c c|} \hline
**Graph** & \(n\) & \(\chi\) & **Random** & **LF** & **SL** & **DSATUR** & 
\begin{tabular}{c} **Gianinazzi** \\ **et al.** \\ \end{tabular} & **ReLCol** \\ \hline queen5\_5 & 25 & 5 & 2.3\({}^{\pm 0.1}\) & 2 & 3 & **0** & 2.1\({}^{\pm 0.3}\) & 0.2\({}^{\pm 0.11}\) \\ queen6\_6 & 36 & 7 & 2.4\({}^{\pm 0.06}\) & 2 & 4 & 2 & 3.2\({}^{\pm 0.16}\) & **1\({}^{\pm 0}\)** \\ myciel5 & 47 & 6 & 0.1\({}^{\pm 0.03}\) & 0 & 0 & 0 & 0.1\({}^{\pm 0.08}\) & 0\({}^{\pm 0}\) \\ queen7\_7 & 49 & 7 & 4\({}^{\pm 0.06}\) & 5 & 3 & 4 & 3.3\({}^{\pm 0.32}\) & **2.2\({}^{\pm 0.16}\)** \\ queen8\_8 & 64 & 9 & 3.4\({}^{\pm 0.07}\) & 4 & 5 & 3 & 3.3\({}^{\pm 0.24}\) & **2.1\({}^{\pm 0.14}\)** \\
1-Insertions\_4 & 67 & 4 & 1.2\({}^{\pm 0.04}\) & 1 & 1 & 1 & 1\({}^{\pm 0}\) & 1\({}^{\pm 0}\) \\ huck & 74 & 11 & 0\({}^{\pm 0}\) & 0 & 0 & 0 & 0\({}^{\pm 0}\) & 0\({}^{\pm 0}\) \\ jean & 80 & 10 & 0.3\({}^{\pm 0.05}\) & 0 & 0 & 0 & 0\({}^{\pm 0}\) & 0.3\({}^{\pm 0.12}\) \\ queen9\_9 & 81 & 10 & 3.9\({}^{\pm 0.07}\) & 5 & 5 & 3 & 5\({}^{\pm 0}\) & **2.7\({}^{\pm 0.25}\)** \\ david & 87 & 11 & 0.7\({}^{\pm 0.07}\) & 0 & 0 & 0 & 0.4\({}^{\pm 0.14}\) & 1.2\({}^{\pm 0.33}\) \\ mug88\_1 & 88 & 4 & 0.1\({}^{\pm 0.02}\) & 0 & 0 & 0 & 0\({}^{\pm 0}\) & 0\({}^{\pm 0}\) \\ myciel6 & 95 & 7 & 0.3\({}^{\pm 0.05}\) & 0 & 0 & 0 & 0.8\({}^{\pm 0.17}\) & 0\({}^{\pm 0}\) \\ queen8\_12 & 96 & 12 & 3.3\({}^{\pm 0.06}\) & 3 & 3 & **2** & 4\({}^{\pm 0}\) & 2.6\({}^{\pm 0.18}\) \\ games120 & 120 & 9 & 0\({}^{\pm 0.01}\) & 0 & 0 & 0 & 0\({}^{\pm 0}\) & 0\({}^{\pm 0}\) \\ queen11\_11 & 121 & 11 & 5.9\({}^{\pm 0.07}\) & 6 & 6 & **4** & 6\({}^{\pm 0}\) & 5.4\({}^{\pm 0.25}\) \\ anna & 138 & 11 & 0.2\({}^{\pm 0.04}\) & 0 & 0 & 0 & 0\({}^{\pm 0}\) & 0.4\({}^{\pm 0.18}\) \\
2-Insertions\_4 & 149 & 4 & 1.5\({}^{\pm 0.05}\) & 1 & 1 & 1 & 1\({}^{\pm 0}\) & 1\({}^{\pm 0}\) \\ queen13\_13 & 169 & 13 & 6.5\({}^{\pm 0.07}\) & 10 & 9 & **4** & 8\({}^{\pm 0}\) & 6.3\({}^{\pm 0.24}\) \\ myciel7 & 191 & 8 & 0.6\({}^{\pm 0.06}\) & 0 & 0 & 0 & 0.3\({}^{\pm 0.14}\) & 0.2\({}^{\pm 0.11}\) \\ homer & 561 & 13 & 1\({}^{\pm 0.07}\) & 0 & 0 & 0 & 0\({}^{\pm 0}\) & 0.6\({}^{\pm 0.22}\) \\ \hline Average & & & 1.9\({}^{\pm 0.01}\) & 1.95 & 2 & 1.2 & 1.92\({}^{\pm 0.05}\) & 1.35\({}^{\pm 0.05}\) \\ \hline \end{tabular}
\end{table}
Table 1: Comparison of ReLCol with other construction algorithms on graphs from the COLOR02 benchmark dataset. Values indicate how many more colours are required than the chromatic number, \(\chi\). For each graph, Random is run 100 times and the average and standard error are reported. For Gianinazzi et al. and ReLCol, the 12 heuristics are run and the average and standard error are reported. A bold number indicates that an algorithm has found the unique best colouring amongst the algorithms.
An example of such a graph with \(m=4\) is shown in Fig. 3. Note that some of the vertices in \(B^{\prime}\) and \(C^{\prime}\) may be disconnected; they exist simply to ensure that the vertices in \(B\) and \(C\) all have degree \(2m\).

The vertices can be partitioned into 3 disjoint sets \(A\cup B^{\prime}\cup C^{\prime}\), \(B\) and \(C\). Given that there are no edges between pairs of vertices in the same set, the chromatic number of the graph is 3. However the DSATUR algorithm assigns the same colour to vertices \(a_{i}\), \(b_{i}\) and \(c_{i}\), meaning it uses \(m\) colours for the whole graph. A proof of this is provided in [36].

Fig. 4 shows that ReLCol vastly outperforms DSATUR on Spinrad graphs, in most cases identifying an optimal colouring using the minimum number of colours. This indicates that despite their similar performance on general graphs, ReLCol has learned a heuristic that is selecting vertices differently to DSATUR.

Figure 4: ReLCol outperforms DSATUR on Spinrad graphs. Error bars show the maximum and minimum number of colours used by the 12 ReLCol-generated heuristics.

Figure 3: Example of a Spinrad graph on 24 vertices, generated with \(m=4\).
### Scalability of ReLCol

While we have shown that ReLCol is competitive with existing construction heuristics, and can outperform them on certain graph classes, our results suggest that the ability of ReLCol to colour general graphs effectively may reduce when the test graphs are significantly larger than those used for training.

This can be observed in Fig. 5, which compares the performance of DSATUR, ReLCol, and Random on graphs of particular sizes generated using the same process as our training dataset. The degradation in performance could be a result of the nature of the training dataset, whose constituent graphs have no more than 50 vertices: for graphs of this size DSATUR and ReLCol seem to achieve comparable results, and much better than Random, but the performance of ReLCol moves away from DSATUR towards Random as the graphs grow in size.

### Representing the state as a complete graph

To demonstrate the benefit of the proposed complete graph representation, we compare ReLCol with a version that preserves the topology of the original graph, meaning that within the GNN, messages are only passed between pairs of adjacent vertices. Fig. 6 compares the number of colours used by each version when applied to a validation dataset periodically during training. The validation dataset is composed of 100 graphs generated by the same mechanism as the training dataset. The complete graph representation clearly leads to faster learning and significantly better final performance.

Figure 5: As the graph size increases, the performance of ReLCol moves from being similar to DSATUR towards Random. This suggests that there are limitations to how well ReLCol generalises to graphs larger than those seen during training.
## 7 Conclusions

We have proposed ReLCol, a reinforcement learning algorithm based on graph neural networks that is able to learn a greedy construction heuristic for GCP. The ReLCol heuristic is competitive with DSATUR, a leading greedy algorithm from the literature, and better than several other comparable methods. We have demonstrated that part of this success is due to a novel (to the best of our knowledge) complete graph representation of the graph within the GNN. Since our complete graph representation seems to perform much better than the standard GNN representation, we intend to investigate its effect in further RL tasks with graph-structured data. We also plan to incorporate techniques for general-isability from the machine learning literature to improve the performance of the ReLCol heuristic on graphs much larger than the training set.

An advantage of automatically generated heuristics is that they can be tuned to specific classes of problem instances by amending the training data, so exploring the potential of ReLCol to learn an algorithm tailored to specific graph types would be an interesting direction. Finally, given that the ReLCol heuristic appears to work quite differently from DSATUR, further analysis of how it selects vertices may yield insights into previously unknown methods for GCP.

## Acknowledgements

G. Watkins acknowledges support from EPSRC under grant EP/L015374/1.

G. Montana acknowledges support from EPSRC under grant EP/V024868/1.

We thank L. Gianinazzi for sharing the code for the method presented in [16].

Figure 6: Our complete graph representation results in faster learning and better final performance compared to the standard GNN representation.