@@ -21,9 +21,62 @@ To run this example:
2121
2222``` bash
2323cd examples/graph_coloring
24- python ../../openevolve-run.py initial_program.py evaluator.py --config config.yaml --iterations 50
24+ python ../../openevolve-run.py initial_program.py evaluator.py --config config.yaml --iterations 100
2525```
2626
27+ ### Running Benchmarks
28+
29+ To test a coloring algorithm on the full DIMACS benchmark suite:
30+
31+ ``` bash
32+ # Test the initial greedy algorithm
33+ python run_benchmarks.py
34+
35+ # Test an evolved program
36+ python run_benchmarks.py best_program.py
37+ ```
38+
39+ This produces a results table showing colors used vs chromatic number for each graph.
40+
41+ ## Evaluation System
42+
43+ The evaluator uses a ** 3-stage cascade** with DIMACS benchmark graphs:
44+
45+ ### Stage 1: Validity Check
46+ - Tests on 3 simple graphs (Petersen, K5, cycle)
47+ - Must produce ** valid colorings** (no adjacent vertices share colors)
48+ - Programs that fail validity are rejected immediately
49+
50+ ### Stage 2: Quick Evaluation
51+ - Tests on small DIMACS benchmarks (11-87 vertices)
52+ - Includes: Mycielski graphs (myciel3-5), Queen graphs (5×5 to 8×8), and book graphs (david, huck, jean)
53+ - Score threshold: 0.7 to proceed to Stage 3
54+
55+ ### Stage 3: Comprehensive Evaluation
56+ - Full DIMACS benchmark suite (22 graphs, 11-211 vertices)
57+ - Includes challenging graphs: queen11_11, queen12_12, mulsol.i.1, zeroin.i.1
58+ - Scoring combines coloring quality (70%) and time efficiency (30%)
59+
60+ ### DIMACS Benchmarks
61+
62+ The evaluator uses standard [ DIMACS graph coloring benchmarks] ( https://mat.tepper.cmu.edu/COLOR/instances.html ) with known chromatic numbers:
63+
64+ | Graph | Vertices | χ (chromatic number) |
65+ | -------| ----------| ---------------------|
66+ | myciel3 | 11 | 4 |
67+ | myciel4 | 23 | 5 |
68+ | myciel5 | 47 | 6 |
69+ | queen5_5 | 25 | 5 |
70+ | queen6_6 | 36 | 7 |
71+ | queen8_8 | 64 | 9 |
72+ | david | 87 | 11 |
73+ | huck | 74 | 11 |
74+ | jean | 80 | 10 |
75+ | anna | 138 | 11 |
76+ | games120 | 120 | 9 |
77+ | mulsol.i.1 | 197 | 49 |
78+ | zeroin.i.1 | 211 | 49 |
79+
2780## Algorithm Evolution
2881
2982### Initial Algorithm (Simple Greedy)
@@ -47,47 +100,71 @@ def graph_coloring(graph):
47100 return coloring
48101```
49102
50- ### Evolved Algorithm
103+ ### Evolved Algorithm (DSatur)
51104
52- * To be updated after running OpenEvolve *
105+ After 100 iterations, OpenEvolve independently discovered an optimized ** DSatur algorithm ** :
53106
54- ## Key Improvements
107+ ``` python
108+ def graph_coloring (graph ):
109+ coloring = {}
110+ uncolored = set (range (graph.num_vertices))
55111
56- Through evolution, OpenEvolve may discover improvements such as:
112+ # Cache saturation degrees for efficiency
113+ sat_degrees = [0 ] * graph.num_vertices
114+ neighbor_color_sets = [set () for _ in range (graph.num_vertices)]
57115
58- 1 . ** Vertex Ordering** : Processing high-degree vertices first (Welsh-Powell)
59- 2 . ** Saturation Degree** : DSatur algorithm - prioritize vertices with most neighbor colors
60- 3 . ** Independent Set Building** : RLF-style algorithms
61- 4 . ** Local Search** : Color swapping to reduce total colors
116+ while uncolored:
117+ # Select vertex with highest saturation degree, then highest degree
118+ vertex = max (uncolored,
119+ key = lambda v : (sat_degrees[v], graph.get_degree(v), - v))
120+
121+ # Assign smallest available color
122+ color = 0
123+ while color in neighbor_color_sets[vertex]:
124+ color += 1
62125
63- ## Test Graphs
126+ coloring[vertex] = color
127+ uncolored.remove(vertex)
128+
129+ # Update saturation degrees of uncolored neighbors
130+ for neighbor in graph.get_neighbors(vertex):
131+ if neighbor in uncolored:
132+ if color not in neighbor_color_sets[neighbor]:
133+ neighbor_color_sets[neighbor].add(color)
134+ sat_degrees[neighbor] += 1
135+
136+ return coloring
137+ ```
64138
65- The evaluator tests on multiple graph types:
66- - ** Petersen Graph** : Classic graph, χ = 3
67- - ** Complete Graph K5** : χ = 5
68- - ** Bipartite Graphs** : χ = 2
69- - ** Cycle Graphs** : χ = 2 (even) or 3 (odd)
70- - ** Random Graphs** : Varying density
139+ Key improvements discovered:
140+ 1 . ** Saturation-based vertex ordering** : Prioritizes vertices with the most distinct neighbor colors
141+ 2 . ** Cached neighbor color sets** : O(1) lookup for available colors
142+ 3 . ** Tie-breaking by degree** : When saturation is equal, prefer high-degree vertices
71143
72144## Results
73145
74- * To be updated after running OpenEvolve*
146+ | Metric | Initial (Greedy) | Evolved (DSatur) |
147+ | --------| ------------------| ------------------|
148+ | Combined Score | 0.893 | ** 0.938** |
149+ | Optimal Colorings | 10/22 | ** 15/22** |
150+ | Total Colors | 389 | ** 362** |
75151
76- | Metric | Initial | Evolved |
77- | -------- | --------- | --------- |
78- | Combined Score | TBD | TBD |
79- | Optimal Colorings | TBD | TBD |
152+ The evolved algorithm:
153+ - Uses ** 27 fewer colors ** across the test suite
154+ - Achieves ** optimal coloring on 5 additional graphs **
155+ - Was discovered by ** iteration 14 ** (generation 2)
80156
81157## References
82158
83159- Welsh, D.J.A. and Powell, M.B. (1967). "An upper bound for the chromatic number of a graph and its application to timetabling problems."
84160- Brélaz, D. (1979). "New Methods to Color the Vertices of a Graph" (DSatur algorithm)
85161- Leighton, F.T. (1979). "A graph coloring algorithm for large scheduling problems" (RLF algorithm)
86- - Hertz, A. and de Werra, D. (1987). "Using Tabu Search Techniques for Graph Coloring"
162+ - DIMACS Graph Coloring Challenge: https://mat.tepper.cmu.edu/COLOR/instances.html
87163
88164## Next Steps
89165
90166Try modifying the config.yaml to:
91167- Increase iterations for more evolution
92- - Change LLM models
93- - Adjust the system message to guide evolution differently
168+ - Change LLM models or weights
169+ - Adjust the system message to guide evolution toward specific algorithms
170+ - Add larger DIMACS benchmarks to the test suite
0 commit comments