pub fn modular_product(g1: &Graph, g2: &Graph) -> IgraphResult<Graph>Expand description
Computes the modular product of two graphs.
The result has |V1| * |V2| vertices. Vertex (i, j) is identified by
i * |V2| + j. An edge exists between (i1, j1) and (i2, j2) iff:
(i1, i2)is an edge ing1AND(j1, j2)is an edge ing2, OR(i1, i2)is NOT an edge ing1AND(j1, j2)is NOT an edge ing2(withi1 ≠ i2andj1 ≠ j2).
Both graphs must be simple (no self-loops, no multi-edges) and have the same directedness.
Computed as tensor(g1, g2) ∪ tensor(complement(g1), complement(g2)).
§Arguments
g1— the first factor graph.g2— the second factor graph.
§Errors
Returns InvalidArgument if:
- the graphs differ in directedness,
- either graph is not simple,
- the product vertex count overflows
u32.
§Examples
use rust_igraph::{Graph, modular_product};
// P3 modular P3: modular product of two paths on 3 vertices
let mut g1 = Graph::with_vertices(3);
g1.add_edge(0, 1).unwrap();
g1.add_edge(1, 2).unwrap();
let mut g2 = Graph::with_vertices(3);
g2.add_edge(0, 1).unwrap();
g2.add_edge(1, 2).unwrap();
let p = modular_product(&g1, &g2).unwrap();
assert_eq!(p.vcount(), 9);