pub fn barabasi_game_bag(
n: u32,
m: u32,
outpref: bool,
directed: bool,
seed: u64,
) -> IgraphResult<Graph>Expand description
Generate a graph with n vertices via Barabási–Albert preferential
attachment, using the original “bag” mechanism (BAG variant).
Each new vertex attaches m outgoing edges to existing vertices,
chosen with probability proportional to their degree. Because draws
are with replacement, the result may contain multi-edges (and
self-loops when outpref = true).
n— vertex count.n = 0returns an empty graph.m— number of edges each newly-added vertex contributes.m = 0yields an edgeless graph onnvertices.outpref— whentrue, the new vertex’s outgoing edges also bias subsequent sampling (i.e., out-degree counts toward attractiveness). Forced totrueifdirected = false(preferential attachment on an undirected graph naturally uses total degree).directed— generate a directed graph (edges point from new vertex to older).seed— initialises an internalSplitMix64PRNG. Same(n, m, outpref, directed, seed)always yields the same graph.
§Errors
Returns IgraphError::Internal if (n - 1) · m or the bag size
overflows u64 (only possible on absurdly large inputs;
(n, m) = (u32::MAX, u32::MAX) is the only realistic failure mode).
§Examples
use rust_igraph::barabasi_game_bag;
// 100-vertex directed BA graph with m = 2 outgoing edges per new vertex.
// The first vertex (seed) has no outgoing edges, so the total edge
// count is exactly (n - 1) · m = 99 · 2 = 198.
let g = barabasi_game_bag(100, 2, false, true, 0xCAFEBEEF).unwrap();
assert_eq!(g.vcount(), 100);
assert_eq!(g.ecount(), 198);
assert!(g.is_directed());