Expand description
Circulant graph constructor (ALGO-CN-011).
Counterpart of igraph_circulant() in
references/igraph/src/constructors/circulant.c:51-112.
A circulant graph G(n, shifts) has n vertices v_0, …, v_{n-1}
and, for every shift s in shifts, the edges
(v_j, v_{(j + s) mod n}) for every j ∈ [0, n).
The constructor handles a few canonical-form rules so the same graph is built regardless of how shifts are spelled:
- Each shift is reduced modulo
ninto[0, n). - In the undirected case, a shift
sand its complementn − sgenerate the same set of edges, so a shift≥ (n + 1) / 2is replaced withn − sbefore dedup. shift == 0is always dropped (it would emitnself-loops).- Repeated shifts (after the above normalisation) are deduplicated so the result has no parallel edges.
- Special case: when
nis even, the graph is undirected, and a shift equalsn / 2, only the firstn / 2edges are emitted — the wrap-around would otherwise produce a duplicate of every antipodal edge.
Specializations:
circulant(n, &[1], false)isring_graph(n)— the cycleC_n.circulant(n, &[k], false)(with0 < k < n/2) is precisely the inner layer ofgeneralized_petersen(n, k).circulant(n, &[1, 2], false)is the squared cycle / Möbius ladder family.circulant(n, &(1..n/2).collect::<Vec<_>>(), false)is the complete graphK_n(every distinct undirected shift contributes).
Time complexity: O(|V| · |shifts|).
Functions§
- circulant
- Build the circulant graph
G(n, shifts).