Skip to content

Fix #789: HC→StackerCrane connector cost prevents incorrect solution extraction#791

Merged
GiggleLiu merged 1 commit intomainfrom
fix/789-hc-stackercrane-connector-cost
Mar 28, 2026
Merged

Fix #789: HC→StackerCrane connector cost prevents incorrect solution extraction#791
GiggleLiu merged 1 commit intomainfrom
fix/789-hc-stackercrane-connector-cost

Conversation

@isPANN
Copy link
Copy Markdown
Collaborator

@isPANN isPANN commented Mar 27, 2026

Summary

Fixes #789: the reduction chain HamiltonianCircuit → StackerCrane → ILP returned Or(false) on the prism graph, which has a valid Hamiltonian circuit.

Root Cause

The HC→StackerCrane reduction splits each vertex $v_i$ into $v_i^{in}$ (= $2i$) and $v_i^{out}$ (= $2i+1$), adding:

  • A mandatory directed arc ($2i → 2i+1$) of length 1 per vertex
  • Two undirected connector edges per original edge ${u,v}$: ${2u+1, 2v}$ and ${2v+1, 2u}$, originally with length 0

The zero-cost connectors form a rich network where multi-hop paths are also zero-cost. On the prism graph, vertices 5 and 6 have no direct connector (original edge ${2,3}$ doesn't exist), but a 5-hop zero-cost path exists:

5 →(0) 0 →(0) 7 →(0) 10 →(0) 9 →(0) 6

This means the ILP can find an optimal SC permutation [1, 2, 3, 0, 5, 4] with cost $n = 6$ that does not correspond to a valid Hamiltonian circuit. When extracted back to HC, edges $2→3$ and $0→5$ don't exist → Or(false).

Fix

Change connector edge lengths from 0 to 1. This ensures:

  • Adjacent vertices (direct connector edge): connector cost = 1
  • Non-adjacent vertices (no direct connector): connector cost ≥ 2, because from an out-node $2i+1$ to a non-adjacent in-node $2j$, one step reaches an in-node $2v$ (neighbor of $i$), and reaching another in-node $2j$ from there requires at least two more steps through the bipartite out/in structure.

Correctness proof for all graphs:

Condition Optimal SC cost Reasoning
HC exists $2n$ $n$ arcs × 1 + $n$ single-hop connectors × 1
HC does not exist $≥ 2n + 1$ Every permutation has at least one non-adjacent pair (cost ≥ 2), so total connector cost ≥ $n + 1$

Since every optimal permutation at cost $2n$ must use only single-hop connectors (each costing exactly 1), every optimal SC permutation maps back to a valid HC. The extract_solution identity mapping is therefore correct.

Changes

  • src/rules/hamiltoniancircuit_stackercrane.rs — connector edge lengths 0 → 1, updated doc comments
  • src/unit_tests/rules/hamiltoniancircuit_stackercrane.rs — updated expected costs ($n → 2n$), added prism graph regression test

Test plan

  • All existing HC→SC unit tests updated and passing
  • New prism graph regression test (test_hamiltoniancircuit_to_stackercrane_prism_graph)
  • CLI reproduction: pred reduce --to StackerCrane | pred solve now returns Or(true) on prism graph
  • Full test suite with example-db and ilp features passing (3657 tests)
  • clippy + fmt clean

🤖 Generated with Claude Code

… graph

Zero-cost connector edges allowed multi-hop shortest paths between
non-adjacent arcs, creating optimal SC permutations that don't map back
to valid Hamiltonian circuits. Change connector edge lengths from 0 to 1
so only single-hop connectors are optimal (cost 2n instead of n).

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

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.85%. Comparing base (f29cfb1) to head (1ed4583).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #791      +/-   ##
==========================================
- Coverage   97.85%   97.85%   -0.01%     
==========================================
  Files         625      625              
  Lines       68311    68329      +18     
==========================================
+ Hits        66846    66863      +17     
- Misses       1465     1466       +1     

☔ 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 GiggleLiu merged commit e1b41bd into main Mar 28, 2026
5 checks passed
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.

[Bug] HC → StackerCrane reduction produces incorrect result

2 participants