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— iftrue, returns a directed graph where every vertex has out-degree = in-degree =k.multiple— iftrue, samples via the configuration model and permits self-loops and parallel edges; iffalse, samples via the fast-heuristic simple-graph sampler.seed— initialises an internalSplitMix64PRNG. The same(n, k, directed, multiple, seed)always yields the same graph.
§Errors
InvalidArgument—n * koverflowsu32.InvalidArgument— undirected andn * kis odd (handshake violation).InvalidArgument—multiple = falseandk > n - 1(no simple realisation exists).Internal—multiple = falseand the fast-heur sampler exceeded its restart budget. Switch tomultiple = trueor pick a smallerk.
§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());