pub fn triad_census(graph: &Graph) -> IgraphResult<TriadCensus>Expand description
Performs a triad census on a directed graph.
Classifies all n*(n-1)*(n-2)/6 vertex triples into the 16
Davis-Leinhardt triad types. Returns counts as f64 to avoid overflow
for large graphs.
For undirected graphs, edges are treated as mutual connections.
§Examples
use rust_igraph::{Graph, triad_census, TriadType};
// Complete directed graph on 3 vertices: all triads are type 300
let mut g = Graph::new(3, true).unwrap();
for i in 0..3u32 {
for j in 0..3u32 {
if i != j { g.add_edge(i, j).unwrap(); }
}
}
let tc = triad_census(&g).unwrap();
assert!((tc.get(TriadType::T300) - 1.0).abs() < 1e-10);
// Directed 3-cycle: 0->1->2->0 — all asymmetric, one 030C triad
let mut g = Graph::new(3, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
let tc = triad_census(&g).unwrap();
assert!((tc.get(TriadType::T030C) - 1.0).abs() < 1e-10);