Skip to main content

establishment_game

Function establishment_game 

Source
pub fn establishment_game(
    nodes: u32,
    types: u32,
    k: u32,
    type_dist: Option<&[f64]>,
    pref_matrix: &[Vec<f64>],
    directed: bool,
    seed: u64,
) -> IgraphResult<(Graph, Vec<u32>)>
Expand description

Generates a random graph with vertex types via the establishment model.

Vertices are added one-by-one. Once i ≥ k, a new vertex tries to connect to k previously added vertices uniformly at random; for each candidate, the edge is accepted with probability pref_matrix[type[i]][type[j]]. The result is a simple (no parallel edges, no self-loops by construction) graph whose density is shaped jointly by the type distribution and the preference matrix.

  • nodes — number of vertices.
  • types ≥ 1 — number of vertex types.
  • k — connections attempted per new vertex.
  • type_dist — categorical weights over types; None means uniform. Must be the same length as types, all entries non-negative, total mass strictly positive.
  • pref_matrixtypes × types matrix of acceptance probabilities in [0, 1]. When directed = false it must be symmetric.
  • directed — generate a directed graph.
  • seedSplitMix64 seed.

Returns the generated Graph and the per-vertex type vector.

§Errors

Returns IgraphError::InvalidArgument when the preference matrix or type distribution is malformed (wrong size, NaN, out-of-range probability, asymmetric for an undirected graph) or when the type distribution is non-positive everywhere.

§Example

use rust_igraph::establishment_game;

// Two types, only-cross prefs ⇒ bipartite directed graph.
let pref = vec![vec![0.0, 1.0], vec![1.0, 0.0]];
let (g, types) =
    establishment_game(20, 2, 5, Some(&[1.0, 1.0]), &pref, true, 42).unwrap();
assert_eq!(g.vcount(), 20);
assert_eq!(types.len(), 20);
assert!(types.iter().all(|&t| t < 2));