Skip to main content

k_regular_game

Function k_regular_game 

Source
pub fn k_regular_game(
    n: u32,
    k: u32,
    directed: bool,
    multiple: bool,
    seed: u64,
) -> IgraphResult<Graph>
Expand description

Generate a random k-regular graph on n vertices.

Every vertex has degree exactly k (in the directed case, both in-degree and out-degree are k).

  • n — vertex count.
  • k — degree.
  • directed — if true, returns a directed graph where every vertex has out-degree = in-degree = k.
  • multiple — if true, samples via the configuration model and permits self-loops and parallel edges; if false, samples via the fast-heuristic simple-graph sampler.
  • seed — initialises an internal SplitMix64 PRNG. The same (n, k, directed, multiple, seed) always yields the same graph.

§Errors

  • InvalidArgumentn * k overflows u32.
  • InvalidArgument — undirected and n * k is odd (handshake violation).
  • InvalidArgumentmultiple = false and k > n - 1 (no simple realisation exists).
  • Internalmultiple = false and the fast-heur sampler exceeded its restart budget. Switch to multiple = true or pick a smaller k.

§Examples

use rust_igraph::k_regular_game;

// 20-vertex 4-regular simple undirected graph.
let g = k_regular_game(20, 4, false, false, 0xC0FF_EE00).unwrap();
assert_eq!(g.vcount(), 20);
assert_eq!(g.ecount(), 40);  // n * k / 2
assert!(!g.is_directed());