Skip to main content

bipartite_game_gnp

Function bipartite_game_gnp 

Source
pub fn bipartite_game_gnp(
    n1: u32,
    n2: u32,
    p: f64,
    directed: bool,
    mode: BipartiteMode,
    seed: u64,
) -> IgraphResult<BipartiteGraph>
Expand description

Generate a random bipartite graph from the G(n1, n2, p) model.

Every possible cross-partition edge is included independently with probability p. The expected number of edges is p · max_edges(n1, n2, directed, mode).

  • n1 — bottom partition size (vertices 0..n1).
  • n2 — top partition size (vertices n1..n1+n2).
  • p ∈ [0, 1] — edge probability.
  • directed — generate a directed bipartite graph; when false edges are undirected and mode is effectively All (pair space n1·n2, no mutual pairs because the graph is undirected).
  • mode — see BipartiteMode. Ignored when directed == false.
  • seed — initialises an internal SplitMix64 PRNG. The same (n1, n2, p, directed, mode, seed) always yields the same graph.

§Errors

Returns IgraphError::InvalidArgument if p is NaN, infinite, or outside [0, 1], or if n1 + n2 overflows u32.

§Examples

use rust_igraph::{bipartite_game_gnp, BipartiteMode};
// Expected edges ≈ 0.3 · 5 · 8 = 12.
let bg = bipartite_game_gnp(5, 8, 0.3, false, BipartiteMode::All, 42).unwrap();
assert_eq!(bg.graph.vcount(), 13);
assert_eq!(bg.types.len(), 13);
// Every edge crosses the partition.
for eid in 0..bg.graph.ecount() {
    let (u, v) = bg.graph.edge(eid as u32).unwrap();
    assert_ne!(bg.types[u as usize], bg.types[v as usize]);
}