Skip to content

Conversation

@GiggleLiu
Copy link
Contributor

Summary

Implements set-theoretic reduction path finding with automatic registration, addressing issues #10 and #11.

Key features:

  • Graph type hierarchy: GraphMarker, GraphSubtype traits with UnitDiskGraph ⊆ PlanarGraph ⊆ SimpleGraph relationships
  • Automatic reduction registration: Uses inventory crate for auto-discovery of reductions at link time
  • Set-theoretic path validation: Rule C→D applies for A→B only if A ⊆ C and D ⊆ B
  • Custom cost functions: PathCostFn trait with Minimize, MinimizeSteps, MinimizeWeighted, etc.
  • Polynomial overhead: Reduction overhead expressed as polynomials over problem size variables
  • Parametric Problem trait: All problems now have NAME, GraphType, Weight associated items

Changes:

  • New modules: graph_types.rs, polynomial.rs, rules/registry.rs, rules/cost.rs
  • Updated Problem trait with parametric types
  • Updated all 19+ Problem implementations
  • Rewrote ReductionGraph with Dijkstra-based path finding
  • Registered 17 reductions with overhead metadata
  • Added 8 integration tests

Test Plan

  • All 691 tests pass
  • Clippy clean with -D warnings
  • Integration tests verify:
    • Graph hierarchy (UnitDisk ⊆ Planar ⊆ Simple)
    • Rule applicability (set-theoretic validation)
    • Multi-step paths (Factoring → CircuitSAT → SpinGlass)
    • Cost function path finding
    • Bidirectional reductions

Closes #10, Closes #11

🤖 Generated with Claude Code

GiggleLiu and others added 14 commits January 26, 2026 20:38
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
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 98.53896% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.04%. Comparing base (a4ff2df) to head (f25abea).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/graph.rs 96.41% 9 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
Copy link

Copilot AI left a 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 the inventory crate
  • Implements polynomial overhead model for expressing reduction complexity as polynomials over input size variables
  • Rewrites ReductionGraph with Dijkstra-based path finding that validates reductions using set-theoretic rules (A ⊆ C and D ⊆ B)
  • Updates the Problem trait 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.


// Declare the graph type hierarchy
declare_graph_subtype!(UnitDiskGraph => PlanarGraph);
declare_graph_subtype!(UnitDiskGraph => SimpleGraph);
Copy link

Copilot AI Jan 26, 2026

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.

Copilot uses AI. Check for mistakes.
self
}


Copy link

Copilot AI Jan 26, 2026

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.

Suggested change

Copilot uses AI. Check for mistakes.
/// 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))
Copy link

Copilot AI Jan 26, 2026

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.

Copilot uses AI. Check for mistakes.
- 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
@GiggleLiu GiggleLiu merged commit f81fef3 into main Jan 26, 2026
6 checks passed
@GiggleLiu GiggleLiu deleted the feat/set-theoretic-reductions branch January 26, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TODO: a set theory based reduction path Design Decision: Type-erased names in ReductionGraph topology

2 participants