pub fn maximum_independent_set(graph: &Graph) -> IgraphResult<Vec<VertexId>>Expand description
Compute an approximate maximum independent set using a greedy heuristic.
Repeatedly picks the vertex with the smallest degree among remaining candidates, adds it to the independent set, then removes it and all its neighbors from the candidate pool.
This is a simple greedy heuristic — it does not guarantee an optimal solution, but tends to produce good results in practice.
§Examples
use rust_igraph::{Graph, maximum_independent_set, is_independent_vertex_set};
// Path 0-1-2-3: maximum independent set is {0, 2} or {1, 3}
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
let mis = maximum_independent_set(&g).unwrap();
assert!(is_independent_vertex_set(&g, &mis).unwrap());
assert!(mis.len() >= 2);
// Empty graph: all vertices are independent
let g = Graph::with_vertices(5);
let mis = maximum_independent_set(&g).unwrap();
assert_eq!(mis.len(), 5);