%% Limit Number of Cycles Returned
% Use the 'MaxNumCycles', 'MaxCycleLength', and 'MinCycleLength' options to limit the number of cycles returned by allcycles.
%
% Create an adjacency matrix for a complete graph with 20 nodes. Create an undirected graph from the adjacency matrix, omitting self-loops.

A = ones(20);
G = graph(A,'omitselfloops');

%
% Since all of the nodes in the graph are connected to all other nodes, there are a large number of cycles in the graph (more than 1.7e17). Therefore, it is not feasible to calculate all of the cycles since the results will not fit in memory. Instead, calculate the first 10 cycles.

cycles1 = allcycles(G,'MaxNumCycles',10)

%
% Now calculate the first 10 cycles that have a cycle length less than or equal to 3.

cycles2 = allcycles(G,'MaxNumCycles',10,'MaxCycleLength',3)

%
% Finally, calculate the first 10 cycles that have a cycle length greater than or equal to 4.

cycles3 = allcycles(G,'MaxNumCycles',10,'MinCycleLength',4)

% Copyright 2020 The MathWorks, Inc.