Skip to content

Fix #213: Add MinimumFeedbackArcSet model#614

Merged
GiggleLiu merged 10 commits intomainfrom
issue-213-minimum-feedback-arc-set
Mar 13, 2026
Merged

Fix #213: Add MinimumFeedbackArcSet model#614
GiggleLiu merged 10 commits intomainfrom
issue-213-minimum-feedback-arc-set

Conversation

@zazabap
Copy link
Copy Markdown
Collaborator

@zazabap zazabap commented Mar 12, 2026

Summary

Adds the MinimumFeedbackArcSet problem model, including a new DirectedGraph topology type as a prerequisite.

Fixes #213

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 98.39357% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.79%. Comparing base (3fc6e47) to head (dd3db8e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/models/graph/minimum_feedback_arc_set.rs 93.22% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #614      +/-   ##
==========================================
+ Coverage   96.77%   96.79%   +0.01%     
==========================================
  Files         232      234       +2     
  Lines       30494    30743     +249     
==========================================
+ Hits        29512    29757     +245     
- Misses        982      986       +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.

zazabap and others added 2 commits March 12, 2026 15:25
Add the MinimumFeedbackArcSet problem model for finding minimum-size
arc subsets whose removal makes a directed graph acyclic. This includes:

- New DirectedGraph topology type (wrapping petgraph DiGraph)
- MinimumFeedbackArcSet model with BruteForce solver support
- Full CLI support (create, solve, serialize) with --arcs flag
- Paper documentation with formal definition and example
- Comprehensive unit tests (12 tests covering creation, evaluation,
  solver, serialization, and edge cases)

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

zazabap commented Mar 12, 2026

Implementation Summary

Changes

  • src/topology/directed_graph.rs (new): DirectedGraph struct wrapping petgraph DiGraph, with new(), num_vertices(), num_arcs(), arcs(), has_arc(), successors(), predecessors(), out_degree(), in_degree(), is_acyclic_subgraph() methods. Registered as VariantParam with category "graph".
  • src/topology/mod.rs: Register and re-export DirectedGraph.
  • src/models/graph/minimum_feedback_arc_set.rs (new): MinimumFeedbackArcSet model — minimization problem with binary variables per arc, feasibility via Kahn's topological sort. declare_variants! with complexity 2^num_vertices.
  • src/models/graph/mod.rs, src/models/mod.rs, src/lib.rs: Register and re-export MinimumFeedbackArcSet in module hierarchy and prelude.
  • problemreductions-cli/src/dispatch.rs: Add load_problem and serialize_any_problem arms.
  • problemreductions-cli/src/problem_name.rs: Add "minimumfeedbackarcset" alias.
  • problemreductions-cli/src/commands/create.rs: Add creation handler with --arcs flag (format: 0>1,1>2,2>0), parse_directed_arcs() helper, and example_for entry.
  • problemreductions-cli/src/cli.rs: Add --arcs flag to CreateArgs, update all_data_flags_empty(), update help table.
  • docs/paper/reductions.typ: Add display-name entry and problem-def with formal definition, background, and example.
  • docs/paper/references.bib: Add Chen et al. 2008 (FPT) and Lucchesi & Younger 1978 (planar) citations.
  • Unit tests: 12 model tests + 10 topology tests covering creation, evaluation, solver, serialization, edge cases.

Deviations from Plan

  • MinimumFeedbackArcSet has no type parameter (not generic over graph type) since DirectedGraph is currently the only directed graph type. This simplifies the implementation while being easy to generalize later.

Open Questions

  • None

@zazabap
Copy link
Copy Markdown
Collaborator Author

zazabap commented Mar 12, 2026

Implementation Summary

Changes

  • src/topology/directed_graph.rs (new): DirectedGraph type wrapping petgraph's DiGraph, with num_vertices(), num_arcs(), arcs(), has_arc(), successors(), predecessors(), is_acyclic_subgraph(). Registered as VariantParam.
  • src/models/graph/minimum_feedback_arc_set.rs (new): MinimumFeedbackArcSet optimization problem (Minimize). Binary variables over arcs; feasibility check via Kahn's topological sort. Complexity: 2^num_vertices.
  • src/unit_tests/topology/directed_graph.rs (new): 11 tests covering construction, arc queries, predecessors/successors, acyclicity check, serialization, equality, panic on invalid arc.
  • src/unit_tests/models/graph/minimum_feedback_arc_set.rs (new): 12 tests including creation, evaluation (valid/invalid/DAG), direction, brute-force solver (simple cycle, issue example, disjoint cycles), serialization, size getters.
  • CLI registration: dispatch.rs (load + serialize), problem_name.rs (alias), create.rs (--arcs flag with u>v syntax), cli.rs (CreateArgs + help table).
  • Paper: problem-def with formal definition, background (Karp, FPT, planar), and worked example.
  • Module registration: graph/mod.rs, models/mod.rs, lib.rs prelude.

Deviations from Plan

  • MinimumFeedbackArcSet is not parameterized by a graph type G (uses concrete DirectedGraph directly) since there are no other directed graph subtypes yet. This simplifies the implementation and can be generalized later if needed.
  • The linter/automation auto-added bibliography entries (@karp1972, @chen2008, @lucchesi1978) and the paper problem-def stub.

Open Questions

  • None

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

zazabap commented Mar 12, 2026

Implementation Summary

Changes

  • src/topology/directed_graph.rs - New DirectedGraph type wrapping petgraph's DiGraph<(), ()> with directed-graph API (arcs, successors, predecessors, acyclicity check)
  • src/topology/mod.rs - Registered DirectedGraph in topology module
  • src/models/graph/minimum_feedback_arc_set.rs - MinimumFeedbackArcSet model (optimization/minimize, binary variables over arcs, feasibility = remaining graph is DAG)
  • src/models/graph/mod.rs, src/models/mod.rs, src/lib.rs - Registered model in module hierarchy and prelude
  • problemreductions-cli/src/dispatch.rs - CLI load/serialize dispatch for MinimumFeedbackArcSet
  • problemreductions-cli/src/problem_name.rs - Lowercase alias minimumfeedbackarcset
  • problemreductions-cli/src/commands/create.rs - pred create MinimumFeedbackArcSet --arcs "0>1,1>2,2>0" support
  • problemreductions-cli/src/cli.rs - Added --arcs flag and help table entry
  • docs/paper/reductions.typ - Problem-def entry with formal definition, background, and example
  • docs/paper/references.bib - Added chen2008 and lucchesi1978 references
  • src/unit_tests/topology/directed_graph.rs - 11 tests for DirectedGraph (creation, arcs, successors/predecessors, acyclicity, serialization, equality)
  • src/unit_tests/models/graph/minimum_feedback_arc_set.rs - 12 tests including the issue example (6 vertices, 9 arcs, optimal FAS size 2)
  • src/unit_tests/trait_consistency.rs - Added MinimumFeedbackArcSet to trait/direction consistency checks

Deviations from Plan

  • DirectedGraph does NOT implement the Graph trait (which is undirected-specific). It has its own API with arcs(), has_arc(), successors(), predecessors() instead of edges(), has_edge(), neighbors().
  • Used variant_params![] (empty) since the problem has no type parameters -- DirectedGraph is the only supported graph type for now.
  • Complexity registered as 2^num_vertices per the issue's recommendation (Held-Karp style DP).

Open Questions

  • None

Copy link
Copy Markdown

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 support for a directed-graph topology and introduces the Minimum Feedback Arc Set (MFAS) optimization model, integrating it into the library exports, CLI (create/dispatch), unit tests, and paper docs.

Changes:

  • Introduce DirectedGraph topology type (petgraph-backed) and corresponding unit tests.
  • Add MinimumFeedbackArcSet model + tests, and re-export it through the crate modules/prelude.
  • Extend CLI to recognize/serialize/deserialize/create MFAS instances via a new --arcs flag; update docs/paper to include MFAS.

Reviewed changes

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

Show a summary per file
File Description
src/topology/mod.rs Registers and re-exports the new DirectedGraph type.
src/topology/directed_graph.rs Implements a directed graph wrapper and DAG-check helper used by MFAS.
src/models/graph/mod.rs Adds the MFAS module and re-export.
src/models/graph/minimum_feedback_arc_set.rs Implements the MFAS optimization problem and registers it in the schema/variants system.
src/models/mod.rs Re-exports MFAS at the models module boundary.
src/lib.rs Re-exports MFAS through the crate prelude.
src/unit_tests/topology/directed_graph.rs Adds unit tests for DirectedGraph.
src/unit_tests/models/graph/minimum_feedback_arc_set.rs Adds unit tests for MFAS behavior/solver correctness/serialization.
src/unit_tests/trait_consistency.rs Ensures MFAS participates in trait consistency + direction tests.
problemreductions-cli/src/problem_name.rs Adds an alias mapping for minimumfeedbackarcset.
problemreductions-cli/src/dispatch.rs Adds load/serialize dispatch arms for MFAS.
problemreductions-cli/src/commands/create.rs Adds --arcs parsing and MFAS creation path.
problemreductions-cli/src/cli.rs Documents MFAS flags and adds arcs to CLI args.
examples/detect_isolated_problems.rs Formatting-only change.
docs/paper/references.bib Adds MFAS-related references.
docs/paper/reductions.typ Adds MFAS definition to the paper.

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

let num_arcs = graph.num_arcs();
if config.len() != num_arcs {
return false;
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

evaluate() / is_valid_fas() currently treat any non-zero value in config as “removed” (since kept_arcs uses x == 0), but the objective counts only entries equal to 1. This means configs containing values like 2 could be considered valid while under-counting the removed arcs. Suggest either (a) rejecting configs with values > 1 as invalid, or (b) consistently interpreting “removed” as x != 0 and counting accordingly.

Suggested change
}
}
// Ensure configuration values are binary (0 = kept, 1 = removed)
if config.iter().any(|&x| x > 1) {
return false;
}

Copilot uses AI. Check for mistakes.
}

crate::declare_variants! {
MinimumFeedbackArcSet => "2^num_vertices",
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The declared variant complexity is "2^num_vertices", but this model’s configuration space is binary per arc (dims() is 2 repeated num_arcs() times). The complexity metadata should likely be expressed in terms of num_arcs to match the actual variable count.

Suggested change
MinimumFeedbackArcSet => "2^num_vertices",
MinimumFeedbackArcSet => "2^num_arcs",

Copilot uses AI. Check for mistakes.
Comment on lines +117 to +132
/// Check if the subgraph induced by keeping only the given arcs is acyclic (a DAG).
///
/// `kept_arcs` is a boolean slice of length `num_arcs()`, where `true` means the arc is kept.
pub fn is_acyclic_subgraph(&self, kept_arcs: &[bool]) -> bool {
let n = self.num_vertices();
let arcs = self.arcs();

// Build adjacency list for the subgraph
let mut adj = vec![vec![]; n];
let mut in_degree = vec![0usize; n];
for (i, &(u, v)) in arcs.iter().enumerate() {
if kept_arcs[i] {
adj[u].push(v);
in_degree[v] += 1;
}
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

is_acyclic_subgraph() indexes kept_arcs[i] for every arc, but does not validate kept_arcs.len() == num_arcs(). Since this is a public API, a mismatched slice length will panic with an out-of-bounds access. Consider adding an explicit length check (return false or panic with a clearer message) before iterating.

Copilot uses AI. Check for mistakes.
Comment on lines 86 to 92
"QUBO" => "--matrix \"1,0.5;0.5,2\"",
"SpinGlass" => "--graph 0-1,1-2 --couplings 1,1",
"KColoring" => "--graph 0-1,1-2,2-0 --k 3",
"Factoring" => "--target 15 --m 4 --n 4",
"MinimumFeedbackArcSet" => "--arcs \"0>1,1>2,2>0\"",
_ => "",
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The pred create schema-driven help will list parameters based on ProblemSchemaEntry field names. For MinimumFeedbackArcSet, that means users will see --graph (since the JSON field is graph), but the actual CLI input flag implemented here is --arcs. Consider special-casing DirectedGraph / MinimumFeedbackArcSet in print_problem_help() (or type_format_hint()) so the parameters section advertises --arcs instead of --graph.

Copilot uses AI. Check for mistakes.
GiggleLiu and others added 3 commits March 13, 2026 22:03
- Fix evaluate/is_valid_fas consistency: use x != 0 for counting removed arcs
- Fix complexity from 2^num_vertices to 2^num_arcs (matches config space)
- Add length validation assert to is_acyclic_subgraph
- Add DirectedGraph to type_format_hint and show --arcs in schema help

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add 'FAS' as a short alias for MinimumFeedbackArcSet (matching FVS pattern)
- Support --num-vertices flag for creating graphs with isolated vertices
- Update CLI help text

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

Review Pipeline Report

Check Result
Merge with main Resolved 8 conflicting files (additive: MinimumFeedbackVertexSet added on main)
Copilot comments 4 fixed (evaluate consistency, complexity num_arcs, is_acyclic_subgraph validation, CLI help)
Issue/human comments 0 actionable (all bot-generated)
Agentic test passed — all 12 unit tests + CLI create/solve/evaluate/inspect work
Agentic test fixes Added FAS alias, --num-vertices support for CLI
CI green (all 5 checks pass)
Board review-agentic → In Review

🤖 Generated by review-pipeline

GiggleLiu and others added 3 commits March 13, 2026 23:28
…012)

The best known exact algorithm for Minimum Feedback Arc Set uses DP over
vertex subsets in O*(2^n) time, not brute force over arcs. Add citation
to Bodlaender, Fomin, Koster, Kratsch, Thilikos (2012) in both the paper
and references.bib.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add generic W parameter matching FVS pattern (WeightElement + VariantParam)
- Evaluate sums arc weights instead of counting (supports weighted FAS)
- Add weights(), set_weights(), is_weighted() accessors
- Deduplicate arc parsing: extract parse_directed_graph() shared by FAS/FVS
- Add parse_arc_weights() for FAS --weights CLI support
- Add weighted test case (high-weight arc avoided by solver)
- Register MinimumFeedbackArcSet<i32> variant in declare_variants!
- Update dispatch.rs to use MinimumFeedbackArcSet<i32>

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolve merge conflicts by combining MinimumFeedbackArcSet additions
with new models from main (RuralPostman, SubgraphIsomorphism,
PartitionIntoTriangles, etc.) in shared files: mod.rs, lib.rs,
create.rs, dispatch.rs, and reductions.typ.
@GiggleLiu GiggleLiu merged commit 40b2623 into main Mar 13, 2026
5 checks passed
@GiggleLiu GiggleLiu deleted the issue-213-minimum-feedback-arc-set 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.

[Model] MinimumFeedbackArcSet

3 participants