Skip to main content

create_bipartite

Function create_bipartite 

Source
pub fn create_bipartite(
    types: &[bool],
    edges: &[(VertexId, VertexId)],
    directed: bool,
) -> IgraphResult<Graph>
Expand description

Create a bipartite graph from a type vector and edge list.

Validates that every edge connects vertices of different types (one endpoint in each partition). The type vector length defines the vertex count.

§Parameters

  • types — per-vertex partition: false = partition 0, true = partition 1.
  • edges — pairs (from, to) of vertex IDs.
  • directed — whether the resulting graph is directed.

§Errors

§Examples

use rust_igraph::create_bipartite;

// Simple K_{2,2} bipartite graph.
let types = vec![false, false, true, true];
let edges = vec![(0, 2), (0, 3), (1, 2), (1, 3)];
let g = create_bipartite(&types, &edges, false).unwrap();
assert_eq!(g.vcount(), 4);
assert_eq!(g.ecount(), 4);

// Rejects same-type edges.
let bad_edges = vec![(0, 1)]; // both false
assert!(create_bipartite(&types, &bad_edges, false).is_err());