Skip to main content

bipartite_projection

Function bipartite_projection 

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

Project a bipartite graph onto one of its vertex types.

Given a bipartite graph with vertex types specified by types (where types[v] is false for type-0 and true for type-1), this function creates the projection onto the specified type. Two vertices of the target type are connected in the projection if they share at least one common neighbor of the other type.

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.
  • project_type — which type to project onto (false = type-0, true = type-1).

§Errors

  • InvalidArgument if types.len() != vcount().
  • InvalidArgument if a non-bipartite edge is found (both endpoints have the same type).

§Examples

use rust_igraph::{Graph, bipartite_projection};

// Bipartite graph: types [F, F, T, T]
// Edges: 0-2, 0-3, 1-2, 1-3
// Projection onto type F (false): 0 and 1 share neighbors 2 and 3.
let mut g = Graph::with_vertices(4);
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(1, 3).unwrap();
let types = [false, false, true, true];
let proj = bipartite_projection(&g, &types, false).unwrap();
assert_eq!(proj.graph.vcount(), 2); // vertices 0, 1
assert_eq!(proj.graph.ecount(), 1); // edge 0-1
assert_eq!(proj.multiplicity[0], 2); // shared neighbors: 2 and 3
assert_eq!(proj.vertex_map, vec![0, 1]);