Fix #184: Add MinimumMultiwayCut model#221
Conversation
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>
13ffca2 to
4e30437
Compare
Agentic Test ResultsRan Personas
Verdict: pass
Issues Found & Fixed During Testing
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>
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
examples/minimummultiwaycut.rs
Outdated
There was a problem hiding this comment.
This may not be needed
There was a problem hiding this comment.
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
MinimumMultiwayCutmodel (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.
| // 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); | ||
| } | ||
| } | ||
| } | ||
| } |
| /// 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() | ||
| } |
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
- 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>
Review Pipeline Report
Fixes applied
Remaining issues for final review
🤖 Generated by review-pipeline |
Summary
--terminals/--edge-weights/--graph, solve, evaluateCo-authored with Claude (opus-4.6)
Test plan
cargo test minimum_multiway_cut)cargo run --example minimummultiwaycut)make checkpasses (fmt + clippy + test)make paper)pred create→pred inspect→pred solve --solver brute-force→pred evaluateFixes #184