pub fn dyad_census(graph: &Graph) -> IgraphResult<DyadCensus>Expand description
Counts the mutual, asymmetric, and null dyads in a directed graph.
A dyad is an unordered pair of vertices. In a directed graph:
- Mutual: both
(u,v)and(v,u)edges exist. - Asymmetric: exactly one of
(u,v)or(v,u)exists. - Null: neither edge exists.
Self-loops and multi-edges are ignored (only simple edges counted). For undirected graphs, all edges are treated as mutual.
Uses f64 to avoid overflow for large graphs where n*(n-1)/2
may exceed u32::MAX.
§Examples
use rust_igraph::{Graph, dyad_census};
let mut g = Graph::new(4, true).unwrap();
// Mutual: 0↔1
g.add_edge(0, 1).unwrap();
g.add_edge(1, 0).unwrap();
// Asymmetric: 2→3
g.add_edge(2, 3).unwrap();
let dc = dyad_census(&g).unwrap();
assert!((dc.mutual - 1.0).abs() < 1e-10);
assert!((dc.asymmetric - 1.0).abs() < 1e-10);
assert!((dc.null - 4.0).abs() < 1e-10);