Skip to main content

count_automorphisms

Function count_automorphisms 

Source
pub fn count_automorphisms(
    graph: &Graph,
    colors: Option<&[u32]>,
) -> IgraphResult<f64>
Expand description

Count the automorphisms of graph — the order |Aut(G)| of its automorphism group.

An automorphism is a vertex permutation that maps graph onto itself (preserving adjacency and, when supplied, vertex colours). The count can grow factorially, so it is returned as an f64, exactly as igraph’s igraph_count_automorphisms returns an igraph_real_t. The value is exact up to 2^53; beyond that the f64 loses precision (igraph has the same limit and offers a string-returning variant for larger groups, which is out of scope here).

colors is an optional per-vertex colour slice (length must equal the vertex count); only colour-preserving permutations are counted. Pass None for an uncoloured graph.

The count is computed by the shared individualization-refinement engine (see canonical_permutation): |Aut(G)| equals the number of leaves of the I-R search tree whose relabeled-adjacency certificate equals the canonical (lexicographically maximal) one.

§Scope

Simple graphs (directed or undirected), self-loops allowed, optional vertex colours. Multi-edges are rejected.

§Errors

Returns an error if colors has the wrong length or the graph has multiple edges between the same pair of vertices.

§Examples

use rust_igraph::{Graph, count_automorphisms};

// The 4-cycle C_4 has the dihedral group of order 2*4 = 8.
let mut c4 = Graph::new(4, false).unwrap();
for (u, v) in [(0, 1), (1, 2), (2, 3), (3, 0)] {
    c4.add_edge(u, v).unwrap();
}
assert_eq!(count_automorphisms(&c4, None).unwrap(), 8.0);