Skip to main content

average_path_length

Function average_path_length 

Source
pub fn average_path_length<N, E, Ix>(graph: &Graph<N, E, Ix>) -> Option<f64>
where N: Node + Clone + Debug + Ord, E: EdgeWeight, Ix: IndexType,
Expand description

Average shortest-path length of the graph.

Computed as the arithmetic mean of all pairwise BFS distances. Returns None for empty or disconnected graphs.

ยงExample

use scirs2_graph::network_statistics::average_path_length;
use scirs2_graph::generators::complete_graph;
let g = complete_graph(4).unwrap();
// All paths in K_4 have length 1
assert!((average_path_length(&g).unwrap() - 1.0).abs() < 1e-9);