Skip to main content

strength_with_mode

Function strength_with_mode 

Source
pub fn strength_with_mode(
    graph: &Graph,
    weights: &[f64],
    mode: StrengthMode,
    loops: bool,
) -> IgraphResult<Vec<f64>>
Expand description

Weighted vertex degree with direction mode and loop control.

Returns a vector of length graph.vcount() where entry v is the sum of the weights of edges incident to vertex v filtered by mode.

  • On undirected graphs, mode is ignored (all edges are both out and in).
  • loops:
    • true — self-loops contribute their weight to the strength. On undirected graphs with mode = All, a self-loop contributes twice (once on the “out” side, once on the “in” side), matching the IGRAPH_LOOPS_TWICE semantics of igraph_degree().
    • false — self-loops are skipped entirely.

§Arguments

  • graph — the input graph.
  • weights — edge weight vector of length graph.ecount().
  • mode — which edge direction(s) to follow.
  • loops — whether to include self-loops.

§Errors

§Examples

use rust_igraph::{Graph, StrengthMode, strength_with_mode};

// Directed: 0→1 (w=3), 0→2 (w=5), 1→0 (w=7)
let mut g = Graph::new(3, true).unwrap();
for (u, v) in [(0, 1), (0, 2), (1, 0)] {
    g.add_edge(u, v).unwrap();
}
let out_s = strength_with_mode(&g, &[3.0, 5.0, 7.0], StrengthMode::Out, true).unwrap();
assert!((out_s[0] - 8.0).abs() < 1e-12); // 3+5
assert!((out_s[1] - 7.0).abs() < 1e-12); // 7
assert!((out_s[2] - 0.0).abs() < 1e-12);

let in_s = strength_with_mode(&g, &[3.0, 5.0, 7.0], StrengthMode::In, true).unwrap();
assert!((in_s[0] - 7.0).abs() < 1e-12); // receives edge 1→0 (w=7)
assert!((in_s[1] - 3.0).abs() < 1e-12); // receives edge 0→1 (w=3)
assert!((in_s[2] - 5.0).abs() < 1e-12); // receives edge 0→2 (w=5)