Skip to content

Commit 487517e

Browse files
GiggleLiuclaude
andauthored
perf: optimize pathdecomposition and add ground truth tests (#54)
* docs: add documentation improvements design plan 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: add documentation improvements implementation plan 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * perf: optimize pathdecomposition and add ground truth tests Build adjacency list once and pass by reference instead of rebuilding from edge list in every function call during recursive branch-and-bound. Also eliminate duplicate vsep_updated computation by reusing sorted costs. Add pathwidth ground truth JSON dataset (21 standard graphs) and 4 new tests that verify correctness against it. Mark tutte (46v, ~10s B&B) and tutte MIS overhead (1232v grid, ~10s ILP) as #[ignore] for routine runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: add reduction workflow diagram Add a visual diagram illustrating the core reduction workflow: Problem A -> reduce_to() -> Problem B -> find_best() -> Solution B -> extract_solution() -> Solution A Includes both light and dark theme SVG variants for mdBook. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: add module overview diagram Add a diagram showing how the main modules in the codebase relate: - models/ contains problem type implementations - rules/ contains reduction rules that import models - registry/ collects reduction metadata at compile time - solvers/ solve problem instances 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: add trait hierarchy diagram 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: rewrite Getting Started page with reduction workflow diagram Rewrites the Getting Started page to: - Start with "what this library does" overview - Include the reduction workflow diagram (light/dark variants) - Show a complete example with step-by-step comments - Document chaining reductions pattern - Add solvers section with links to API docs - Document JSON resources (reduction_graph.json, problem_schemas.json) - Update Next Steps section with relevant links 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: update Architecture with diagrams and current API - Add intro text and Module Overview section with SVG diagram - Add Trait Hierarchy section with diagram and code examples - Fix outdated API: solution_size() -> evaluate() - Update method table with Metric, dims(), evaluate() - Remove reference to deleted ConstraintSatisfactionProblem trait - Fix ReduceTo syntax: problem.reduce_to::<T>() -> ReduceTo::<T>::reduce_to(&problem) - Add Contributing section with issue-based workflow 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: regenerate reduction_graph.json 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: single source location for JSON schemas - Export examples now write directly to docs/src/reductions/ - Paper uses --root flag to access files via relative path - Remove duplicate files from docs/paper/ - Update doc comments with correct paths 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: resolve rustdoc and mdbook warnings - Escape `Weighted<i32>` in doc comment to avoid HTML tag warning - Remove orphan </details> tag in arch.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: make arch.md orthogonal with getting-started.md - Remove duplicated workflow/usage explanations - Focus on implementation details for contributors - Rename sections to "Implementing X" for clarity - Reference getting-started.md for usage examples - Streamline JSON schema examples 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * update * diagrams * refactor: Solver::find_best returns Option, polish docs - Change Solver::find_best to return Option<Vec<usize>> (was Vec<Vec<usize>>) for symmetry with find_satisfying - Make BruteForce::find_all_best public for multi-solution queries - Migrate all call sites: tests use find_all_best, examples use find_all_best - Polish getting-started.md, arch.md, introduction.md - Align arch.md sections with module overview (Models, Rules, Registry, Solvers) - Add "Call for Contributions" section to introduction with authorship incentive Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: remove stale docs/src/claude.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: address PR review comments - Move HashSet import to top of file (pathdecomposition test) - Pretty-print pathwidth_ground_truth.json for readability Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3ee5da8 commit 487517e

123 files changed

Lines changed: 5768 additions & 2284 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.

.claude/CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ enum Direction { Maximize, Minimize }
7272
### Key Patterns
7373
- Problems parameterized by weight type `W` and graph type `G`
7474
- `ReductionResult` provides `target_problem()` and `extract_solution()`
75-
- `Solver::find_best()` for optimization problems, `Solver::find_satisfying()` for `Metric = bool`
75+
- `Solver::find_best()``Option<Vec<usize>>` for optimization problems; `Solver::find_satisfying()``Option<Vec<usize>>` for `Metric = bool`
76+
- `BruteForce::find_all_best()` / `find_all_satisfying()` return `Vec<Vec<usize>>` for all optimal/satisfying solutions
7677
- Graph types: SimpleGraph, GridGraph, UnitDiskGraph, Hypergraph
7778
- Weight types: `Unweighted` (marker), `i32`, `f64`
7879
- Weight management via inherent methods (`weights()`, `set_weights()`, `is_weighted()`), not traits

.claude/rules/testing.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ New code must have >95% test coverage. Run `make coverage` to check.
2020

2121
Follow the reference files above for exact API usage. Summary:
2222

23-
- `solver.find_best(&problem)` — for optimization problems (`OptimizationProblem`, `Metric = SolutionSize<W>`)
24-
- `solver.find_satisfying(&problem)` — for satisfaction problems (`Metric = bool`)
23+
- `solver.find_best(&problem)``Option<Vec<usize>>` — one optimal solution for optimization problems
24+
- `solver.find_satisfying(&problem)``Option<Vec<usize>>` — one satisfying assignment
25+
- `solver.find_all_best(&problem)``Vec<Vec<usize>>` — all optimal solutions (BruteForce only)
26+
- `solver.find_all_satisfying(&problem)``Vec<Vec<usize>>` — all satisfying assignments (BruteForce only)
2527
- `problem.evaluate(&config)` — returns `SolutionSize::Valid(value)` / `SolutionSize::Invalid` for optimization, `bool` for satisfaction
2628

2729
## File Organization

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile for problemreductions
22

3-
.PHONY: help build test fmt clippy doc mdbook paper examples clean coverage rust-export compare qubo-testdata export-schemas release run-plan
3+
.PHONY: help build test fmt clippy doc mdbook paper examples clean coverage rust-export compare qubo-testdata export-schemas release run-plan diagrams
44

55
# Default target
66
help:
@@ -11,6 +11,7 @@ help:
1111
@echo " fmt-check - Check code formatting"
1212
@echo " clippy - Run clippy lints"
1313
@echo " doc - Build mdBook documentation"
14+
@echo " diagrams - Generate SVG diagrams from Typst (light + dark)"
1415
@echo " mdbook - Build and serve mdBook (with live reload)"
1516
@echo " paper - Build Typst paper (requires typst)"
1617
@echo " coverage - Generate coverage report (requires cargo-llvm-cov)"
@@ -47,16 +48,26 @@ clippy:
4748
# Build mdBook documentation
4849
doc:
4950
cargo run --example export_graph
50-
cp docs/paper/reduction_graph.json docs/src/reductions/
51+
cargo run --example export_schemas
5152
mdbook build docs
5253
RUSTDOCFLAGS="--default-theme=dark" cargo doc --all-features --no-deps
5354
rm -rf docs/book/api
5455
cp -r target/doc docs/book/api
5556

57+
# Generate SVG diagrams from Typst sources (light + dark themes)
58+
TYPST_DIAGRAMS := $(wildcard docs/src/static/*.typ)
59+
diagrams:
60+
@for src in $(TYPST_DIAGRAMS); do \
61+
base=$$(basename $$src .typ); \
62+
echo "Compiling $$base..."; \
63+
typst compile $$src --input dark=false docs/src/static/$$base.svg; \
64+
typst compile $$src --input dark=true docs/src/static/$$base-dark.svg; \
65+
done
66+
5667
# Build and serve mdBook with API docs
5768
mdbook:
5869
cargo run --example export_graph
59-
cp docs/paper/reduction_graph.json docs/src/reductions/
70+
cargo run --example export_schemas
6071
RUSTDOCFLAGS="--default-theme=dark" cargo doc --all-features --no-deps
6172
mdbook build
6273
rm -rf book/api
@@ -84,7 +95,7 @@ export-schemas:
8495
paper: examples
8596
cargo run --example export_graph
8697
cargo run --example export_schemas
87-
cd docs/paper && typst compile reductions.typ reductions.pdf
98+
cd docs/paper && typst compile --root .. reductions.typ reductions.pdf
8899

89100
# Generate coverage report (requires: cargo install cargo-llvm-cov)
90101
coverage:

0 commit comments

Comments
 (0)