🧩 Constraint Solving POTD:Graph Coloring #32108
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 #32350. |
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 the minimum number of colors possible (the chromatic numberχ(G)).Small Concrete Instance
Consider this 5-node graph (a cycle
C5):The chromatic number of an odd cycle is 3 — try it! Any 2-coloring forces a conflict.
Input: An adjacency list and a target number of colors
kOutput (decision): A valid
k-coloring, or UNSAT if none existsOutput (optimization): The minimum
kand corresponding coloringWhy It Matters
Modeling Approaches
Approach 1 — Constraint Programming (CP)
Decision variables:
color[v] ∈ {1..k}for each vertexv ∈ VConstraints:
Symmetry breaking (critical for performance):
Trade-offs: CP propagation via arc consistency prunes the domain of
color[v]whenever a neighbor is assigned. Thealldifferent-like structure is exploited well by global clique constraints. Scales reasonably to hundreds of nodes with good search heuristics.Approach 2 — SAT Encoding
Introduce Boolean variables
x[v][c]= "vertexvgets colorc".At-least-one:
∀v: x[v][1] ∨ x[v][2] ∨ ... ∨ x[v][k]At-most-one:
∀v, c≠c': ¬x[v][c] ∨ ¬x[v][c']Conflict:
∀(u,v)∈E, ∀c: ¬x[u][c] ∨ ¬x[v][c]This produces
O(|V|·k)variables andO(|E|·k + |V|·k2)clauses. Modern CDCL SAT solvers (MiniSat, CaDiCaL) handle instances with thousands of nodes. The SAT encoding naturally supports incremental solving — incrementkand re-solve.Trade-offs: SAT loses the semantic structure CP exploits but benefits from decades of CDCL engineering. Works exceptionally well near phase transitions.
Approach 3 — MIP / ILP
LP relaxations are weak (fractional solutions abound), so MIP solvers lean heavily on branch-and-cut with clique inequalities. Better suited when combined with column generation (treating colors as patterns).
Example Model — MiniZinc (CP)
Run with
k=2→ UNSAT;k=3→ solution found.Key Techniques
1. Propagation — Forward Checking & Arc Consistency (AC-3)
When
color[v] = cis assigned, AC-3 removescfrom the domains of all neighbors. Bound consistency isn't meaningful here (discrete colors), but domain wipeout detection early in search is crucial. The DSATUR algorithm greedily assigns colors in order of saturation (number of distinct colors in the neighborhood) and is a remarkable constructive heuristic.2. Symmetry Breaking
Graph coloring has massive color symmetry: any permutation of colors yields an equivalent solution. Without breaking this, a solver wastes exponential time on symmetric branches. The lex-leader constraint (
coloris lexicographically minimal among all equivalent colorings) is complete but expensive; practical variants fix the color of the first vertex and enforce that new colors are introduced in order.3. Clique-Based Lower Bounds
The chromatic number
χ(G) ≥ ω(G)whereω(G)is the clique number (size of the largest complete subgraph). Finding large cliques (itself NP-hard, but heuristically tractable) provides strong lower bounds that prune the search for the minimumk. Combined with fractional relaxations, this forms the backbone of branch-and-bound exact solvers like DSATUR + backtrack and Brelaz's algorithm.Challenge Corner
💡 Think about this:
The graph coloring problem on perfect graphs (where
χ(G) = ω(G)for every induced subgraph) is solvable in polynomial time. Interval graphs and chordal graphs are perfect.As an extension: how would you model list coloring, where each vertex
vhas its own allowed set of colorsL(v) ⊆ {1..k}? Does the SAT or CP model extend more naturally?References
AddAllDifferentandAddForbiddenAssignments.Beta Was this translation helpful? Give feedback.
All reactions