Skip to main content

component_ratio

Function component_ratio 

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

Compute the component ratio.

num_components / n — fraction of vertices that are component representatives. Equals 1.0 when every vertex is isolated, 1/n when the graph is connected. Returns 0.0 for empty graphs.

§Examples

use rust_igraph::{Graph, component_ratio};

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