pub fn isomorphic(graph1: &Graph, graph2: &Graph) -> IgraphResult<bool>Expand description
Decide whether two graphs are isomorphic, choosing a backend automatically.
Mirrors igraph_isomorphic: the dispatch picks whichever engine fits the
input. Only the Boolean verdict is returned — call isomorphic_vf2 or
isomorphic_bliss directly when you also need the vertex mapping.
The dispatch is:
- directed vs. undirected →
IgraphError::InvalidArgument; - if either graph has multi-edges, both are reduced with
simplify_and_colorizeand compared by colour-aware VF2 (self-loops become vertex colours, parallel-edge multiplicities become edge colours); - otherwise, differing vertex or edge counts →
false; - otherwise the canonical-form (BLISS) test decides.
Upstream takes an O(1) precomputed-isoclass shortcut for tiny graphs
(directed 3–4, undirected 3–6 vertices) before falling back to BLISS; the
canonical-form test returns the identical verdict, so this port uses it
uniformly. Self-loops are supported (folded into the BLISS vertex
invariant).
§Errors
Returns IgraphError::InvalidArgument if the two graphs differ in
directedness. Propagates backend errors otherwise.
§Examples
use rust_igraph::{Graph, isomorphic};
// A 4-cycle and its relabelling are isomorphic.
let mut a = Graph::new(4, false).unwrap();
for (u, v) in [(0, 1), (1, 2), (2, 3), (3, 0)] {
a.add_edge(u, v).unwrap();
}
let mut b = Graph::new(4, false).unwrap();
for (u, v) in [(0, 2), (2, 1), (1, 3), (3, 0)] {
b.add_edge(u, v).unwrap();
}
assert!(isomorphic(&a, &b).unwrap());
// A 4-cycle is not isomorphic to a path on 4 vertices.
let mut p = Graph::new(4, false).unwrap();
for (u, v) in [(0, 1), (1, 2), (2, 3)] {
p.add_edge(u, v).unwrap();
}
assert!(!isomorphic(&a, &p).unwrap());