Skip to main content

turan

Function turan 

Source
pub fn turan(n: u32, r: u32) -> IgraphResult<FullMultipartite>
Expand description

Build the Turán graph T(n, r).

n is the vertex count; r is the partition count. Returns a FullMultipartite whose graph is the complete r'-partite graph with maximally balanced partition sizes (where r' = min(r, n)) and whose types records the partition index of every vertex.

See the module documentation for the precise semantics and degenerate-case handling.

§Errors

  • IgraphError::InvalidArgumentr == 0 while n > 0. The upstream C entry returns IGRAPH_EINVAL in this case and we preserve that contract.
  • Any IgraphError surfaced by the underlying full_multipartite call (overflow when the resulting graph would have more than u32::MAX vertices or more than usize::MAX edges).

§Examples

use rust_igraph::turan;

// T(6, 3) — three balanced partitions of size 2, the cocktail-party
// graph K_{2,2,2} a.k.a. the octahedron.
let r = turan(6, 3).unwrap();
assert_eq!(r.graph.vcount(), 6);
assert_eq!(r.graph.ecount(), 12);
assert_eq!(r.types, vec![0, 0, 1, 1, 2, 2]);

// r > n → capped at r = n, yielding K_4.
let r = turan(4, 6).unwrap();
assert_eq!(r.graph.vcount(), 4);
assert_eq!(r.graph.ecount(), 6);
assert_eq!(r.types, vec![0, 1, 2, 3]);

// n == 0 → empty graph regardless of r.
let r = turan(0, 10).unwrap();
assert_eq!(r.graph.vcount(), 0);
assert!(r.types.is_empty());