Skip to main content

graph_product

Function graph_product 

Source
pub fn graph_product(
    g1: &Graph,
    g2: &Graph,
    product_type: GraphProductType,
) -> IgraphResult<Graph>
Expand description

Computes a graph product selected by product_type.

Unified dispatcher for all five non-rooted graph product types, matching the C igraph_product() function. The rooted product requires an extra root parameter and is available separately via rooted_product.

Both graphs must have the same directedness. The result has |V1| * |V2| vertices where vertex (i, j) is identified by i * |V2| + j.

ยงExamples

use rust_igraph::{Graph, graph_product, GraphProductType};

let mut g1 = Graph::with_vertices(2);
g1.add_edge(0, 1).unwrap();
let mut g2 = Graph::with_vertices(2);
g2.add_edge(0, 1).unwrap();

let p = graph_product(&g1, &g2, GraphProductType::Cartesian).unwrap();
assert_eq!(p.vcount(), 4);
assert_eq!(p.ecount(), 4);