pub fn lexicographic_product(g1: &Graph, g2: &Graph) -> IgraphResult<Graph>Expand description
Computes the lexicographic product of two graphs.
The result has |V1| * |V2| vertices. Vertex (i, j) is identified by
i * |V2| + j. An edge exists between (i, j) and (k, l) iff:
(i, k)is an edge ing1(regardless ofjandl), ORi == kand(j, l)is an edge ing2.
Note: unlike the other products, the lexicographic product is NOT commutative.
Both graphs must have the same directedness.
§Arguments
g1— the first factor graph (outer).g2— the second factor graph (inner).
§Errors
Returns InvalidArgument if the graphs differ in directedness, or if
the product vertex count overflows u32.
§Examples
use rust_igraph::{Graph, lexicographic_product};
let mut g1 = Graph::with_vertices(2);
g1.add_edge(0, 1).unwrap();
let g2 = Graph::with_vertices(3); // 3 isolated vertices
let p = lexicographic_product(&g1, &g2).unwrap();
assert_eq!(p.vcount(), 6);
// 1 edge in g1 × 3² = 9 cross-edges (undirected, so 9 unique pairs)
assert_eq!(p.ecount(), 9);