-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Implement set-theoretic reduction path finding #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Design document addressing issues #10 and #11: - Parametric problem modeling with graph type + weight type - Set-theoretic path validation (A ⊆ C, D ⊆ B) - Automatic registration via inventory crate - Polynomial overhead model for output size - Customizable cost functions for path optimization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Detailed step-by-step plan with 25+ bite-sized tasks across 7 phases: 1. Foundation types (graph markers, NumericWeight, Polynomial) 2. Reduction registration (inventory, ReductionEntry, overhead) 3. Update Problem trait (NAME, GraphType, Weight parameters) 4. Update problem implementations (all 14+ problem types) 5. Rewrite ReductionGraph (set-theoretic validation, Dijkstra) 6. Update reduction implementations (add registration) 7. Integration tests Each task includes exact file paths, complete code, and commit points. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add three new associated items to the Problem trait for parametric problem modeling and registration: - const NAME: Base name of the problem type (e.g., "IndependentSet") - type GraphType: The graph type marker this problem operates on - type Weight: The numeric weight type for this problem Update test problem types (SimpleWeightedProblem, SimpleCsp, MultiFlavorProblem) to implement the new requirements. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add const NAME, type GraphType, and type Weight to all Problem trait implementations across graph, set, satisfiability, optimization, and specialized problem types - Update CSP implementations to use 'static bounds for compatibility - Add blanket implementation for NumericWeight trait to support generic weight types that satisfy the required bounds - Update all reduction rules with 'static lifetime bounds - Update test problems in brute_force.rs and traits.rs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add ReductionEdge struct to store graph type info and overhead on edges - Build graph hierarchy from GraphSubtypeEntry via inventory - Implement transitive closure for graph type subtyping - Add is_graph_subtype() and rule_applicable() for set-theoretic validation - Add find_cheapest_path() using Dijkstra with custom cost functions - Auto-discover reductions from inventory::iter::<ReductionEntry> - Export ReductionEdge from rules module - Keep backward compatibility with manual reduction registration - Add comprehensive tests for new functionality 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add inventory::submit! blocks to all reduction files to enable automatic registration with the ReductionGraph. This allows the graph to discover all available reductions at runtime without manual registration. Changes: - Modified ReductionEntry to use overhead_fn (function pointer) instead of overhead field to avoid static allocation issues with Vec/Polynomial - Added inventory::submit! to 12 reduction files with proper overhead polynomials: - vertexcovering_independentset.rs (2 reductions) - independentset_setpacking.rs (2 reductions) - matching_setpacking.rs (1 reduction) - vertexcovering_setcovering.rs (1 reduction) - spinglass_maxcut.rs (2 reductions) - spinglass_qubo.rs (2 reductions) - sat_independentset.rs (1 reduction) - sat_coloring.rs (1 reduction) - sat_dominatingset.rs (1 reduction) - sat_ksat.rs (2 reductions) - factoring_circuit.rs (1 reduction) - circuit_spinglass.rs (1 reduction) - Updated graph.rs to use overhead() method instead of field access - Fixed test_find_cheapest_path_multi_step to use compatible graph types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12 +/- ##
==========================================
+ Coverage 97.98% 98.04% +0.05%
==========================================
Files 55 59 +4
Lines 11659 12265 +606
==========================================
+ Hits 11424 12025 +601
- Misses 235 240 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add additional tests to improve test coverage for: - graph_types.rs: declared subtype relationships, Default/Clone/Copy traits, BipartiteGraph and UnitDiskGraph entries - cost.rs: CustomCost function, Minimize with missing field, MinimizeMax with empty vector - registry.rs: ReductionEntry overhead evaluation, debug formatting, registered entries verification - polynomial.rs: zero polynomial, constant polynomial, monomial scale, polynomial scale, multi-variable monomial 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a comprehensive set-theoretic reduction path finding system that addresses issues #10 and #11 by introducing parametric problem modeling with automatic reduction registration. The implementation enables rigorous validation of reduction paths based on graph type hierarchies and weight type compatibility.
Changes:
- Introduces graph type markers (
GraphMarker,GraphSubtype) with automatic hierarchy registration via theinventorycrate - Implements polynomial overhead model for expressing reduction complexity as polynomials over input size variables
- Rewrites
ReductionGraphwith Dijkstra-based path finding that validates reductions using set-theoretic rules (A ⊆ C and D ⊆ B) - Updates the
Problemtrait with parametric types (NAME,GraphType,Weight) and updates all 19+ problem implementations - Adds 5 customizable cost functions (
Minimize,MinimizeSteps,MinimizeWeighted,MinimizeMax,MinimizeLexicographic) for path optimization - Registers 17 reductions with polynomial overhead metadata using inventory auto-discovery
Reviewed changes
Copilot reviewed 46 out of 47 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/graph_types.rs |
New module defining graph type markers and subtype hierarchy with compile-time traits and runtime registration |
src/polynomial.rs |
New module for polynomial representation of reduction overhead with evaluation and macro support |
src/types.rs |
Adds NumericWeight marker trait for weight type subsumption |
src/traits.rs |
Updates Problem trait with NAME, GraphType, and Weight associated items |
src/rules/registry.rs |
New module for automatic reduction registration via inventory crate |
src/rules/cost.rs |
New module defining PathCostFn trait and built-in cost functions |
src/rules/graph.rs |
Major rewrite implementing set-theoretic path finding with Dijkstra's algorithm and graph hierarchy validation |
src/rules/mod.rs |
Exports new modules and public types |
src/rules/*.rs (reductions) |
Updates all reduction implementations with 'static bounds and inventory registration |
src/models/**/*.rs (problems) |
Updates all problem implementations with new Problem trait requirements |
tests/set_theoretic_tests.rs |
Comprehensive integration tests for graph hierarchy, rule applicability, and path finding |
Cargo.toml |
Adds inventory and ordered-float dependencies |
docs/plans/*.md |
Extensive design and implementation documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/graph_types.rs
Outdated
|
|
||
| // Declare the graph type hierarchy | ||
| declare_graph_subtype!(UnitDiskGraph => PlanarGraph); | ||
| declare_graph_subtype!(UnitDiskGraph => SimpleGraph); |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The direct declaration of UnitDiskGraph => SimpleGraph on line 74 is redundant since it's already implied by the transitive closure of UnitDiskGraph => PlanarGraph (line 73) and PlanarGraph => SimpleGraph (line 75). The build_graph_hierarchy function in src/rules/graph.rs computes the transitive closure, so this relationship will be derived automatically. Consider removing this redundant declaration to keep the code DRY and make the hierarchy easier to maintain.
src/polynomial.rs
Outdated
| self | ||
| } | ||
|
|
||
|
|
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line that should be removed for code consistency.
| /// Evaluate output size given input size. | ||
| pub fn evaluate_output_size(&self, input: &ProblemSize) -> ProblemSize { | ||
| let fields: Vec<_> = self.output_size.iter() | ||
| .map(|(name, poly)| (*name, poly.evaluate(input).round() as usize)) |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of round() when converting polynomial evaluations to usize could lead to unexpected behavior. For example, if a polynomial evaluates to 99.5, it will round to 100, which might not be the intended behavior for problem size calculations. Consider whether ceil() or floor() would be more appropriate, or document why round() is the correct choice for this use case.
- Remove redundant clone() on Copy type (clippy fix) - Add comment explaining why explicit subtype declarations are needed - Remove extra blank line in polynomial.rs - Document round() usage in registry.rs
Summary
Implements set-theoretic reduction path finding with automatic registration, addressing issues #10 and #11.
Key features:
GraphMarker,GraphSubtypetraits withUnitDiskGraph ⊆ PlanarGraph ⊆ SimpleGraphrelationshipsinventorycrate for auto-discovery of reductions at link timePathCostFntrait withMinimize,MinimizeSteps,MinimizeWeighted, etc.NAME,GraphType,Weightassociated itemsChanges:
graph_types.rs,polynomial.rs,rules/registry.rs,rules/cost.rsProblemtrait with parametric typesReductionGraphwith Dijkstra-based path findingTest Plan
-D warningsCloses #10, Closes #11
🤖 Generated with Claude Code