Skip to main content

harmonic_centrality_weighted

Function harmonic_centrality_weighted 

Source
pub fn harmonic_centrality_weighted(
    graph: &Graph,
    weights: &[f64],
) -> IgraphResult<Vec<f64>>
Expand description

Per-vertex weighted harmonic centrality.

result[v] = (1/(n-1)) * sum_{u != v, reachable} 1/d_w(v, u), where d_w is the Dijkstra weighted distance. Unreachable vertices contribute 0 (defining 1/inf = 0), so harmonic centrality is well-defined on disconnected graphs (unlike closeness).

weights[e] is the weight of edge e; weights must be non-negative and finite (forwarded from crate::dijkstra_distances). Zero-weight edges that produce a distance of 0 between distinct vertices are silently skipped to avoid division by zero.

ยงExamples

use rust_igraph::{Graph, harmonic_centrality_weighted};

// Path 0-1-2 with weights (1, 1) recovers the unweighted answer.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let h = harmonic_centrality_weighted(&g, &[1.0, 1.0]).unwrap();
assert!((h[0] - 0.75).abs() < 1e-12);
assert!((h[1] - 1.00).abs() < 1e-12);
assert!((h[2] - 0.75).abs() < 1e-12);