Skip to main content

strength

Function strength 

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

Weighted vertex degree for all vertices.

Returns a vector of length graph.vcount() where entry v is the sum of the weights of edges incident to vertex v. For undirected graphs, mode is implicitly StrengthMode::All and self-loops contribute their weight twice (matching the IGRAPH_LOOPS_TWICE default of igraph_degree).

§Arguments

  • graph — the input graph.
  • weights — edge weight vector of length graph.ecount().

§Errors

§Examples

use rust_igraph::{Graph, strength};

// Triangle 0-1-2 with weights [1.0, 2.0, 3.0]
let mut g = Graph::with_vertices(3);
for (u, v) in [(0, 1), (0, 2), (1, 2)] {
    g.add_edge(u, v).unwrap();
}
let s = strength(&g, &[1.0, 2.0, 3.0]).unwrap();
// v0: w(0-1)+w(0-2) = 3.0, v1: w(0-1)+w(1-2) = 4.0, v2: w(0-2)+w(1-2) = 5.0
assert!((s[0] - 3.0).abs() < 1e-12);
assert!((s[1] - 4.0).abs() < 1e-12);
assert!((s[2] - 5.0).abs() < 1e-12);