simple_cycles: Finds all simple cycles in a graph.

View source: R/cycles.R

simple_cyclesR Documentation

Finds all simple cycles in a graph.

Description

[Experimental]

This function lists all simple cycles in a graph within a range of cycle lengths. A cycle is called simple if it has no repeated vertices.

Multi-edges and self-loops are taken into account. Note that typical graphs have exponentially many cycles and the presence of multi-edges exacerbates this combinatorial explosion.

Usage

simple_cycles(
  graph,
  mode = c("out", "in", "all", "total"),
  min = NULL,
  max = NULL
)

Arguments

graph

The input graph.

mode

Character constant specifying how to handle directed graphs. out follows edge directions, ⁠in⁠ follows edges in the reverse direction, and all ignores edge directions. Ignored in undirected graphs.

min

Lower limit on cycle lengths to consider. NULL means no limit.

max

Upper limit on cycle lengths to consider. NULL means no limit.

Value

A named list, with two entries:

vertices

The list of cycles in terms of their vertices.

edges

The list of cycles in terms of their edges.

Related documentation in the C library

simple_cycles().

See Also

Graph cycles feedback_arc_set(), feedback_vertex_set(), find_cycle(), girth(), has_eulerian_path(), is_acyclic(), is_dag()

Examples


g <- graph_from_literal(A -+ B -+ C -+ A -+ D -+ E +- F -+ A, E -+ E, A -+ F, simplify = FALSE)
simple_cycles(g)
simple_cycles(g, mode = "all") # ignore edge directions
simple_cycles(g, mode = "all", min = 2, max = 3) # limit cycle lengths


igraph/rigraph documentation built on June 13, 2025, 1:44 p.m.