Skip to content

Commit cc35756

Browse files
GiggleLiuclaude
andauthored
feat: add problem_size() to Problem trait with validation (#76)
* feat: add problem_size() to Problem trait (compile-breaking) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: implement problem_size() for all graph problems Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: implement problem_size() for SAT problems Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: implement problem_size() for set problems Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: implement problem_size() for optimization problems Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: implement problem_size() for specialized problems Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: validate overhead variable names against problem_size in find_cheapest_path Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: add problem_size() unit tests for all 21 problem types Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: add find_cheapest_path integration test with problem_size Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: update test ProblemSize variable names to match problem_size() components Existing tests used arbitrary variable names like "n" and "m" that don't match the overhead polynomial variable names. Updated to use correct names (num_vertices, num_edges) or empty ProblemSize to pass the new validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: format Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: split ProblemSize into type-level names + instance-level values Split the `Problem::problem_size()` method into two parts: - `problem_size_names() -> &'static [&'static str]` (type-level, static) - `problem_size_values(&self) -> Vec<usize>` (instance-level) A free function `problem_size()` combines them into a `ProblemSize`. This enables compile-time overhead validation: `ReductionGraph::new()` now asserts that each reduction's overhead input variables are a subset of the source's `problem_size_names`, and output fields are a subset of the target's. This caught and fixed several latent bugs: - `num_elements` → `universe_size` in SetPacking/SetCovering overheads - `num_gates` → `num_variables`/`num_assignments` in Factoring→CircuitSAT - `num_variables` → `num_vars` in SAT→CircuitSAT input - `num_colors` removed from KColoring size (k is a type parameter) - KColoring→ILP/QUBO overheads updated to not reference num_colors Also includes earlier work from this branch: - BicliqueCover refactored to use BipartiteGraph as input - Polynomial composition (mul, pow, substitute) for symbolic overhead - evaluate_path_overhead + compose_path_overhead on ReductionGraph - 3-SAT→MIS triangular overhead test with numeric and symbolic asserts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: extract validate_overhead_variables and use ILP for factoring test - Extract overhead validation logic from ReductionGraph::new() and find_cheapest_path() into standalone validate_overhead_variables() - Add 5 unit tests for the validation function - Replace brute-force SpinGlass solve with ILP solver in test_jl_parity_factoring_to_spinglass_path (>60s → <1s) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: assert_eq in ProblemSize + correct SAT→KColoring edge overhead - Use assert_eq! instead of debug_assert_eq! in from_names_values() so length mismatches are caught in release builds - Fix SAT→KColoring num_edges polynomial: 3*num_vars + 11*num_literals - 9*num_clauses + 3 (was incorrectly copied from num_vertices) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: add reduction overhead section to getting-started Show evaluate_path_overhead and compose_path_overhead in the chained reduction example. The getting-started guide now explains how to inspect problem size growth along a reduction path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 776e855 commit cc35756

102 files changed

Lines changed: 2592 additions & 485 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benches/solver_benchmarks.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,10 @@ fn bench_comparison(c: &mut Criterion) {
197197
let solver = BruteForce::new();
198198

199199
// MaximumIndependentSet with 8 vertices
200-
let is_problem =
201-
MaximumIndependentSet::new(SimpleGraph::new(8, vec![(0, 1), (2, 3), (4, 5), (6, 7)]), vec![1i32; 8]);
200+
let is_problem = MaximumIndependentSet::new(
201+
SimpleGraph::new(8, vec![(0, 1), (2, 3), (4, 5), (6, 7)]),
202+
vec![1i32; 8],
203+
);
202204
group.bench_function("MaximumIndependentSet", |b| {
203205
b.iter(|| solver.find_best(black_box(&is_problem)))
204206
});
@@ -228,7 +230,10 @@ fn bench_comparison(c: &mut Criterion) {
228230
});
229231

230232
// MaxCut with 8 vertices
231-
let mc_problem = MaxCut::new(SimpleGraph::new(8, vec![(0, 1), (2, 3), (4, 5), (6, 7)]), vec![1, 1, 1, 1]);
233+
let mc_problem = MaxCut::new(
234+
SimpleGraph::new(8, vec![(0, 1), (2, 3), (4, 5), (6, 7)]),
235+
vec![1, 1, 1, 1],
236+
);
232237
group.bench_function("MaxCut", |b| {
233238
b.iter(|| solver.find_best(black_box(&mc_problem)))
234239
});

docs/paper/reductions.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
]
247247

248248
#block(width: 100%, inset: (x: 2em, y: 1em))[
249-
*Abstract.* We present formal definitions for computational problems and polynomial-time reductions implemented in the `problemreductions` library. For each reduction, we state theorems with constructive proofs that preserve solution structure.
249+
*Abstract.* We present formal definitions for computational problems and polynomial-time reductions implemented in the `problem-reductions` library. For each reduction, we state theorems with constructive proofs that preserve solution structure.
250250
]
251251

252252

0 commit comments

Comments
 (0)