pub fn satisfies_dirac(graph: &Graph) -> IgraphResult<bool>Expand description
Check whether a graph satisfies Dirac’s condition.
Dirac’s condition: every vertex has degree ≥ ⌈n/2⌉ (equivalently ≥ n/2 for integer arithmetic). A graph satisfying this on n ≥ 3 vertices is guaranteed to be Hamiltonian.
Returns false for directed graphs or n < 3.
§Examples
use rust_igraph::{Graph, satisfies_dirac};
// `K_4`: every vertex has degree 3 ≥ 4/2 = 2
let mut g = Graph::with_vertices(4);
for i in 0..4u32 {
for j in (i+1)..4 {
g.add_edge(i, j).unwrap();
}
}
assert!(satisfies_dirac(&g).unwrap());
// `C_5`: each vertex has degree 2 < 5/2 = 2.5 → fails
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();
g.add_edge(4, 0).unwrap();
assert!(!satisfies_dirac(&g).unwrap());