Skip to main content

bipartite_projection_size

Function bipartite_projection_size 

Source
pub fn bipartite_projection_size(
    graph: &Graph,
    types: &[bool],
) -> IgraphResult<BipartiteProjectionSize>
Expand description

Compute sizes of both bipartite projections without building them.

Given a bipartite graph with vertex types specified by types, this function counts the vertices and edges that each projection would contain if super::bipartite_projection were called.

Two vertices of the same type are connected in a projection if they share at least one common neighbor of the other type. This function counts such pairs efficiently using a marking array.

The graph is treated as undirected regardless of its directedness.

§Arguments

  • graph — the bipartite input graph.
  • types — boolean slice of length vcount(), giving vertex types.

§Errors

  • InvalidArgument if types.len() != vcount().
  • InvalidArgument if a non-bipartite edge is found.

§Examples

use rust_igraph::{Graph, bipartite_projection_size};

// K_{2,3}: types [F, F, T, T, T]
// Edges: 0-2, 0-3, 0-4, 1-2, 1-3, 1-4
let mut g = Graph::with_vertices(5);
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(0, 4).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(1, 3).unwrap();
g.add_edge(1, 4).unwrap();
let types = [false, false, true, true, true];
let sz = bipartite_projection_size(&g, &types).unwrap();
assert_eq!(sz.vcount1, 2); // type-0 vertices: 0, 1
assert_eq!(sz.ecount1, 1); // edge 0-1 (share 3 common neighbors)
assert_eq!(sz.vcount2, 3); // type-1 vertices: 2, 3, 4
assert_eq!(sz.ecount2, 3); // K3 (all share 2 common neighbors)