pub fn feedback_vertex_set(
graph: &Graph,
weights: Option<&[f64]>,
_algo: FvsAlgorithm,
) -> IgraphResult<Vec<VertexId>>Expand description
Compute a feedback vertex set — a set of vertex IDs whose removal makes the graph acyclic.
Uses a greedy heuristic that repeatedly finds a cycle and removes the vertex with the highest degree. Not guaranteed to be minimum.
§Errors
- Returns an error if
weightslength does not matchvcount. - Returns an error if weights contain non-finite values.
§Examples
use rust_igraph::{Graph, feedback_vertex_set, FvsAlgorithm};
// Directed cycle 0 → 1 → 2 → 0: removing one vertex 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 fvs = feedback_vertex_set(&g, None, FvsAlgorithm::Greedy).unwrap();
assert_eq!(fvs.len(), 1);
// DAG: no feedback vertices needed.
let mut g = Graph::new(3, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let fvs = feedback_vertex_set(&g, None, FvsAlgorithm::Greedy).unwrap();
assert!(fvs.is_empty());