Skip to main content

mean_distance

Function mean_distance 

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

Mean unweighted shortest-path length over all reachable ordered pairs. Counterpart of igraph_average_path_length(_, NULL_weights, _, _, /*directed=*/true, /*unconn=*/true).

Returns None when no connected pairs exist (e.g. vcount() < 2, or all pairs are unreachable). Edge directions matter for directed graphs (uses distances which follows out-edges).

§Examples

use rust_igraph::{Graph, mean_distance};

// Path 0-1-2-3-4: ordered pairs at distance 1, 2, 3, 4 (4 each direction
// → 8, 6, 4, 2 contributions); 20 pairs total. Mean = 40/20 = 2.0.
let mut g = Graph::with_vertices(5);
for i in 0..4u32 { g.add_edge(i, i + 1).unwrap(); }
assert_eq!(mean_distance(&g).unwrap(), Some(2.0));