Skip to content

feat: add 8 Tier 1a reduction rules (#770)#777

Merged
isPANN merged 6 commits intomainfrom
tier1a-batch-rules
Mar 26, 2026
Merged

feat: add 8 Tier 1a reduction rules (#770)#777
isPANN merged 6 commits intomainfrom
tier1a-batch-rules

Conversation

@zazabap
Copy link
Copy Markdown
Collaborator

@zazabap zazabap commented Mar 26, 2026

Summary

Implements 8 simple, verified Tier 1a reduction rules from Garey & Johnson (issue #770):

# Source → Target Technique Lines
#199 HamiltonianCircuit → HamiltonianPath Vertex duplication + pendants ~80
#201 KClique → SubgraphIsomorphism Pattern = K_k ~60
#203 Partition → MultiprocessorScheduling m=2, D=S/2 ~60
#234 HamiltonianPath → IsomorphicSpanningTree T = P_n ~55
#259 HamiltonianCircuit → BottleneckTravelingSalesman {1,2}-distances ~80
#464 KClique → ConjunctiveBooleanQuery k-clique as Boolean CQ ~75
#487 ExactCoverBy3Sets → StaffScheduling Subset-to-schedule encoding ~60
#753 Satisfiability → NAESatisfiability Sentinel variable construction ~65

Each rule includes:

  • Full ReduceTo implementation with #[reduction(overhead = {...})]
  • ReductionResult with extract_solution()
  • Canonical example-db spec
  • 4-9 unit tests (closed-loop, edge cases, extraction, negative cases)

Fixes #199, Fixes #201, Fixes #203, Fixes #234, Fixes #259, Fixes #464, Fixes #487, Fixes #753

Test plan

  • make check passes (fmt + clippy + test)
  • CI passes
  • All 8 issues auto-close on merge

🤖 Generated with Claude Code

Implement 8 simple, verified reduction rules from Garey & Johnson:

- HamiltonianCircuit → HamiltonianPath (#199): vertex duplication + pendants
- KClique → SubgraphIsomorphism (#201): pattern = K_k
- Partition → MultiprocessorScheduling (#203): m=2, D=S/2
- HamiltonianPath → IsomorphicSpanningTree (#234): T = P_n
- HamiltonianCircuit → BottleneckTravelingSalesman (#259): {1,2}-distances
- KClique → ConjunctiveBooleanQuery (#464): k-clique as Boolean CQ
- ExactCoverBy3Sets → StaffScheduling (#487): subset-to-schedule encoding
- Satisfiability → NAESatisfiability (#753): sentinel variable construction

Each rule includes full test coverage (closed-loop, edge cases, extraction).

Fixes #199, Fixes #201, Fixes #203, Fixes #234, Fixes #259, Fixes #464, Fixes #487, Fixes #753

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 99.02597% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.82%. Comparing base (a69b719) to head (0033e2a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/hamiltoniancircuit_hamiltonianpath.rs 94.20% 4 Missing ⚠️
src/rules/graph_helpers.rs 92.10% 3 Missing ⚠️
src/rules/satisfiability_naesatisfiability.rs 97.95% 1 Missing ⚠️
..._tests/rules/partition_multiprocessorscheduling.rs 98.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #777      +/-   ##
==========================================
+ Coverage   97.79%   97.82%   +0.02%     
==========================================
  Files         582      599      +17     
  Lines       65454    66337     +883     
==========================================
+ Hits        64012    64893     +881     
- Misses       1442     1444       +2     

☔ 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.

@zazabap zazabap requested a review from Copilot March 26, 2026 12:45
@zazabap zazabap moved this to Review pool in Good issues Mar 26, 2026
@zazabap zazabap moved this from Review pool to Under review in Good issues Mar 26, 2026
@zazabap
Copy link
Copy Markdown
Collaborator Author

zazabap commented Mar 26, 2026

Agentic Review Report

Structural Check

Rule Math OK Overhead OK Registration Tests Example Issues
HC → HP ⚠️ MINOR 6 num_edges is worst-case upper bound (no deg(0) getter available)
HC → BTSP 4 None
HP → IST 5 None
KClique → SubIso 5 None
KClique → CBQ 5 None
Partition → MPS ⚠️ MINOR 7 Overhead missing num_processors and deadline fields
XC3S → StaffSched 5 None
SAT → NAESAT 9 None

All 8 reductions mathematically verified. Forward/backward correctness confirmed. Solution extraction inverts correctly. Example specs validated with concrete instances.

Minor findings:

  • HC→HP: num_edges = "num_edges + num_vertices + 1" is an upper bound (actual = m + deg(0) + 2). No getter for deg(0), so this is the tightest expressible formula.
  • Partition→MPS: Only num_tasks declared in overhead. Could add num_processors = "2" and deadline = "total_sum / 2".

Quality Check

Design Principles:

  • DRY: HC→BTSP extract_solution (~55 lines) and reduce_to (~12 lines) are verbatim copies of HC→TSP. Should be refactored into shared helpers.
  • KISS: All 8 rules are appropriately simple for textbook reductions. No over-engineering.
  • Cohesion: Each rule is self-contained with its own struct, impl, example, and tests. Good.

Test Quality:

Rule # Tests Closed-loop Edge cases Quality
HC → BTSP 4 Non-Hamiltonian, manual extraction Strong
HC → HP 6 No-circuit, reversed path, triangle Strong
HP → IST 5 Star graph, complete graph, triangle Strong
KClique → SubIso 6 No clique, k=1, k=2 Strong
KClique → CBQ 5 No clique, k=1 Strong
Partition → MPS 8 Odd sum, single element, equal, two elements Excellent
SAT → NAESAT 9 Unsat, empty, sentinel T/F, all-solutions Excellent
XC3S → StaffSched 5 No solution, unique cover, structure Strong

Issues:

  • MEDIUM src/rules/hamiltoniancircuit_bottlenecktravelingsalesman.rs:26-82 — DRY violation: extract_solution duplicates HC→TSP verbatim
  • LOW — Inconsistent import style: some test files use use super::*;, others use explicit imports
  • INFO — No empty-graph / k=0 edge case tests for HC→BTSP, KClique→CBQ, KClique→SubIso

Agentic Feature Tests

Rule In catalog pred show pred path pred reduce Notes
HC → HamiltonianPath Grows 6→9 vertices
HC → BottleneckTSP Complete graph, {1,2} weights
HP → IsomorphicSpanningTree Tree = path graph
KClique → SubgraphIsomorphism Pattern = K_3
KClique → ConjunctiveBooleanQuery k² conjuncts
Partition → MultiprocessorScheduling 2 processors, D=S/2
XC3S → StaffScheduling Schedules mirror subsets
SAT → NAESatisfiability Sentinel variable added

All 8 rules pass all CLI integration tests. No failures or unexpected behavior.


Generated by review-pipeline

@zazabap zazabap moved this from Under review to Final review in Good issues Mar 26, 2026
Copy link
Copy Markdown

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

Adds eight Tier 1a reduction rules (Garey & Johnson) to the reductions registry, along with canonical example-db specs and unit tests to validate closed-loop correctness and solution extraction.

Changes:

  • Implement 8 new ReduceTo reductions (SAT→NAE-SAT, Partition→MPS, HC→HP, HC→BTSP, HP→IST, KClique→SubgraphIsomorphism, KClique→CBQ, X3C→StaffScheduling).
  • Add focused unit tests per rule (closed-loop, structure checks, extraction, and negative cases).
  • Register new rule modules and wire their canonical example specs into src/rules/mod.rs.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/rules/mod.rs Registers the new rule modules and includes their canonical example specs in the rule example-db export list.
src/rules/satisfiability_naesatisfiability.rs Implements SAT→NAE-SAT sentinel-variable reduction + example-db spec + test module hook.
src/rules/partition_multiprocessorscheduling.rs Implements Partition→MultiprocessorScheduling restriction-style reduction + example-db spec + test hook.
src/rules/kclique_subgraphisomorphism.rs Implements KClique→SubgraphIsomorphism by using a complete pattern graph K_k + example-db spec + test hook.
src/rules/kclique_conjunctivebooleanquery.rs Implements KClique→CBQ encoding clique as a Boolean conjunctive query + example-db spec + test hook.
src/rules/hamiltonianpath_isomorphicspanningtree.rs Implements HamiltonianPath→IsomorphicSpanningTree via T = P_n + example-db spec + test hook.
src/rules/hamiltoniancircuit_hamiltonianpath.rs Implements HamiltonianCircuit→HamiltonianPath via vertex-duplication + pendant endpoints + example-db spec + test hook.
src/rules/hamiltoniancircuit_bottlenecktravelingsalesman.rs Implements HamiltonianCircuit→BTSP using {1,2}-weights on the complete graph + example-db spec + test hook.
src/rules/exactcoverby3sets_staffscheduling.rs Implements X3C→StaffScheduling subset-to-schedule encoding + example-db spec + test hook.
src/unit_tests/rules/satisfiability_naesatisfiability.rs Unit tests for SAT→NAE-SAT (structure, extraction, edge cases).
src/unit_tests/rules/partition_multiprocessorscheduling.rs Unit tests for Partition→MPS (structure, odd sum, extraction, small cases).
src/unit_tests/rules/kclique_subgraphisomorphism.rs Unit tests for KClique→SubgraphIsomorphism (yes/no cases, k=1/2/3).
src/unit_tests/rules/kclique_conjunctivebooleanquery.rs Unit tests for KClique→CBQ (structure, satisfiable/unsatisfiable, extraction, k=1).
src/unit_tests/rules/hamiltonianpath_isomorphicspanningtree.rs Unit tests for HP→IST (closed-loop, multiple graph families, negative case).
src/unit_tests/rules/hamiltoniancircuit_hamiltonianpath.rs Unit tests for HC→HP (closed-loop, structure, extraction, negative case).
src/unit_tests/rules/hamiltoniancircuit_bottlenecktravelingsalesman.rs Unit tests for HC→BTSP (closed-loop, weight structure, bottleneck gap, extraction).
src/unit_tests/rules/exactcoverby3sets_staffscheduling.rs Unit tests for X3C→StaffScheduling (closed-loop, no-solution, unique-cover, structure).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- HC→HP: special-case n < 3 to avoid panic on empty/tiny graphs
- SAT→NAESAT: handle empty clauses (map to fixed unsatisfiable NAE clause)
- SAT→NAESAT: guard extract_solution against short configs with assert
- SAT→NAESAT test: fix comment (variable 3 → variable 4)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zazabap
Copy link
Copy Markdown
Collaborator Author

zazabap commented Mar 26, 2026

Solver Reachability Summary

Source problems (all have existing solver paths — no change needed)

Source Solver path
HamiltonianCircuit HC → TSP → ILP/bool
HamiltonianPath HP → ILP/bool
KClique KC → ILP/bool
Partition Partition → Knapsack → ILP/bool
ExactCoverBy3Sets XC3S → ILP/bool
Satisfiability SAT → CircuitSAT → ILP/bool

Target problems

Target Outgoing reductions ILP solvable? Notes
HamiltonianPath → IST, → ILP/bool Direct ILP path
BottleneckTravelingSalesman → ILP/i32 Uses i32 variant
IsomorphicSpanningTree → ILP/bool Direct ILP path
SubgraphIsomorphism → ILP/bool Direct ILP path
MultiprocessorScheduling → ILP/bool Direct ILP path
NAESatisfiability → ILP/bool Direct ILP path
ConjunctiveBooleanQuery None Dead end — no outgoing reductions. Needs CBQ → ILP.
StaffScheduling None Dead end — no outgoing reductions. Needs StaffScheduling → ILP.

Action items

Two target problems are sink nodes (no outgoing reductions, unsolvable via ILP). They can still be solved by BruteForce, but ILP reductions would complete the solver coverage:

  • ConjunctiveBooleanQuery → ILP
  • StaffScheduling → ILP

isPANN and others added 3 commits March 26, 2026 21:58
- Extract duplicated edges_to_cycle_order logic from HC→TSP and HC→BTSP
  into graph_helpers module (-110 lines)
- Use SimpleGraph::complete(k) in KClique→SubgraphIsomorphism
- Use .edges() directly in KClique→CBQ instead of O(n²) has_edge loop
- Replace assert! with graceful fallback in SAT→NAE-SAT extract_solution

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- simplify new graph reductions by using shared graph constructors and a shared KClique selection helper
- reduce control-flow and repeated setup in HamiltonianCircuit/Partition-related rule code and tests
- add regression coverage for HamiltonianCircuit small-n and Satisfiability empty-clause edge cases
- remove the unused example variable warning and align rustfmt config with the stable toolchain
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@isPANN isPANN merged commit 704ed6a into main Mar 26, 2026
5 checks passed
@isPANN isPANN moved this from Final review to Done in Good issues Mar 27, 2026
zazabap added a commit that referenced this pull request Apr 3, 2026
… entries

Complete missing documentation and test coverage for 41 reduction rules
shipped across PRs #777, #779, #804, and #972.

Check 10: 39 new `test_find_rule_example_*` tests in example_db.rs covering
all cross-problem reductions from the four PRs (ILP i32→bool excluded as a
same-name variant edge).

Check 11: 31 new `#reduction-rule(...)` entries in reductions.typ — 30 for
cross-problem reductions (PRs #777, #779, #972) plus 1 for the ILP<i32> →
ILP<bool> variant reduction via FBBT + truncated binary encoding.

Closes #974

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
GiggleLiu added a commit that referenced this pull request Apr 4, 2026
… rules (#997)

* docs: add design spec for proposed reductions Typst note

Covers 9 reductions: 2 NP-hardness chain extensions (#973, #198),
4 Tier 1a blocked issues (#379, #380, #888, #822), and
3 Tier 1b blocked issues (#892, #894, #890).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(#974): add 39 example-db lookup tests and 31 paper reduction-rule entries

Complete missing documentation and test coverage for 41 reduction rules
shipped across PRs #777, #779, #804, and #972.

Check 10: 39 new `test_find_rule_example_*` tests in example_db.rs covering
all cross-problem reductions from the four PRs (ILP i32→bool excluded as a
same-name variant edge).

Check 11: 31 new `#reduction-rule(...)` entries in reductions.typ — 30 for
cross-problem reductions (PRs #777, #779, #972) plus 1 for the ILP<i32> →
ILP<bool> variant reduction via FBBT + truncated binary encoding.

Closes #974

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Delete docs/superpowers/specs/2026-03-31-proposed-reductions-note-design.md

* docs: add Institute of Science Tokyo affiliation to paper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: remove accidentally committed docs/superpowers directory

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: add worked example for HamiltonianCircuit -> RuralPostman reduction

Upgrade the prose-only reduction-rule entry to include data-driven
example with load-example binding, pred-commands, three construction
steps, and multiplicity note.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for HamiltonianCircuit -> HamiltonianPath reduction

Upgrade the prose-only reduction-rule entry with load-example data binding,
pred-commands reproducibility block, and a 3-step worked example showing the
vertex-splitting construction on a C4 cycle graph.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for HamiltonianCircuit -> BottleneckTravelingSalesman reduction

Add data-driven example with load-example binding, pred-commands block,
step-by-step construction walkthrough, and solution verification.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for HamiltonianCircuit -> StrongConnectivityAugmentation reduction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: add worked example for HamiltonianCircuit -> QuadraticAssignment paper entry

Upgrade the prose-only reduction-rule entry to include a data-driven
worked example with load-example binding, pred-commands block, and
step-by-step construction/verification using the C4 cycle graph fixture.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for Partition -> BinPacking reduction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for ThreePartition -> JobShopScheduling reduction

Add data-driven example with load-example binding, pred-commands block,
and step-by-step walkthrough showing the m=1 canonical instance with
3 elements, sizes (4,5,6), bound B=15 on 2 machines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: add worked example for Partition → MultiprocessorScheduling reduction

Upgrade the prose-only reduction-rule entry to include a data-driven
worked example with load-example binding, pred-commands block, and
step-by-step verification of the canonical witness.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for ThreePartition -> ResourceConstrainedScheduling reduction

Also remove duplicate Partition -> ShortestWeightConstrainedPath entry that caused a label collision.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for ThreePartition -> SequencingWithReleaseTimesAndDeadlines reduction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: add worked example for ThreePartition -> FlowShopScheduling reduction

Add data-driven example with load-example binding, pred-commands block,
and step-by-step walkthrough showing source instance, job construction,
separator window mechanism, and end-to-end solution verification.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for KSatisfiability -> KClique reduction

Add data-driven worked example with load-example binding, pred-commands
reproducibility block, step-by-step construction walkthrough, and
end-to-end solution verification for the 3-SAT to k-clique reduction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for MinimumVertexCover -> MinimumFeedbackArcSet reduction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for Satisfiability -> NAESatisfiability reduction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for ExactCoverBy3Sets -> MaximumSetPacking reduction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for KSatisfiability -> MinimumVertexCover reduction

Also remove duplicate ThreePartition -> FlowShopScheduling entry that caused
a duplicate label compilation error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs(paper): add worked example for MaxCut -> MinimumCutIntoBoundedSets reduction

Also remove duplicate ThreePartition -> FlowShopScheduling prose entry
that was left over from a merge conflict.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove duplicate SAT→NAESatisfiability prose-only entry

Leftover from parallel worktree merge — the data-driven entry
was placed at line ~10136 by the SAT→NAE agent, but the original
prose-only entry at line ~13454 was not cleaned up.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: GiggleLiu <cacate0129@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

4 participants