🧩 Constraint Solving POTD:Problem of the Day: Graph Coloring #54212
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 #54505. |
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
The graph coloring problem asks: given an undirected graph, assign a color to each vertex such that no two adjacent vertices share the same color, while minimizing the total number of colors used.
Concrete Instance
Consider a simple graph with 4 vertices representing four courses:
Question: Can you schedule these courses using 3 colors (time slots), or do you need 4?
Solution: Color 1 (Math), Color 2 (Physics, History), Color 3 (Chemistry). Yes, 3 colors suffice!
Input/Output Specification
Input: An undirected graph
G = (V, E)with verticesVand edgesEOutput: A mapping
color: V → {1, 2, ..., k}such that for every edge(u, v) ∈ E, we havecolor(u) ≠ color(v), andk(the chromatic number) is minimized.Why It Matters
Register Allocation in Compilers: When compiling code, a compiler must assign CPU registers to variables. Two variables that are "live" simultaneously (used in overlapping time windows) cannot share the same register—this is exactly graph coloring, where vertices are variables and edges connect variables that conflict.
Exam Scheduling: Universities must schedule exams for courses such that students taking multiple courses don't have conflicting exam times. Courses are vertices, edges connect courses with common students, and colors are exam time slots.
Frequency Assignment: Telecom networks assign radio frequencies to base stations to minimize interference. Stations that are geographically close (edges) must use different frequencies (colors).
Map Coloring: The famous four-color theorem states that any planar map can be colored with at most 4 colors. This classic result motivated much of early graph theory and constraint solving research.
Modeling Approaches
Approach 1: Constraint Programming (CP)
Decision Variables:
color[v] ∈ {1, 2, ..., k}for each vertexv ∈ VConstraints:
color[u] ≠ color[v]for all edges(u, v) ∈ E(inequality constraints)alldifferent()on clique subsets to propagate more stronglyObjective: Minimize
kTrade-offs:
alldifferent) provide strong propagationExample Model (MiniZinc)
Approach 2: Integer Linear Programming (MIP)
Decision Variables:
x[v, c] ∈ {0, 1}for each vertexvand colorc ∈ {1, ..., k}, wherex[v, c] = 1iff vertexvgets colorcused[c] ∈ {0, 1}indicating whether colorcis usedConstraints:
∑_c x[v, c] = 1for allv(each vertex gets exactly one color)x[u, c] + x[v, c] ≤ 1for all edges(u, v)and colorsc(endpoints of edges don't share colors)used[c] ≥ x[v, c]for allv, c(colorcis marked used if any vertex uses it)Objective: Minimize
∑_c used[c]Trade-offs:
Key Techniques
1. Greedy Heuristics & Degeneracy Ordering
A simple greedy algorithm colors vertices in order, assigning each vertex the smallest color not used by its neighbors. The order matters: degeneracy ordering (iteratively removing the vertex with fewest uncolored neighbors) often yields better solutions. This is a fast preprocessing step combined with search.
2. Arc Consistency & Propagation
In CP, maintaining arc consistency on inequality constraints removes impossible values early. For cliques (fully connected subgraphs), use
alldifferent()constraints to propagate aggressively. Bounds consistency onmax(color)tightens the domain of the chromatic number variable as colors are assigned.3. Symmetry Breaking & Partial Coloring
Graph coloring has inherent symmetry: swapping colors does not change the solution's quality. Symmetry-breaking constraints like "color(v1) < color(v2)" for a canonical pair of vertices (e.g., highest-degree vertices) reduce the search space. Alternatively, partial coloring techniques order vertices by degree and branch on high-degree vertices first, since they constrain the problem most.
Challenge Corner
Can you model graph coloring as a SAT problem? Graph coloring can be encoded in Boolean satisfiability: use Boolean variables
p[v, c]("vertexvhas colorc") and write clauses enforcing exactly-one color per vertex and conflict-free edges. What is the clause complexity, and how does SAT solver performance compare to dedicated CP solvers on structured instances?Extension: The list coloring variant restricts each vertex
vto a subsetL[v]of allowed colors. How would you handle this in each model? Can you exploit list structure to improve propagation?References
Jensen, T. R., & Toft, B. (1995). Graph Coloring Problems. Wiley-Interscience. — Comprehensive reference on graph coloring variants and algorithms.
Rossi, F., van Beek, P., & Walsh, T. (2006). Handbook of Constraint Programming, ch. 7 (Graph Problems). — Excellent overview of how constraint programming tackles coloring and related graph problems.
Kubale, M. (Ed.). (2004). Graph Colorings. American Mathematical Society. — Advanced treatment of coloring algorithms and complexity.
OR-Tools Graph Coloring Guide (https://github.com/google/or-tools) — Practical examples in C++, Python, and Java using Google's constraint solver library.
All reactions