Skip to main content

wiener_index

Function wiener_index 

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

Compute the Wiener index of a connected graph.

W(G) = Σ_{u<v} d(u,v) — the sum of all pairwise shortest-path distances. Returns an error for disconnected or directed graphs.

§Examples

use rust_igraph::{Graph, wiener_index};

// Path 0-1-2: W = d(0,1) + d(0,2) + d(1,2) = 1 + 2 + 1 = 4
let g = Graph::from_edges(&[(0,1),(1,2)], false, Some(3)).unwrap();
let w = wiener_index(&g).unwrap();
assert!((w - 4.0).abs() < 0.01);