🧩 Constraint Solving POTD:Graph Coloring #32609
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 #32799. |
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 of the Day: Graph Coloring
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, using as few colors as possible.The minimum number of colors needed is the chromatic number
χ(G).Small Concrete Instance
Consider a 5-vertex "wheel" graph (a central hub connected to a 4-cycle):
Question: What is
χ(G)for this graph, and what is a valid coloring?Answer:
χ(G) = 3. One valid 3-coloring:{0→R, 1→G, 2→B, 3→G, 4→B}.Input / Output
G = (V, E), optionally an upper boundkon colorscolor: V → {1..k}, or proof that none existsWhy It Matters
Register allocation in compilers: Variables that are "live" at the same time cannot share a CPU register — exactly the graph coloring problem on the interference graph. Modern compilers (LLVM, GCC) rely on coloring heuristics for this.
Timetabling and scheduling: Exams that share students cannot be scheduled in the same slot — model each exam as a vertex, conflicts as edges, and time slots as colors. Universities schedule thousands of exams this way.
Frequency assignment in wireless networks: Neighboring cells that would interfere must use different frequency channels. Cellular network planning is a weighted graph coloring problem at its core.
Modeling Approaches
Approach 1 — Constraint Programming (CP)
Decision variables:
color[v] ∈ {1..k}for each vertexv ∈ VConstraints:
Objective: Minimize
k = max(color[v] : v ∈ V)Trade-offs: CP excels here because the
alldifferent-like propagation and arc-consistency on≠constraints prune the search space aggressively. Adding symmetry-breaking constraints (e.g.,color[u] ≤ color[v] + 1in vertex-order) drastically reduces the search tree.Approach 2 — Integer Linear Programming (MIP/ILP)
Decision variables:
x[v][c] ∈ {0,1}— 1 if vertexvreceives colorc;y[c] ∈ {0,1}— 1 if colorcis used at allConstraints:
Objective: Minimize
Σ_c y[c]Trade-offs: The LP relaxation is weak (fractional solutions proliferate), so MIP solvers need many branch-and-bound nodes. However, adding clique inequalities — for each clique
Q,Σ_{v∈Q} x[v][c] ≤ 1— tightens the relaxation significantly and is standard practice.Example Model (MiniZinc)
Run with increasing
kstarting from a lower bound (e.g., clique numberω(G)) until satisfiable.Key Techniques
1. DSATUR Heuristic (Greedy + Bounding)
DSATUR (Degree of SATURation) greedily colors vertices in order of saturation — the number of distinct colors already used by their neighbors. It often produces near-optimal colorings and is commonly used to find a good upper bound before exact search.
2. Symmetry Breaking
Without symmetry breaking, any permutation of a valid
k-coloring is another valid coloring — yieldingk!symmetric solutions. Standard fixes:color[0] = 1, enforcecolor[v] ≤ max(color[0..v-1]) + 1These alone can reduce search time by orders of magnitude.
3. Clique-Based Lower Bounds
The chromatic number
χ(G) ≥ ω(G)(clique number). Finding a large clique (even heuristically via greedy clique algorithms) gives a tight lower bound for branch-and-bound. Combined with fractional relaxation bounds, solvers can prune entire subtrees without branching.Challenge Corner
Given a graph
Gand a fixedk:x[v][c]for each vertex–color pairExtensions to explore:
References
Beta Was this translation helpful? Give feedback.
All reactions