Skip to main content

greedy_independent_set

Function greedy_independent_set 

Source
pub fn greedy_independent_set(graph: &Graph) -> IgraphResult<Vec<u32>>
Expand description

Find a maximal independent set using a greedy heuristic.

Iteratively picks the vertex with the smallest degree among remaining candidates, adds it to the independent set, and removes it and all its neighbours from the candidate pool.

The result is maximal (no vertex can be added without breaking independence) but not necessarily maximum.

ยงExamples

use rust_igraph::{Graph, greedy_independent_set, is_independent_vertex_set};

let g = Graph::from_edges(
    &[(0,1),(1,2),(2,3),(3,4),(4,0)], false, Some(5)
).unwrap();
let ind = greedy_independent_set(&g).unwrap();
assert!(is_independent_vertex_set(&g, &ind).unwrap());
assert!(ind.len() >= 2);