Skip to main content

odd_cycle_density

Function odd_cycle_density 

Source
pub fn odd_cycle_density(graph: &Graph) -> IgraphResult<f64>
Expand description

Compute the odd cycle density.

Fraction of closed triplets (triangles) relative to possible triplets. This equals the global clustering coefficient, but interpreted here as a measure of odd-cycle (length-3) density — a non-zero value proves the graph is not bipartite. Returns 0.0 for triangle-free or trivial graphs.

§Examples

use rust_igraph::{Graph, odd_cycle_density};

// K_4: C=1.0 (all triplets closed)
let g = Graph::from_edges(
    &[(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)], false, Some(4)
).unwrap();
assert!((odd_cycle_density(&g).unwrap() - 1.0).abs() < 1e-10);