pub fn chung_lu_game(
out_weights: &[f64],
in_weights: Option<&[f64]>,
loops: bool,
variant: ChungLuVariant,
seed: u64,
) -> IgraphResult<Graph>Expand description
Sample a random graph from the Chung–Lu expected-degree model.
out_weights— non-negative, finite per-vertex weights. Length is the resulting graph’s vertex countn. In the sparse-graph limit eachout_weights[i]is approximately the expected (out-)degree of vertexi.in_weights— whenSome, generates a directed graph; must have the same length asout_weightsand the same total mass (withinf64exact equality, per upstream igraph). WhenNone, generates an undirected graph within_weights = out_weights.loops— whentrue, self-loop edges are allowed (sampled independently withp_ii).variant— which connection-probability formula to use; seeChungLuVariant.seed— initialises an internalSplitMix64PRNG so output is reproducible given the inputs.
§Errors
Returns IgraphError::InvalidArgument if:
- any weight is negative, NaN, or non-finite (
±∞); in_weightshas a different length thanout_weights;in_weightsandout_weightshave a different sum (directed case);out_weights.len()exceeds2^53(the largest integer exactly representable asf64, matching upstream igraph’sIGRAPH_MAX_EXACT_REALguard).
§Complexity
O(|V| log |V| + |E|) — the log |V| factor comes from the
descending in-weight sort; the sampler itself is linear in the
realised edge count.
§Examples
use rust_igraph::{chung_lu_game, ChungLuVariant};
// Power-law-style weights: a handful of "hubs" plus many low-degree
// vertices. The expected degree of vertex i ≈ out_weights[i].
let weights: Vec<f64> = (0..50).map(|i| 1.0 + (i as f64) * 0.2).collect();
let g = chung_lu_game(&weights, None, false, ChungLuVariant::Maxent, 42).unwrap();
assert_eq!(g.vcount(), 50);
assert!(!g.is_directed());