Skip to main content

satisfies_ore

Function satisfies_ore 

Source
pub fn satisfies_ore(graph: &Graph) -> IgraphResult<bool>
Expand description

Check whether a graph satisfies Ore’s condition.

Ore’s condition: for every pair of non-adjacent vertices u, v, deg(u) + deg(v) ≥ n. 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_ore};

// `K_4`: every non-adjacent pair... but K_4 is complete (no
// non-adjacent pairs), so Ore is vacuously true
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_ore(&g).unwrap());

// Path `P_4`: endpoints 0,3 are non-adjacent, deg(0)+deg(3)=1+1=2 < 4
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();
assert!(!satisfies_ore(&g).unwrap());