pub fn feedback_arc_set(
graph: &Graph,
weights: Option<&[f64]>,
_algo: FasAlgorithm,
) -> IgraphResult<Vec<u32>>Expand description
Compute a feedback arc set — a set of edge IDs whose removal makes the graph acyclic.
For undirected graphs, the result is a minimum FAS (non-tree edges of a maximum-weight spanning forest). For directed graphs, the Eades-Lin-Smyth heuristic provides a good approximation.
§Errors
- Returns an error if
weightslength does not matchecount. - Returns an error if weights contain non-finite values.
§Examples
use rust_igraph::{Graph, feedback_arc_set, FasAlgorithm};
// Directed cycle 0 → 1 → 2 → 0: removing one edge breaks it.
let mut g = Graph::new(3, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
let fas = feedback_arc_set(&g, None, FasAlgorithm::EadesLinSmyth).unwrap();
assert!(!fas.is_empty());
assert!(fas.len() <= 2);
// DAG: no feedback edges needed.
let mut g = Graph::new(3, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let fas = feedback_arc_set(&g, None, FasAlgorithm::EadesLinSmyth).unwrap();
assert!(fas.is_empty());