Skip to main content

constraint

Function constraint 

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

Compute Burt’s constraint scores for all vertices.

The constraint of vertex i is defined as:

C[i] = Σ_j (p[i,j] + Σ_{q ≠ i,j} p[i,q] · p[q,j])²

where the proportional tie strength is:

p[i,j] = (a[i,j] + a[j,i]) / Σ_{k ≠ i} (a[i,k] + a[k,i])

For isolated vertices (no incident edges excluding self-loops), the constraint is NaN.

Optionally accepts edge weights. If weights is None, all edges are treated as having unit weight.

§Examples

use rust_igraph::{Graph, constraint};

// Star graph: center has constraint from 4 leaves
let mut g = Graph::with_vertices(5);
for i in 1..5 {
    g.add_edge(0, i).unwrap();
}
let c = constraint(&g, None).unwrap();
// Center vertex: each leaf contributes (1/4)² = 1/16, total = 4/16 = 0.25
assert!((c[0] - 0.25).abs() < 1e-9);
// Each leaf: only neighbor is center, constraint = 1.0
assert!((c[1] - 1.0).abs() < 1e-9);