This is a Matlab implementation of the general purpose algorithm for counting simple cycles presented in the article "A general purpose algorithm for counting simple cycles and simple paths of any length" available at https://arxiv.org/abs/1612.05531 (to appear in Algorithmica). Simple cycles, a.k.a elementary circuits, self-avoiding walks, are cycles that do not visit any vertex more than once.
The algorithm, a combinatorial sieve, counts simple cycles (self-loops, backtracks, triangles, squares, pentagons, etc.) of any length on both directed and undirected networks, returning a list with the number of simple cycles up to some desired length L. The algorithm also works on weighted graphs, where it returns the sum of the weights of all the simple cycles of any given length.
Use as follows:
[Primes,elapsedTime] = CycleCount(A,L0)
with Primes the list with the number of simple cycles, A the graph adjacency matrix and L0 the maximum length up to which to count the simple cycles.
PYTHON version available at: https://github.com/milani/cycleindex
Pierre-Louis Giscard (2023). CycleCount(A,L0) (https://www.mathworks.com/matlabcentral/fileexchange/60814-cyclecount-a-l0), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Now detects automatically if the graph is weighted or not and works accordingly in both situations without having to deactivate line 54.
Fixed a minor error in the published code causing the output for the number of simple cycles on some directed graphs to be faulty. Thanks to Evangelos Evangelou for pointing the error out. Publications based on CycleCount are not affected.