Skip to content

Fix #258: [Rule] HamiltonianCircuit to TravelingSalesman#745

Merged
GiggleLiu merged 4 commits intomainfrom
issue-258
Mar 22, 2026
Merged

Fix #258: [Rule] HamiltonianCircuit to TravelingSalesman#745
GiggleLiu merged 4 commits intomainfrom
issue-258

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

  • add the implementation plan for the HamiltonianCircuit -> TravelingSalesman reduction
  • reserve the issue branch for autonomous pipeline execution

Fixes #258

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Implementation Summary

Changes

  • Added src/rules/hamiltoniancircuit_travelingsalesman.rs implementing the textbook HC -> TSP reduction on the complete graph with 1/2 edge weights, deterministic cycle extraction, and a canonical example fixture.
  • Registered the new rule and canonical example in src/rules/mod.rs.
  • Added src/unit_tests/rules/hamiltoniancircuit_travelingsalesman.rs covering closed-loop behavior, target structure, a non-Hamiltonian cost gap, and solution extraction.
  • Added a new HamiltonianCircuit -> TravelingSalesman theorem and worked example to docs/paper/reductions.typ.

Deviations from Plan

  • Replaced the planned Petersen-graph negative test with a 4-vertex star graph because the Petersen reduction creates a 45-edge TSP instance, which is not tractable for the repository's brute-force target-solver tests.
  • Used make paper's existing export pipeline (export_examples, export_graph, export_schemas) instead of a non-existent make regenerate-fixtures target.

Open Questions

  • None.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 96.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.58%. Comparing base (669f090) to head (ba6ef2b).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/hamiltoniancircuit_travelingsalesman.rs 95.77% 3 Missing ⚠️
...ests/rules/hamiltoniancircuit_travelingsalesman.rs 97.91% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main     #745    +/-   ##
========================================
  Coverage   97.58%   97.58%            
========================================
  Files         415      419     +4     
  Lines       51632    51819   +187     
========================================
+ Hits        50386    50569   +183     
- Misses       1246     1250     +4     

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

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Agentic Review Report

Structural Check

Structural Review: rule HamiltonianCircuit -> TravelingSalesman

Structural Completeness

# Check Status
1 Rule file exists PASS
2 #[reduction(...)] macro present PASS
3 ReductionResult impl present PASS
4 ReduceTo impl present PASS
5 #[cfg(test)] + #[path = "..."] test link PASS
6 Test file exists PASS
7 Closed-loop test present PASS
8 Registered in rules/mod.rs PASS
9 Canonical rule example registered PASS
10 Example-db lookup tests exist PASS
11 Paper reduction-rule entry PASS
12 Blacklisted auto-generated file committed PASS

Build Status

  • make test: PASS
  • make clippy: PASS

Semantic Review

  • reduce_to(): OK - builds K_n on the same vertex set and assigns weight 1 to source edges and 2 to non-edges, matching the reduction.
  • extract_solution(): OK - reconstructs a cycle ordering from the selected degree-2 edges and returns a source configuration of length n.
  • Overhead formulas: OK - num_vertices = num_vertices and num_edges = n(n - 1) / 2 match the complete-graph target size exactly.
  • Example/test coverage: OK - the closed-loop test, weight check, and non-Hamiltonian gap test cover the intended reduction behavior.

Issue Compliance

# Check Status
1 Source/target match issue OK
2 Reduction algorithm matches OK
3 Solution extraction matches OK
4 Correctness preserved OK
5 Overhead expressions match OK
6 Example matches OK

Summary

  • 12/12 structural checks passed
  • 6/6 issue compliance checks passed
  • make test and make clippy passed
  • No findings

Quality Check

Quality Review

Design Principles

  • DRY: OK
  • KISS: OK
  • HC/LC: OK

Test Quality

Issues

Critical (Must Fix)

  • None.

Important (Should Fix)

  • None.

Minor (Nice to Have)

  • Broaden the rule tests beyond 4-vertex graphs so the reduction is validated on at least one 5+ vertex case.

Summary

  • Minor: tests only cover 4-vertex instances; no 5+ vertex case.

Agentic Feature Tests

Summary

Feature Discoverable Setup Works Expected Outcome Met Doc Quality
HamiltonianCircuit -> TravelingSalesman yes yes yes yes good, with one discoverability nuance

Per-Feature Details

HamiltonianCircuit -> TravelingSalesman

  • Role: downstream CLI user validating a new reduction from the catalog and docs
  • Use Case: find the rule, create the canonical source example, solve it, and reduce it to TravelingSalesman
  • What they tried: pred list, pred list --rules, pred show HamiltonianCircuit, pred show TravelingSalesman, pred create --example HamiltonianCircuit, pred create --example HamiltonianCircuit --to TravelingSalesman --example-side source/target, pred solve - --solver brute-force, and pred reduce - --to TravelingSalesman
  • Discoverability: yes; the model and rule are visible in the catalog, and show exposes the outgoing reduction
  • Setup: no special setup was needed beyond running the CLI in the worktree; the commands executed successfully
  • Functionality: the model example created correctly; the canonical rule witness created correctly; brute-force solving succeeded; reducing the canonical source example produced a TravelingSalesman instance with the expected 1/2 edge weights and Valid(4) target evaluation
  • Expected vs Actual Outcome: matched; the canonical source example was the 4-cycle, and reduction produced the documented TSP witness. One nuance: plain pred create --example HamiltonianCircuit returns the standalone model example, not the rule witness, so --to TravelingSalesman is needed to reach the canonical reduction example
  • Blocked steps: none
  • Friction points: the distinction between model examples and rule examples is easy to miss if a user only sees pred create --example HamiltonianCircuit
  • Doc suggestions: add a concrete pred create --example HamiltonianCircuit --to TravelingSalesman --example-side source example near the new rule docs, and mention the corresponding target-side witness command so users can reproduce the canonical pair directly

Issues Found

None.

Suggestions

  • Add an explicit CLI example for the rule-specific canonical witness, not just the model-level example.
  • Mention that the reduction witness lives behind --to TravelingSalesman, so users do not confuse it with the standalone HamiltonianCircuit example.

Additional Local Verification

Important (Should Fix)

  • The rule is not correct on the full admitted HamiltonianCircuit input domain. reduce_to() always builds K_n on the same vertex set (src/rules/hamiltoniancircuit_travelingsalesman.rs), but TravelingSalesman has no feasible Hamiltonian cycle for n < 3. A confirmed out-of-tree reproduction with a 2-vertex source graph produced source_dims=[2, 2], target_vertices=2 target_edges=1, and BruteForce::find_best(target) == None. That breaks the documented invariant that the target optimum distinguishes YES from NO HC instances; for these valid source instances the target has no optimum at all. The new tests only exercise 4-vertex inputs, so this regression is currently uncovered (src/unit_tests/rules/hamiltoniancircuit_travelingsalesman.rs).

Generated by review-pipeline

@GiggleLiu GiggleLiu merged commit 29ae20f into main Mar 22, 2026
5 checks passed
@GiggleLiu GiggleLiu deleted the issue-258 branch April 12, 2026 00:53
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.

[Rule] HamiltonianCircuit to TravelingSalesman

1 participant