Optimizing Graph Coloring with Reinforcement Learning


This is what I will be working for a while. Restart is difficult, but necessary.

Why use Reinforcement Learning for Graph coloring?

In my Python application, that works on 3-regular planar graph, deciding which is the order of the edges to remove can be non-trivial. A naive approach randomly picks edges from F2 faces, F3, F4 or F5. This is the approach I used :-(. It leads to impasses when rebuilding the map. See https://4coloring.wordpress.com/2014/08/27/four-color-theorem-experimenting-impasses-as-in-life/

But a reinforcement learning agent can learn to make better selections over time to reduce color conflicts, I hope :-), and shed light on some properties of the graph that can be used in the proof.

The code will be here: https://github.com/stefanutti/maps-coloring-python

Remove one edge at a time from F2, F3, F4, or F5 faces. These faces represent the basic unavoidable set. This process will reduce the map to three faces, including the ocean as the external area. Afterward, I will restore the edges in reverse order, consistently working with 3-regular planar graphs. I will consider Tait coloring of the edges and apply, when necessary, Kempe’s chain color switching to the edges.

Remove edges a then restore them

For the Agent:

  • Environment initialization = The starting uncolored 3-regular planar graphs
  • Action = Select the edge to remove from the 3-regular planar graphs
  • State = The updated 3-regular planar graphs
  • Reward = +1 if Random Kempe’s chain color switching was not necessary, -1 otherwise

Non-Hamiltonian 3-regular planar graphs, Tait coloring and Kempe cycles … what else ;-)


Considering the smallest known non-Hamiltonian 3-regular planar graphs, discovered by Barnette-Bosák-Lederberg, I computed the Tait coloring and then deformed it to put in evidence the R-G cycles that in this case are four.

Links to the historical importance of this graph:

https://mathworld.wolfram.com/Barnette-Bosak-LederbergGraph.html

https://en.wikipedia.org/wiki/Barnette–Bosák–Lederberg graph

And here is the Tait coloring of this graph:

Deformed here to better show the R-G cycles:

Tait coloring and the four color theorem: personal Q&A


Some questions about the previous post:

Q1) Can cycles be concentric?

Yes, see this example.

Q2) Verify if at least one of the cycles (R-G, R-B, or G-B) form an Hamiltonian circuit

False.

From the Tait’s conjecture we now know (now = 1946 by William Thomas Tutte) that 3-regular graphs exist also without an Hamiltonian circuit. It means that, no matter what, it is not possible to find a cycle that touches all vertices, and therefore no single Kempe cycles of any two color selection, can exist.

From Wikipedia, the free encyclopedia

This article is about graph theory. For the conjectures in knot theory, see Tait conjectures.

In mathematics, Tait’s conjecture states that “Every 3-connected planar cubic graph has a Hamiltonian cycle (along the edges) through all its vertices“. It was proposed by P. G. Tait (1884) and disproved by W. T. Tutte (1946), who constructed a counterexample with 25 faces, 69 edges and 46 vertices. Several smaller counterexamples, with 21 faces, 57 edges and 38 vertices, were later proved minimal by Holton & McKay (1988). The condition that the graph be 3-regular is necessary due to polyhedra such as the rhombic dodecahedron, which forms a bipartite graph with six degree-four vertices on one side and eight degree-three vertices on the other side; because any Hamiltonian cycle would have to alternate between the two sides of the bipartition, but they have unequal numbers of vertices, the rhombic dodecahedron is not Hamiltonian. The conjecture was significant, because if true, it would have implied the four color theorem: as Tait described, the four-color problem is equivalent to the problem of finding 3-edge-colorings of bridgeless cubic planar graphs. In a Hamiltonian cubic planar graph, such an edge coloring is easy to find: use two colors alternately on the cycle, and a third color for all remaining edges. Alternatively, a 4-coloring of the faces of a Hamiltonian cubic planar graph may be constructed directly, using two colors for the faces inside the cycle and two more colors for the faces outside.

Smallest known non-Hamiltonian 3-regular planar graph: https://mathworld.wolfram.com/Barnette-Bosak-LederbergGraph.html.

Next post will be on the four coloring of the barnette-bosák-lederberg graph, which is the smallest known non-Hamiltonian graph, and the analysis of its Kempe cycles.

Q3) What about if I start with finding cycles, of even length (# of edges), that cross all vertices?

Some initial considerations: If cycles have to fit with Kempe cycles (closed paths of two alternating colors), they have to be of even length, and that would also mean that the total number of vertices crossed by all the cycles of the same two colors should be even too. Is it like this, or am I missing something? What about graphs with an odd number of vertices? Am I missing something?

Answer to the initial consideration: https://math.stackexchange.com/questions/181833/proving-that-the-number-of-vertices-of-odd-degree-in-any-graph-g-is-even + https://math.stackexchange.com/questions/181833/proving-that-the-number-of-vertices-of-odd-degree-in-any-graph-g-is-even

Finding cycles seems to be as difficult as finding a solution for of 4 coloring problem 😦

New paths for the 4ct?


The other day, before going to sleep, I realized that I needed to revisit the problem, starting with a piece of evidence I had noticed long ago. When a map is colored, the corresponding Tait coloring of the borders creates color chains (R-G, R-B, or G-B) that always form loops. Moreover, there may be more than one loop for each pair of colors. For example, the map shown here has:

1 R-G loop

  • 190, 557, 776, 525, 527, 126, 92, 76, 75, 84, 613, 770, 765, 170, 55, 61, 32, 15, 16, 10, 745, 712, 590, 756, 775, 6, 30, 57, 190

2 R-B loops

  • 190, 557, 765, …, 756, 190
  • 745, 712, 527, 126, 16, 10, 6, 775, 745

2 G-B loops

  • 190, 57, 55, 170, …, 756, 190
  • 776, 557, 765, 770, 525, 527, 712, 590, 776
Four color theorem

I wonder if analyzing how these loops form during the rebuilding phase of a map, after the reduction phase (see other posts), can lead me out of the mud.

Notes:

  • Once the map is completely four-colored (or 3-edge colored = Tait coloring), each chain (two-color chain) is actually a loop
    • This becomes clear when you consider the colors available at each vertex as you follow a chain. For example, if you’re examining the R-G chain and start from a vertex, following the Red color to the next vertex, that vertex will have the Green color available to continue the chain. As you keep alternating between R and G, each new vertex will offer the other color in the chain until you eventually return to the starting vertex, thereby closing the loop
  • If only one chain for a specific color selection (R-G, R-B, or G-B) exists, that chain touches all vertices of the map
    • If it weren’t so, one of the vertices not on the chain still would have the edges colored with three different colors, two of which (the same two colors of the chosen chain) would form another chain
  • The length of all loops is always an even number
    • This come straightforward from the definition of chain, multiple sequences of R and G = 2n

Deforming the original map, I managed to put in evidence the R-G loop, and then the other loops (R-B and G-B) respect to the first R-G deformation.

And here with the loops filled

Additional note:

This was the map when I discovered that infinite random switches throughout the entire graph do not solve the impasse. It was bad 😦 The graph here is identical to the one in the previous post.

https://four-color-theorem.org/2016/10/31/four-color-theorem-infinite-switches-are-not-enough/

Euler’s formula at work


During the process of removing faces from a planar map (cubic planar graph) this video shows how the Euler’s equation redistribute its weights:

+4F2 +3F3 +2F4 +1F5 +0F6 -1F7 -2F8 -3F9 …. = 12

The map that has been used to produce this video is represented by a planar cubic graph made of almost 10000 faces (20000 vertices and 27972 edges).

The selection for the edges to remove that I used was: take an edge from an F2. Then, if no F2 exist, use an F3. And then, if no F3 exist, use an F4 and finally an F5.

A graph with 20000 vertices opened by Gephy appears as a black square 😦

Here is the .dot file and the planar representation of the map.

Return it to me Tait coloured if you can 🙂

mailto:mario.stefanutti@gmail.com?subject=4CT Tait coloring

Meaning with all edges using only three colours (without conflicts at the vertices), which is equivalent to color the faces with four colours.

Bye

PS:

2020-04-26 22:37:21,310 - root - INFO - ------------------
2020-04-26 22:37:21,310 - root - INFO - BEGIN: Print stats
2020-04-26 22:37:21,310 - root - INFO - ------------------
2020-04-26 22:37:21,311 - root - INFO - Stat: CASE-F2-01 = 4114
2020-04-26 22:37:21,311 - root - INFO - Stat: CASE-F3-01 = 4478
2020-04-26 22:37:21,311 - root - INFO - Stat: CASE-F4-01 = 732
2020-04-26 22:37:21,311 - root - INFO - Stat: CASE-F4-02 = 442
2020-04-26 22:37:21,311 - root - INFO - Stat: CASE-F4-03 = 231
2020-04-26 22:37:21,311 - root - INFO - Stat: CASE-F5-C1!=C2-SameKempeLoop-C1-C2 = 1
2020-04-26 22:37:21,311 - root - INFO - Stat: CASE-F5-C1==C2-SameKempeLoop-C1-C3 = 1
2020-04-26 22:37:21,312 - root - INFO - Stat: CASE-F5-C1==C2-SameKempeLoop-C1-C4 = 0
2020-04-26 22:37:21,312 - root - INFO - Stat: MAX_RANDOM_KEMPE_SWITCHES = 0
2020-04-26 22:37:21,312 - root - INFO - Stat: TOTAL_RANDOM_KEMPE_SWITCHES = 0
2020-04-26 22:37:21,312 - root - INFO - Stat: time_ELABORATION = 1015
2020-04-26 22:37:21,312 - root - INFO - Stat: time_ELABORATION_BEGIN = Sun Apr 26 22:19:55 2020
2020-04-26 22:37:21,313 - root - INFO - Stat: time_ELABORATION_END = Sun Apr 26 22:36:50 2020
2020-04-26 22:37:21,313 - root - INFO - Stat: time_GRAPH_CREATION_BEGIN = Sun Apr 26 22:19:22 2020
2020-04-26 22:37:21,313 - root - INFO - Stat: time_GRAPH_CREATION_END = Sun Apr 26 22:19:55 2020
2020-04-26 22:37:21,313 - root - INFO - ----------------
2020-04-26 22:37:21,314 - root - INFO - END: Print stats
2020-04-26 22:37:21,314 - root - INFO - ----------------

Zoom on a planar graph, 10000 nodes, three-edge Tait colored


I generated a planar map of 10000 nodes and then colored using the 4ct python coloring program.

It did use Tait coloring (3-edge-coloring) which is equivalent to the four face coloring of the four color theorem.

It works pretty fast using:

  • graph reduction removing edges from F2, F3, F4, F5
  • graph rebuilding using Kempe chain color switching techniques

Four color theorem: A fast algorithm – 2


Four color theorem: A fast algorithm

These are the OLD and NEW (last column) execution times on my new laptop:

  • 100 – 196 vertices, 294 edges = 0 seconds – 0 seconds
  • 200 – 396 vertices, 594 edges = 1 seconds – 0 seconds
  • 300 – 596 vertices, 894 edges = 4 seconds – 1 second
  • 400 – 796 vertices, 1194 edges = 6 seconds – 1 second
  • 500 – 996 vertices, 1494 edges = 8 seconds – 2 seconds
  • 600 – 1196 vertices, 1794 edges = 10 seconds – 4 seconds
  • 700 – 1396 vertices, 2094 edges = 16 seconds – 6 seconds
  • 800 – 1596 vertices, 2394 edges = 18 seconds – 7 seconds
  • 900 – 1796 vertices, 2694 edges = 22 seconds – 9 seconds
  • 1000 – 1996 vertices, 2994 edges = 26 seconds – 11 seconds

Four color theorem: Infinite switches are not enough – Rectangular maps :-(


I transformed the really bad case into a rectangular map to play with the Java program and Kempe random switches.

Here is the graph with the two edges to connect:

save-graph-really-bad-case

The two edges marked with the X, have to be joined by a new edge that form a new F5 face.

To try the Java program, rebuild this graph and play with the switches, it is possible to use this string:

  • 1b+, 2b+, 3b+, 4b+, 5b+, 15b+, 14b-, 13b-, 5e-, 6b-, 12b-, 4e-, 8b-, 13e-, 6e-, 9b-, 12e-, 11b-, 3e-, 14e-, 10b-, 7b-, 2e-, 8e-, 9e-, 11e-, 7e-, 10e-, 15e+, 1e+

Next is the graph that shows how the graph has been converted:

really_bad_case-ariadne_step-5-12-7-32-6-15-10-ppt