Skip to main content

degree_sequence_game_configuration

Function degree_sequence_game_configuration 

Source
pub fn degree_sequence_game_configuration(
    out_degrees: &[u32],
    in_degrees: Option<&[u32]>,
    seed: u64,
) -> IgraphResult<Graph>
Expand description

Sample a random graph realising the given degree sequence(s) via the configuration / stub-matching model.

  • out_degrees — degree of every vertex (undirected) or out-degree of every vertex (directed). Length defines vertex count n.
  • in_degrees — when Some(seq), switches to directed mode and seq[i] is the in-degree of vertex i. Must have the same length as out_degrees and the same total.
  • seed — drives the internal SplitMix64 PRNG.

The output is a multigraph: self-loops and parallel edges can occur whenever the degree sequence allows them, with the natural configuration-model probabilities.

§Errors

  • in_degrees length disagrees with out_degrees length.
  • Degree sum overflows u64 (only possible at billion-vertex scale).
  • Undirected mode with an odd Σ out_degrees (not graphical).
  • Directed mode with Σ out_degrees != Σ in_degrees.
  • Edge count overflows u32 (igraph’s hard ECOUNT_MAX).
  • Vertex count exceeds u32::MAX.

§Examples

use rust_igraph::degree_sequence_game_configuration;

// Undirected 4-cycle target: every vertex degree 2 ⇒ 4 edges total.
let g = degree_sequence_game_configuration(&[2, 2, 2, 2], None, 7).unwrap();
assert_eq!(g.vcount(), 4);
assert_eq!(g.ecount(), 4);
assert!(!g.is_directed());