pub fn realize_degree_sequence(
degrees: &[u32],
method: RealizeDegseqMethod,
) -> IgraphResult<Graph>Expand description
Realize an undirected simple graph from a degree sequence.
Uses the Havel-Hakimi algorithm: repeatedly pick a vertex and connect it to the vertices with the highest remaining degrees.
§Arguments
degrees— the target degree for each vertex.method— vertex selection order (seeRealizeDegseqMethod).
§Errors
Returns InvalidArgument if:
- The degree sum is odd (no realization exists).
- Any degree exceeds
n - 1(no simple realization exists). - The sequence is not graphical (Havel-Hakimi fails).
§Examples
use rust_igraph::{realize_degree_sequence, RealizeDegseqMethod};
// Realize a path graph: degrees [1, 2, 2, 1]
let g = realize_degree_sequence(&[1, 2, 2, 1], RealizeDegseqMethod::Largest).unwrap();
assert_eq!(g.vcount(), 4);
assert_eq!(g.ecount(), 3);