Skip to main content

transitivity_undirected

Function transitivity_undirected 

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

Global transitivity (clustering coefficient) of graph3 * triangles / connected_triples. Returns None when there are no connected triples (matches upstream’s IGRAPH_TRANSITIVITY_NAN mode); use .unwrap_or(0.0) for the IGRAPH_TRANSITIVITY_ZERO behaviour.

Edge directions, parallel edges, and self-loops are ignored.

§Examples

use rust_igraph::{Graph, transitivity_undirected};

// K4: every triple is a triangle → transitivity 1.0.
let mut g = Graph::with_vertices(4);
for u in 0..4u32 {
    for v in (u + 1)..4 {
        g.add_edge(u, v).unwrap();
    }
}
let t = transitivity_undirected(&g).unwrap();
assert_eq!(t, Some(1.0));

// 4-cycle: 4 connected triples (one per vertex) but no triangles.
let mut g = Graph::with_vertices(4);
for i in 0..4u32 { g.add_edge(i, (i + 1) % 4).unwrap(); }
let t = transitivity_undirected(&g).unwrap();
assert_eq!(t, Some(0.0));