Skip to main content

cyclomatic_density

Function cyclomatic_density 

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

Compute the cyclomatic density.

(m - n + c) / n where c is the number of connected components. The circuit rank divided by the number of vertices gives the density of independent cycles per vertex. Returns 0.0 for graphs with no vertices.

§Examples

use rust_igraph::{Graph, cyclomatic_density};

// K_3: m=3, n=3, c=1, circuit_rank=1 → 1/3
let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, Some(3)).unwrap();
assert!((cyclomatic_density(&g).unwrap() - 1.0/3.0).abs() < 1e-10);