Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions problems/graph-coloring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<!--
SPDX-FileCopyrightText: 2025 Ondřej Liška <[email protected]>
SPDX-FileCopyrightText: 2025 Patrik Olszar <[email protected]>
SPDX-FileCopyrightText: 2025 David Sedlák <[email protected]>

SPDX-License-Identifier: CC-BY-4.0
-->

<!-- According to the copyright and licensing policy of ROAR-NET original
problem statements contributed to this repository shall be licensed under the
CC-BY-4.0 licence. In some cases CC-BY-SA-4.0 might be accepted, e.g., if the
problem is based upon an existing problem licensed under those terms. Please
provide a clear justification when opening the pull request if the problem is
not licensed under CC-BY-4.0 -->

# Graph Coloring (vertex coloring)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem statement seems to describe a classic problem of Combinatorial Optimization. What is the added value of this problem here? As a non-expert in the field, I don't understand whether something new is proposed...


**Ondřej Liška¹, Patrik Olszar², David Sedlák²**\
¹ Brno University of Technology, Faculty of Mechanical Engineering, Czech Republic\
² Brno University of Technology, Faculty of Information Technology, Czech Republic

Copyright 2025 Ondřej Liška, Patrik Olszar, David Sedlák

This document is licensed under CC-BY-4.0.

## Introduction

The Graph Coloring problem is a classic challenge in graph theory and combinatorial optimisation.
Its objective is to assign colors to the vertices of an undirected graph such that no two adjacent vertices share the same color, and the total number of used colors is minimized.

This problem arises in a variety of real-world scenarios, such as scheduling, register allocation in compilers, and frequency assignment in wireless networks. Due to its NP-hard nature, it is also widely used as a benchmark for exact and heuristic optimisation methods.

## Task

Assign a color (represented as an integer) to each vertex of a given undirected graph such that adjacent vertices receive different colors and the number of distinct colors used is minimised.

## Detailed Description

Each problem instance defines an **undirected graph** `G = (V, E)`, where:

- `V` is the set of **vertices**, typically numbered from `0` to `n - 1`
- `E` is the set of **edges**, where each edge is an unordered pair `{u, v}`

---

### Objective

The goal is to find a **coloring function**:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the search space of this problem statement? A set of coloring functions?


c: V → ℕ

such that:

- For every edge `{u, v} ∈ E`, the colors are different:

c(u) ≠ c(v)

- The total number of colors used is minimised:

min( max\_{v ∈ V} c(v) + 1 )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Written like this, the function to assign a color to a new vertex is not entirely clear to me.
The fitness function of the problem is also not entirely clear to me.


---

### Infeasible Solutions

A solution is **infeasible** if **any** adjacent vertices are assigned the **same color**, i.e.

∃ {u,v} ∈ E: c(u) = c(v)

---

### Valid Solution

A solution is **valid** if all adjacency constraints are satisfied, and the number of colors is minimised.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term valid confuses me. What do you mean with valid? Do you mean "optimal"?
Valid makes me think about something that complies with certain rules or requirement, so it would be close to the concept of "feasible", while in your explanation a valid solution also seems to improve the objective of previous solutions... But this makes me think about moves between two solutions... Could you clarify the concept, please?


## Instance data file

The input format is based on the standard [DIMACS `.col` format] - more instances can be found there: (<https://github.com/dynaroars/npbench/tree/master/instances/coloring/graph_color>)

- Lines starting with `c` are comments
- The `p` line has the form: `p edge <number_of_vertices> <number_of_edges>`
- Each edge is defined on a line: `e <u> <v>` (1-based vertex indices)

> In the `support` folder, you can find a method that transforms the input from this format into a matrix.

## Solution file

The solution must be provided as a plain text file, where each line assigns a color to a vertex.

Each line has the format:

`<vertex_id> <color_id>`

For example:

```
0 0
1 1
2 0
3 1
```

- `vertex_id` is an integer matching the ID of a vertex in the input graph.
- `color_id` is a non-negative integer representing the assigned color.
- Vertex indices must match those used in the input instance file.
- The format assumes one-based or zero-based indexing, depending on the instance.

This format will be used by the solution validator included in the `support/` folder.

## Example

### Instance

A simple graph with 5 vertices and 6 edges, in edge list format:

```
0 1
0 2
1 2
1 3
2 4
3 4
```

Visual representation of the graph:

![Uncolored Graph](images/0-SmallExample.col.png)

### Solution

A feasible 3-coloring of the graph:

```
0 0
1 1
2 0
3 2
4 1
```

This uses 3 colors:
-Color 0 (e.g. red) for vertices 0 and 2
-Color 1 (e.g. green) for vertices 1 and 4
-Color 2 (e.g. blue) for vertex 3

### Explanation

The following image shows a valid coloring of the graph where no adjacent vertices share the same color.
This solution uses 3 distinct colors.

![Colored Graph](images/0-SmallExample.sol.png)

## Acknowledgements

This problem statement is based upon work from COST Action Randomised
Optimisation Algorithms Research Network (ROAR-NET), CA22137, is supported by
COST (European Cooperation in Science and Technology).

<!-- Please keep the above acknowledgement. Add any other acknowledgements as
relevant. -->

## References

- Garey, M. R., & Johnson, D. S. (1979). _Computers and Intractability: A Guide to the Theory of NP-Completeness_. W. H. Freeman.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two references are not cited in the description text. Please cite them where suitable.

- Jensen, T. R., & Toft, B. (1995). _Graph Coloring Problems_. Wiley-Interscience.
11 changes: 11 additions & 0 deletions problems/graph-coloring/data/0-SmallExample/0-SmallExample.col
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
c FILE: input.col

c DESCRIPTION: Small example input for illustrative purposses

p edge 5 6
e 0 1
e 0 2
e 1 2
e 1 3
e 2 4
e 3 4
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 0
2 1
0 2
3 1
4 0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions problems/graph-coloring/data/1-FullIns_3/1-FullIns_3.col
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
c FILE: 1-FullIns_3.col

c SOURCE: M. Caramia ([email protected]) and P. Dell'Olmo ([email protected])

c DESCRIPTION: 1-FullIns graph of order 3

p edge 30 100
e 1 2
e 1 4
e 1 11
e 1 13
e 2 3
e 2 10
e 2 12
e 3 6
e 3 8
e 3 11
e 3 15
e 3 17
e 4 5
e 4 8
e 4 10
e 4 14
e 4 17
e 5 7
e 5 9
e 5 13
e 5 16
e 5 18
e 6 7
e 6 9
e 6 12
e 6 16
e 6 18
e 7 8
e 7 9
e 7 14
e 7 15
e 7 17
e 7 18
e 8 9
e 8 12
e 8 13
e 8 16
e 8 18
e 9 14
e 9 15
e 9 16
e 9 17
e 10 20
e 10 22
e 10 29
e 11 19
e 11 21
e 11 29
e 12 20
e 12 24
e 12 26
e 12 29
e 13 19
e 13 23
e 13 26
e 13 29
e 14 22
e 14 25
e 14 27
e 14 29
e 15 21
e 15 25
e 15 27
e 15 29
e 16 23
e 16 24
e 16 26
e 16 27
e 16 29
e 17 21
e 17 22
e 17 25
e 17 27
e 17 29
e 18 23
e 18 24
e 18 25
e 18 26
e 18 29
e 19 28
e 19 30
e 20 28
e 20 30
e 21 28
e 21 30
e 22 28
e 22 30
e 23 28
e 23 30
e 24 28
e 24 30
e 25 28
e 25 30
e 26 28
e 26 30
e 27 28
e 27 30
e 28 29
e 28 30
e 29 30
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions problems/graph-coloring/data/1-FullIns_3/1-FullIns_3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
29 0
28 1
30 2
17 1
16 1
18 1
8 0
7 2
9 3
13 1
12 1
15 1
14 1
4 2
3 2
6 0
5 0
26 0
25 0
27 0
11 1
10 1
22 0
21 0
24 0
23 0
1 0
2 3
20 0
19 0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading