Skip to main content

is_dominating_set

Function is_dominating_set 

Source
pub fn is_dominating_set(graph: &Graph, dom_set: &[VertexId]) -> bool
Expand description

Check whether a set of vertices forms a valid dominating set.

A dominating set is valid if every vertex in the graph is either in the set or adjacent to at least one vertex in the set.

For directed graphs, a vertex v is considered dominated by a vertex u in the set if there is an edge in either direction between u and v.

ยงExamples

use rust_igraph::{Graph, is_dominating_set};

let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 4).unwrap();

assert!(is_dominating_set(&g, &[1, 3]));
assert!(!is_dominating_set(&g, &[0, 4]));