Skip to content

Commit a0b6480

Browse files
GiggleLiuclaude
andauthored
feat: Implement integer programming solver for Coloring problem (#20)
* feat: Implement integer programming solver for Coloring problem Add ILP reduction for the Graph K-Coloring problem with: - Binary variables x_{v,c} for each (vertex, color) pair - Constraints ensuring each vertex has exactly one color - Constraints ensuring adjacent vertices have different colors - Comprehensive test suite covering various graph types Closes #19 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: Add Coloring -> ILP to reduction graph and documentation - Register Coloring -> ILP in inventory for automatic discovery - Add ILP as a problem type in reduction graph - Add theorem and proof for Coloring -> ILP reduction in reductions.typ - Update reduction graph diagram and registered reductions table - Regenerate reduction_graph.json with ILP node 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Resolve clippy needless_range_loop warning Refactor extract_solution to use functional style with map/find instead of indexing into a mutable vector. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c758eae commit a0b6480

5 files changed

Lines changed: 461 additions & 0 deletions

File tree

docs/paper/reduction_graph.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
"target": "SpinGlass",
8383
"bidirectional": false
8484
},
85+
{
86+
"source": "Coloring",
87+
"target": "ILP",
88+
"bidirectional": false
89+
},
8590
{
8691
"source": "Factoring",
8792
"target": "CircuitSAT",

docs/paper/reductions.typ

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ In all graph problems below, $G = (V, E)$ denotes an undirected graph with $|V|
170170
Given $n$ binary variables $x_i in {0, 1}$, matrix $Q in RR^(n times n)$, minimize $f(bold(x)) = bold(x)^top Q bold(x)$.
171171
]
172172

173+
#definition("Integer Linear Programming (ILP)")[
174+
Given $n$ integer variables $bold(x) in ZZ^n$, constraint matrix $A in RR^(m times n)$, bounds $bold(b) in RR^m$, and objective $bold(c) in RR^n$, find $bold(x)$ minimizing $bold(c)^top bold(x)$ subject to $A bold(x) <= bold(b)$ and variable bounds.
175+
]
176+
173177
== Satisfiability Problems
174178

175179
#definition("SAT")[
@@ -331,6 +335,24 @@ In all graph problems below, $G = (V, E)$ denotes an undirected graph with $|V|
331335
_Solution extraction._ Without ancilla: identity. With ancilla: if $sigma_a = 1$, flip all spins before removing ancilla.
332336
]
333337

338+
#theorem[
339+
*(Coloring $arrow.r$ ILP)* The $k$-coloring problem reduces to binary ILP with $|V| dot k$ variables and $|V| + |E| dot k$ constraints.
340+
]
341+
342+
#proof[
343+
_Construction._ For graph $G = (V, E)$ with $k$ colors:
344+
345+
_Variables:_ Binary $x_(v,c) in {0, 1}$ for each vertex $v in V$ and color $c in {1, ..., k}$. Interpretation: $x_(v,c) = 1$ iff vertex $v$ has color $c$.
346+
347+
_Constraints:_ (1) Each vertex has exactly one color: $sum_(c=1)^k x_(v,c) = 1$ for all $v in V$. (2) Adjacent vertices have different colors: $x_(u,c) + x_(v,c) <= 1$ for all $(u, v) in E$ and $c in {1, ..., k}$.
348+
349+
_Objective:_ Feasibility problem (minimize 0).
350+
351+
_Correctness._ ($arrow.r.double$) A valid $k$-coloring assigns exactly one color per vertex with different colors on adjacent vertices; setting $x_(v,c) = 1$ for the assigned color satisfies all constraints. ($arrow.l.double$) Any feasible ILP solution has exactly one $x_(v,c) = 1$ per vertex; this defines a coloring, and constraint (2) ensures adjacent vertices differ.
352+
353+
_Solution extraction._ For each vertex $v$, find $c$ with $x_(v,c) = 1$; assign color $c$ to $v$.
354+
]
355+
334356
#theorem[
335357
*(Factoring $arrow.r$ ILP)* Integer factorization reduces to binary ILP using McCormick linearization with $O(m n)$ variables and constraints.
336358
]
@@ -400,6 +422,7 @@ assert_eq!(p * q, 15); // e.g., (3, 5) or (5, 3)
400422
[CircuitSAT $arrow.r$ SpinGlass], [$O(|"gates"|)$], [@whitfield2012 @lucas2014],
401423
[Factoring $arrow.r$ CircuitSAT], [$O(m n)$], [Folklore],
402424
[SpinGlass $arrow.l.r$ MaxCut], [$O(n + |J|)$], [@barahona1982 @lucas2014],
425+
table.cell(fill: gray)[Coloring $arrow.r$ ILP], table.cell(fill: gray)[$O(|V| dot k + |E| dot k)$], table.cell(fill: gray)[—],
403426
table.cell(fill: gray)[Factoring $arrow.r$ ILP], table.cell(fill: gray)[$O(m n)$], table.cell(fill: gray)[—],
404427
),
405428
caption: [Summary of reductions. Gray rows indicate trivial reductions.]

docs/src/reductions/graph.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ flowchart TD
6161
SG_f64 <--> QUBO
6262
SG_i32 <--> MaxCut
6363
64+
%% ILP reductions
65+
Coloring --> ILP
66+
6467
%% Styling
6568
style Factoring fill:#f9f,stroke:#333
6669
style CircuitSAT fill:#f9f,stroke:#333
@@ -129,6 +132,7 @@ println!("Types: {}, Reductions: {}", graph.num_types(), graph.num_reductions())
129132
| Satisfiability | DominatingSet | No |
130133
| CircuitSAT | SpinGlass&lt;i32&gt; | No |
131134
| Factoring | CircuitSAT | No |
135+
| Coloring | ILP | No |
132136
| Factoring | ILP | No |
133137

134138
## API

0 commit comments

Comments
 (0)