Skip to main content

closeness_weighted

Function closeness_weighted 

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

Per-vertex weighted closeness centrality.

Returns Vec<Option<f64>>: Some(reach / sum_dist) if the vertex has at least one reachable neighbour with finite total distance, None for isolated vertices.

weights[e] is the weight of edge e; weights.len() must equal graph.ecount(). All weights must be >= 0 and finite.

§Examples

use rust_igraph::{Graph, closeness_weighted};

// Star with non-uniform weights.
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();   // weight 1.0
g.add_edge(0, 2).unwrap();   // weight 2.0
g.add_edge(0, 3).unwrap();   // weight 3.0
let c = closeness_weighted(&g, &[1.0, 2.0, 3.0]).unwrap();
// Centre: 3 reachable, sum = 1+2+3 = 6 → 0.5.
assert!((c[0].unwrap() - 0.5).abs() < 1e-12);