Skip to main content

hyper_wiener_index

Function hyper_wiener_index 

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

Compute the hyper-Wiener index of a graph.

WW(G) = ½ Σ_{u<v} d(u,v) + ½ Σ_{u<v} d(u,v)²

Only finite distances contribute. Returns 0.0 for graphs with fewer than 2 vertices or no edges.

§Examples

use rust_igraph::{Graph, hyper_wiener_index};

// Path 0-1-2: distances 1,2,1
// W = 1+2+1 = 4, but u<v only: d(0,1)=1, d(0,2)=2, d(1,2)=1
// WW = ½(1+2+1) + ½(1+4+1) = 2 + 3 = 5
let g = Graph::from_edges(&[(0,1),(1,2)], false, Some(3)).unwrap();
assert!((hyper_wiener_index(&g).unwrap() - 5.0).abs() < 1e-10);