Expand description
Barabási–Albert preferential-attachment random graph (ALGO-GN-002, BAG variant).
Counterpart of the IGRAPH_BARABASI_BAG branch of
igraph_barabasi_game() in
references/igraph/src/games/barabasi.c:67-178.
The “bag” mechanism (Newman 2003, originally implemented by Albert
and Barabási themselves) maintains a multiset whose multiplicity of
vertex v equals deg(v) + 1. Drawing a vertex uniformly from the
bag therefore yields a vertex proportional to its degree — the
preferential-attachment kernel of the classical BA model with
power = 1 and constant attractiveness A = 1.
Algorithm:
- Initial bag =
[0](vertex0is the seed). - For each new vertex
i = 1 .. n:- Draw
mneighbours from the bag uniformly with replacement. - Emit
(i, to)for each neighbour. - Push
ionto the bag once (so the new vertex itself is sample-able next round). - Push each chosen neighbour back onto the bag (their degree just went up by one).
- If
outpref, also pushmcopies ofi(so the new vertex’s out-degree also drives future sampling).
- Draw
Because draws are with replacement, two of the m neighbours of a
given vertex can collide → the BAG variant can produce multi-edges
and (when i itself is in the bag at sampling time, only possible
with outpref=true) self-loops. Use the PSUMTREE variant
(crate::erdos_renyi_gnp is not a substitute) once that AWU
lands if a simple graph is required.
Total cost: O(n · m) work, O(n · m) memory for the bag and edge
list.
§Scope
MVP scope only covers the most-used dispatch path:
power = 1,A = 1(hardcoded — the BAG model only supports these per upstreambarabasi.c:567-574).mis constant across all new vertices (nooutseq).- No
start_fromgraph — we always seed with the singleton[0]. outprefdefaults tofalsefor directed graphs, and is forced totruefor undirected graphs (matching upstreambarabasi.c:83-85).
Functions§
- barabasi_
game_ bag - Generate a graph with
nvertices via Barabási–Albert preferential attachment, using the original “bag” mechanism (BAG variant).