π§© Constraint Solving POTD:Graph Coloring β Color Vertices, Color the World #31932
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Constraint Solving β Problem of the Day. A newer discussion is available at Discussion #32108. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
Given an undirected graph
G = (V, E), assign a color to each vertex such that no two adjacent vertices share the same color. The goal is to minimize the number of colors used β this minimum is called the chromatic numberΟ(G).Small Concrete Instance
Consider a graph with 5 vertices and 6 edges (the cycle
C5):Can you 2-color it? Try it β you'll find you need 3 colors (odd cycles require 3). A valid 3-coloring:
{1βR, 2βG, 3βR, 4βG, 5βB}.Input: Graph
G = (V, E), maximum colorskOutput: Assignment
color: V β {1..k}satisfying all edge constraints, or UNSAT if impossibleWhy It Matters
Modeling Approaches
Approach 1 β Constraint Programming (CP)
Decision variables:
color[v] β {1..k}for each vertexv β VConstraints:
Symmetry breaking (colors are interchangeable β permuting them yields equivalent solutions):
Trade-offs: Very natural encoding;
βconstraints propagate well via arc-consistency (AC-3). Globalalldifferentis not applicable here (we want conflicts, not uniqueness). The model scales modestly; fork-colorability checking, binary CSP suffices.Approach 2 β Integer Programming (MIP/ILP)
Decision variables:
x[v,c] β {0,1}β 1 if vertexvgets colorc;y[c] β {0,1}β 1 if colorcis usedConstraints:
Objective: minimize
Ξ£_c y[c]Trade-offs: LP relaxation gives useful lower bounds; branch-and-bound can prove optimality. However, the model has
O(|V|Β·k)binary variables and is sensitive to symmetry. Column-generation and clique-based lower bounds (from maximum cliqueΟ(G) β€ Ο(G)) significantly tighten the formulation.Example Model (MiniZinc β CP approach)
Key Techniques
1. DSATUR Heuristic (Degree of SATURation)
At each step, color the vertex with the highest number of distinct colors already used among its neighbors (saturation degree). Ties broken by degree. This greedy heuristic often finds near-optimal colorings and is the basis for excellent branching heuristics in exact solvers.
2. Clique-Based Lower Bounds
The chromatic number satisfies
Ο(G) β₯ Ο(G)(maximum clique size). Finding a large clique (even via heuristic max-clique solvers) gives tight lower bounds and can seed the search. Combined with the fractional chromatic number from LP relaxations, this dramatically prunes the search tree.3. Symmetry Breaking & Value Ordering
Colors are interchangeable β any permutation of colors in a valid solution yields another valid solution. This creates massive symmetry. Breaking it (e.g., with the first-fit ordering: vertex
vmay only receive colorcif some earlier vertex already uses colors1..c-1) can reduce the search space by a factor ofk!.Challenge Corner
π‘ Think about this:
The decision version of graph coloring (
k-colorability fork β₯ 3) is NP-complete β yet it's solved routinely in practice for real compiler register allocation (graphs of thousands of nodes,k = 16β32).Bonus: Can you model the list coloring variant, where each vertex
vhas its own allowed setL(v) β {1..k}, with minimal changes to the CP model above?References
Beta Was this translation helpful? Give feedback.
All reactions