Skip to content

Fix #184: Add MinimumMultiwayCut model#221

Open
hmyuuu wants to merge 9 commits intoCodingThrust:mainfrom
hmyuuu:issue-184-minimum-multiway-cut
Open

Fix #184: Add MinimumMultiwayCut model#221
hmyuuu wants to merge 9 commits intoCodingThrust:mainfrom
hmyuuu:issue-184-minimum-multiway-cut

Conversation

@hmyuuu
Copy link
Contributor

@hmyuuu hmyuuu commented Mar 10, 2026

Summary

  • Add MinimumMultiwayCut problem model — minimum-weight edge set whose removal disconnects all terminal pairs
  • Edge-based binary optimization with BFS feasibility check
  • Cao, Chen & Wang (2013) complexity: O(1.84^k * n^3)
  • CLI support: dispatch, create with --terminals/--edge-weights/--graph, solve, evaluate
  • Paper problem-def entry with formal definition, background, and CeTZ example figure
  • 8 unit tests, example program, schema/graph exports updated

Co-authored with Claude (opus-4.6)

Test plan

  • All unit tests pass (cargo test minimum_multiway_cut)
  • Example runs correctly (cargo run --example minimummultiwaycut)
  • make check passes (fmt + clippy + test)
  • Paper builds (make paper)
  • CLI workflow verified: pred createpred inspectpred solve --solver brute-forcepred evaluate

Fixes #184

hmyuuu and others added 3 commits March 10, 2026 18:10
Co-authored-by: Claude <noreply@anthropic.com>
Implement the Minimum Multiway Cut problem — find minimum-weight edge set
whose removal disconnects all terminal pairs. Edge-based binary variables
with BFS feasibility check. Solved via BruteForce.

- Model struct with Problem/OptimizationProblem traits
- CLI dispatch and alias (mmc)
- 10 unit tests + example program
- Regenerated schemas and reduction graph

Co-authored-by: Claude <noreply@anthropic.com>
…hrust#184)

- Add `pred create MinimumMultiwayCut` with --terminals, --edge-weights, --graph
- Add problem-def entry in Typst paper with example figure
- Improve `pred solve` error: suggest --solver brute-force when no ILP path
- Remove spurious MMC alias (not a well-known abbreviation)
- Regenerate reduction graph and schema exports
- Delete implementation plan

Co-authored-by: Claude <noreply@anthropic.com>
@hmyuuu hmyuuu force-pushed the issue-184-minimum-multiway-cut branch from 13ffca2 to 4e30437 Compare March 10, 2026 10:22
@hmyuuu
Copy link
Contributor Author

hmyuuu commented Mar 10, 2026

Agentic Test Results

Ran /test-feature with two simulated user personas to validate the MinimumMultiwayCut implementation end-to-end.

Personas

  1. Rust developer — moderate experience, first time using the crate, wants to model a network isolation problem
  2. Researcher — comfortable with CLI, not a Rust developer, wants to explore/create/solve from terminal

Verdict: pass

Feature Discoverable Setup Works Expected Outcome Met Doc Quality
Library API yes yes yes yes good
CLI tool yes (via pred list) yes yes yes good

Issues Found & Fixed During Testing

  1. [Fixed] pred create had no MinimumMultiwayCut support → Added --terminals flag, dispatch handler, problem-specific help
  2. [Fixed] pred solve error message → Now suggests --solver brute-force when no ILP reduction path exists
  3. [Fixed] pred create --help missing MMC entry → Added to "Flags by problem type" section
  4. [Fixed] Spurious MMC alias → Removed (not a well-known abbreviation)
  5. [Fixed] Edge weight ordering undocumented on new() → Added doc comment explaining weight-to-edge correspondence and config encoding
  6. [Fixed] CLI docs stale → Updated pred list output (17 → 25 types), added MMC create example, added CVP/MaxMatching aliases to table

All issues resolved — no remaining items.

- Document edge weight ordering and config encoding on `new()` docstring
- Add MinimumMultiwayCut create example to CLI docs
- Update `pred list` output in CLI docs (17 → 25 problem types)
- Add CVP and MaxMatching aliases to CLI docs alias table

Co-authored-by: Claude <noreply@anthropic.com>
hmyuuu

This comment was marked as resolved.

Use config.get(idx) and edge_weights.get(idx) instead of direct
indexing to avoid panics on malformed input, matching the codebase
convention used by MaximumIndependentSet, TravelingSalesman, etc.

Made-with: Cursor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be needed

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

Adds a new graph optimization model, MinimumMultiwayCut, to the core library and wires it through the CLI + documentation pipeline so it can be created/serialized/used from pred and showcased via examples/tests.

Changes:

  • Introduce MinimumMultiwayCut model (schema registration, variant declaration, feasibility + objective evaluation).
  • Integrate the new model into CLI aliasing/dispatch and pred create, plus add a runnable example and test coverage.
  • Regenerate/update docs artifacts (schemas + reduction graph) and extend the paper/CLI documentation to include the new problem.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/suites/examples.rs Adds the new minimummultiwaycut example to the example test suite.
src/unit_tests/models/graph/minimum_multiway_cut.rs New unit tests for creation, evaluation, brute force solving, serialization, and edge cases.
src/models/mod.rs Re-exports MinimumMultiwayCut from the models module.
src/models/graph/mod.rs Registers and re-exports the new graph model in the graph module.
src/models/graph/minimum_multiway_cut.rs New implementation of the Minimum Multiway Cut optimization problem + schema/variants.
src/lib.rs Exposes MinimumMultiwayCut through the crate prelude.
problemreductions-cli/src/problem_name.rs Adds CLI alias resolution for minimummultiwaycut.
problemreductions-cli/src/dispatch.rs Enables load/serialize dispatch for MinimumMultiwayCut and improves the “no ILP path” hint.
problemreductions-cli/src/commands/create.rs Adds pred create MinimumMultiwayCut support and parses --terminals.
problemreductions-cli/src/cli.rs Documents MinimumMultiwayCut flags and adds --terminals argument.
examples/minimummultiwaycut.rs New runnable example demonstrating brute-force solving + JSON export.
docs/src/reductions/reduction_graph.json Adds the new problem variant node to the generated reduction graph.
docs/src/reductions/problem_schemas.json Adds the new problem schema entry to the generated schemas.
docs/src/cli.md Updates CLI docs (pred list output sample, examples, alias table).
docs/paper/references.bib Adds citations for Minimum Multiway Cut complexity/algorithms.
docs/paper/reductions.typ Adds a formal definition + example figure/text for Minimum Multiway Cut.

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

Comment on lines +121 to +148
// Build adjacency list from non-cut edges
let mut adj: Vec<Vec<usize>> = vec![vec![]; n];
for (idx, (u, v)) in edges.iter().enumerate() {
if config.get(idx).copied().unwrap_or(0) == 0 {
adj[*u].push(*v);
adj[*v].push(*u);
}
}

// BFS from each terminal; if a terminal is already visited by a previous
// terminal's BFS, they share a component => infeasible.
let mut component = vec![usize::MAX; n];
for (comp_id, &t) in terminals.iter().enumerate() {
if component[t] != usize::MAX {
return false;
}
let mut queue = VecDeque::new();
queue.push_back(t);
component[t] = comp_id;
while let Some(u) = queue.pop_front() {
for &v in &adj[u] {
if component[v] == usize::MAX {
component[v] = comp_id;
queue.push_back(v);
}
}
}
}
Comment on lines +654 to +669
/// Parse `--terminals` as a comma-separated list of vertex indices.
fn parse_terminals(args: &CreateArgs) -> Result<Vec<usize>> {
let terminals_str = args
.terminals
.as_deref()
.ok_or_else(|| anyhow::anyhow!("MinimumMultiwayCut requires --terminals (e.g., 0,2,4)"))?;

terminals_str
.split(',')
.map(|s| {
s.trim()
.parse::<usize>()
.map_err(|e| anyhow::anyhow!("Invalid terminal index '{}': {}", s.trim(), e))
})
.collect()
}
zazabap and others added 3 commits March 15, 2026 10:32
Resolve additive merge conflicts: both sides added new problem models.
Include MinimumMultiwayCut (PR) alongside all new models from main
(HamiltonianPath, GraphPartitioning, OptimalLinearArrangement, etc.).
For dispatch.rs and problem_name.rs, adopt main's registry-based
dynamic dispatch. For JSON artifacts, use main's version with
MinimumMultiwayCut entries added.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add missing fields (display_name, aliases, dimensions) required by
updated ProblemSchemaEntry struct, and add opt/default to declare_variants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Per reviewer comment: example binaries should be utility/export tools
or pedagogical demos, not per-model files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 96.96970% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.85%. Comparing base (5bd4da9) to head (5c9bcd7).

Files with missing lines Patch % Lines
src/models/graph/minimum_multiway_cut.rs 93.68% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #221      +/-   ##
==========================================
- Coverage   96.86%   96.85%   -0.01%     
==========================================
  Files         264      266       +2     
  Lines       35196    35394     +198     
==========================================
+ Hits        34091    34282     +191     
- Misses       1105     1112       +7     

☔ 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 MinimumMultiwayCut to trait_consistency tests
- Add canonical model example in example_db
- Strengthen brute-force test to verify specific optimal config
- Strengthen short_config test assertions
- Regenerate problem_schemas.json

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zazabap
Copy link
Collaborator

zazabap commented Mar 15, 2026

Review Pipeline Report

Check Result
Copilot comments approved, no actionable inline comments
Issue/human comments 3 checked, 1 already fixed (bounds checking), 1 addressed (example file removed)
Structural review 18/18 passed (after fixes)
CI green
Agentic test passed (2 personas: Rust dev + researcher)
Needs human decision none
Board Ready → Under review → Final review

Fixes applied

  • Merged origin/main and resolved 12 merge conflicts
  • Updated ProblemSchemaEntry to include new required fields (display_name, aliases, dimensions)
  • Added opt/default to declare_variants! macro call
  • Removed per-model example file (examples/minimummultiwaycut.rs) per reviewer comment
  • Added MinimumMultiwayCut to trait_consistency tests (both check_problem_trait and direction)
  • Added canonical model example in example_db (canonical_model_example_specs)
  • Strengthened brute-force test to verify specific optimal config [1,0,0,1,1,0] is among solutions
  • Strengthened short_config test to assert SolutionSize::Invalid instead of != Valid(0)
  • Regenerated problem_schemas.json

Remaining issues for final review

  • None.

🤖 Generated by review-pipeline

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.

[Model] MinimumMultiwayCut

3 participants