Skip to main content

Module cycles

Module cycles 

Source
Expand description

Graph cycles: acyclicity, topological orders, feedback sets, cycle enumeration, cycle bases and Eulerian paths.

This module binds the C headers igraph_cycles.h and igraph_eulerian.h, documented in the Graph cycles chapter of the igraph C manual. All functions are methods of Graph.

TaskMethodResult
Is the graph a directed acyclic graph?Graph::is_dagbool
Order the vertices of a DAGGraph::topological_sortingVec<VertexId>
Find one cycle, if anyGraph::find_cycleOption<Cycle>
List all simple cyclesGraph::simple_cyclesVec<Cycle>
Visit simple cycles lazily, with early stopGraph::simple_cycles_callback()
Fundamental cycle basis (from a BFS tree)Graph::fundamental_cyclesVec<Vec<EdgeId>>
Minimum weight cycle basis (Horton), see MinimumCycleBasisOptionsGraph::minimum_cycle_basisVec<Vec<EdgeId>>
Edges whose removal breaks all cyclesGraph::feedback_arc_setVec<EdgeId>
Vertices whose removal breaks all cyclesGraph::feedback_vertex_setVec<VertexId>
Does an Eulerian path / cycle exist?Graph::is_eulerianEulerianStatus
Find an Eulerian pathGraph::eulerian_pathEulerianWalk
Find an Eulerian cycleGraph::eulerian_cycleEulerianWalk

Cycles are described both by their vertices and by their edges (see Cycle): with multi-edges, the vertex sequence alone would be ambiguous. Cycle bases are returned as edge-id lists only, as igraph does.

Some functions (Graph::simple_cycles, Graph::simple_cycles_callback, Graph::fundamental_cycles and Graph::minimum_cycle_basis) are marked experimental in igraph 1.0 (both 1.0.0 and 1.0.1): their behavior may change in future releases of the C library. None of the C sources bound here changed between igraph 1.0.0 and 1.0.1.

§See also

Related functionality in other modules:

§Example

Scheduling tasks with dependencies: a topological order exists exactly when the dependency graph has no cycle.

use igraph::prelude::*;

// 0: fetch, 1: configure, 2: build, 3: test, 4: package
let mut deps = Graph::from_edges(&[(0, 1), (1, 2), (2, 3), (2, 4), (3, 4)], 5, true)?;
assert!(deps.is_dag()?);
assert_eq!(deps.topological_sorting(NeighborMode::Out)?, vec![0, 1, 2, 3, 4]);

// Someone adds a circular dependency "package -> configure" ...
deps.add_edge(4, 1)?;
assert!(!deps.is_dag()?);
let cycle = deps.find_cycle(NeighborMode::Out)?.expect("there is a cycle now");
assert!(cycle.vertices.contains(&4) && cycle.vertices.contains(&1));
// ... and removing the edges of a feedback arc set fixes it again.
let fas = deps.feedback_arc_set(None, FasAlgorithm::ExactIp)?;
assert_eq!(fas.len(), 1);
deps.delete_edges(&fas)?;
assert!(deps.is_dag()?);

Structs§

Cycle
A cycle (closed walk) of a graph, given both as vertices and edges.
EulerianStatus
Whether a graph has an Eulerian path and/or cycle, see Graph::is_eulerian.
EulerianWalk
An Eulerian path or cycle, see Graph::eulerian_path and Graph::eulerian_cycle.
MinimumCycleBasisOptions
Options for Graph::minimum_cycle_basis.
SimpleCyclesOptions
Options for Graph::simple_cycles and Graph::simple_cycles_callback.