cycles#

Enumerate simple cycles of a given length.

cycles(g, n)#

Return all simple cycles of length n in the diagram.

Cycles are reported in a canonical form: among all rotations and the reversed cycle’s rotations, the lexicographically smallest tuple is kept. This avoids duplicates caused by different starting points or direction.

Parameters:
  • g (PlanarDiagram) – Unoriented planar diagram.

  • n (int) – Target cycle length (must be ≥ 1).

Returns:

A set of node-tuples, each tuple representing a simple cycle of length n.

Return type:

set[tuple]