Skip to content

Fix #186: Add MinimumMultiwayCut -> QUBO reduction#694

Merged
GiggleLiu merged 9 commits intomainfrom
issue-186
Mar 19, 2026
Merged

Fix #186: Add MinimumMultiwayCut -> QUBO reduction#694
GiggleLiu merged 9 commits intomainfrom
issue-186

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

Add reduction rule from MinimumMultiwayCut to QUBO using the Heidari, Dinneen & Delmas (2022) formulation with kn binary variables encoding vertex-to-terminal assignments via penalty Hamiltonian + cut-cost Hamiltonian.

Fixes #186

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #694      +/-   ##
==========================================
+ Coverage   97.32%   97.34%   +0.02%     
==========================================
  Files         327      329       +2     
  Lines       42170    42297     +127     
==========================================
+ Hits        41042    41175     +133     
+ Misses       1128     1122       -6     

☔ 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 and others added 4 commits March 18, 2026 02:52
Implement the reduction from MinimumMultiwayCut<SimpleGraph, i32> to QUBO<f64>
using the one-hot vertex-terminal assignment encoding (Heidari, Dinneen & Delmas
2022). The QUBO Hamiltonian uses penalty terms for one-hot constraints and terminal
pinning (H_A) plus cut cost encoding (H_B). Includes 4 unit tests covering
closed-loop correctness, a small instance, size verification, and terminal pinning.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add reduction rule from MinimumMultiwayCut to QUBO using the
Heidari, Dinneen & Delmas (2022) penalty Hamiltonian formulation
with kn binary variables encoding vertex-to-terminal assignments.

- Reduction rule with one-hot + terminal pinning penalties (H_A)
  and cut-cost objective (H_B)
- 4 unit tests including closed-loop verification
- Canonical example in example_db
- Paper entry with worked example in reductions.typ
- Regenerated exports (reduction_graph.json, problem_schemas.json, fixtures)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Implementation Summary

Changes

  • src/rules/minimummultiwaycut_qubo.rs — Reduction rule using Heidari et al. (2022) penalty Hamiltonian with kn binary variables
  • src/unit_tests/rules/minimummultiwaycut_qubo.rs — 4 unit tests (closed-loop, small, sizes, terminal pinning)
  • src/rules/mod.rs — Module registration and example-db integration
  • docs/paper/reductions.typ — Paper entry with rule statement, proof, and worked example
  • docs/paper/references.bib — Bibliography entry for Heidari et al. (2022)
  • Regenerated exports: reduction_graph.json, problem_schemas.json, examples.json

Deviations from Plan

  • None

Open Questions

  • None

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Agentic Review Report

Structural Check

# Check Status
1 Rule file exists (src/rules/minimummultiwaycut_qubo.rs) 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 (src/unit_tests/rules/minimummultiwaycut_qubo.rs) PASS
7 Closed-loop test present PASS
8 Registered in rules/mod.rs PASS
9 Canonical rule example in canonical_rule_example_specs() PASS
10 Example-db lookup tests exist PASS
11 Paper reduction-rule entry in reductions.typ PASS

Result: 11/11 structural checks passed.

Build: all tests pass, clippy clean.

Semantic Review:

  • extract_solution correctness — OK. Correctly inverts the one-hot encoding: finds the active terminal for each vertex, then marks edges as cut/uncut. Output vector length matches source dims().
  • Overhead accuracy — OK. num_vars = "num_terminals * num_vertices" matches the code (nq = n * k). Verified on concrete instance: n=5, k=3 → 15-variable QUBO.
  • Mathematical correctness — OK. Traced on small instances: H_A (one-hot + terminal pinning) correctly penalizes invalid partitions with alpha = sum(|w|) + 1; H_B (cut cost) correctly counts each cut edge exactly once. Upper-triangular matrix convention consistent with QUBO evaluation. Both optimal QUBO solutions decode to minimum cuts matching brute-force on the source.
  • Penalty coefficient — OK. Code uses alpha = sum(|w|) + 1.0 = 18.0 for the canonical instance (the issue said α=20, which appears to be an arithmetic error in the issue: 2+3+1+2+4+5 = 17, so sum+1 = 18). The code's formula is correct.
  • Paper quality — OK. Proof sketch includes Construction, Correctness (forward + backward), and Solution extraction. Worked example is data-driven from fixture JSON. Reference (Heidari et al. 2022) properly added to references.bib.

Issue Compliance (#186): 6/6 checks passed — source/target, algorithm, solution extraction, correctness, overhead, and example all match the linked issue.


Quality Check

Design Principles:

  • DRY: OK — The add_upper closure pattern is duplicated across QUBO reductions but is a 3-line inline closure; extracting it would add coupling without benefit.
  • KISS: OK — Straightforward reduction logic following established QUBO encoding patterns. reduce_to is 60 lines.
  • HC/LC: OK — Clean separation between solution mapping (ReductionResult) and matrix construction (reduce_to).

HCI: N/A (no CLI changes).

Test Quality Issues:

# Severity Issue Location
1 Important Closed-loop tests use hardcoded expected values instead of assert_optimization_round_trip_from_optimization_target helper src/unit_tests/rules/minimummultiwaycut_qubo.rs:7-49
2 Important 3 of 4 tests reuse the identical 5-vertex instance — limited instance diversity src/unit_tests/rules/minimummultiwaycut_qubo.rs
3 Minor test_minimummultiwaycut_to_qubo_sizes only checks shape (num_variables() == 15), adding minimal value over the closed-loop test src/unit_tests/rules/minimummultiwaycut_qubo.rs:51-59

Agentic Feature Tests

Test Status
pred list (catalog registration) PASS
pred show MinimumMultiwayCut PASS
pred show QUBO (reverse lookup) PASS
pred create --example MinimumMultiwayCut PASS
pred solve (direct, ILP) PASS
pred solve (direct, brute-force) PASS
pred reduce --to QUBO PASS
Solve reduced QUBO PASS
Cross-check (bundle solve) PASS
Edge case: 2 terminals PASS
Edge case: disconnected graph PASS
Edge case: K4 dense graph PASS
Overhead formula verification PASS
Multi-hop path (→ QUBO → ILP) PASS
Unit tests (20/20) PASS
Integration tests (63/63) PASS
Clippy PASS
Format check FAIL (2 minor items)

Cross-checks: All direct-solve vs solve-via-reduction results match across all tested instances (canonical 5-vertex, minimal 2-terminal, disconnected, K4).

Issues found:

# Severity Issue
1 Low src/rules/mod.rs line 27-28: minimummultiwaycut_qubo sorts after minimumvertexcover_maximumindependentset, breaking alphabetical order
2 Low src/rules/minimummultiwaycut_qubo.rs lines 146-147: line wrapping differs from rustfmt preference

Both are caught by cargo fmt --check and trivially fixable with cargo fmt.


Generated by review-pipeline

GiggleLiu and others added 4 commits March 19, 2026 15:36
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
# Conflicts:
#	docs/paper/references.bib
The direct_best_example function was removed on main. Update to use
the current rule_example_with_witness API with explicit solution pair.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@GiggleLiu GiggleLiu merged commit 3f81121 into main Mar 19, 2026
3 checks passed
@GiggleLiu GiggleLiu deleted the issue-186 branch April 12, 2026 00:51
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] MinimumMultiwayCut to QUBO

1 participant