当前位置:网站首页>[digital analog] source code of MATLAB allcycles() function (not available before 2021a)
[digital analog] source code of MATLAB allcycles() function (not available before 2021a)
2022-07-07 04:41:00 【Dream of Grass】
Matlaballcycles() Function source code
In this previous blog post Use a program to find all the directed cycles of a directed graph ( Directed ring ) And visualize There's one used in allcycles function , This function has only 2021a Only then , If matlab If the version is not high, you can't use this function , So for the convenience of everyone , I put allcycles Find the built-in function of and share it with you .
function [cycles, edgecycles] = allcycles(G, varargin)
% ALLCYCLES Compute all cycles in digraph
% CYCLES = ALLCYCLES(G) computes all the cycles in digraph G. CYCLES is a
% cell array in which CYCLES{
i} is a vector of numeric node IDs (if G
% does not have node names) or a cell array of character vectors (if G
% has node names). Each cycle in CYCLES begins with the smallest node
% index. If G is acyclic, then CYCLES is empty. The cycles are in
% lexicographical order.
%
% [CYCLES, EDGECYCLES] = ALLCYCLES(G) also returns a cell array
% EDGECYCLES in which EDGECYCLES{
i} contains the edges on the cycle
% CYCLES{
i} of G.
%
% [...] = ALLCYCLES(G, Name, Value) specifies one or more additional
% options using name-value pair arguments. The available options are:
%
% 'MaxNumCycles' - A scalar that specifies the maximum number
% of cycles in the output.
% 'MaxCycleLength' - A scalar that specifies the maximum cycle
% length of cycles in the output.
% 'MinCycleLength' - A scalar that specifies the minimum cycle
% length of cycles in the output.
%
% See also ISDAG, HASCYCLES, CYCLEBASIS, ALLPATHS
% Copyright 2020-2021 The MathWorks, Inc.
%
% Reference:
% Johnson, Donald B. "Finding all the elementary circuits of a directed
% graph." SIAM Journal on Computing 4.1 (1975): 77-84.
[maxNumCycles, maxCycleLength, minCycleLength] = parseInputs(varargin{
:});
if maxCycleLength < minCycleLength
cycles = cell(0, 1);
edgecycles = cell(0, 1);
return
end
try
if nargout < 2
cycles = allSimpleCycles(G.Underlying, maxNumCycles, maxCycleLength,...
minCycleLength);
else
[cycles, edgecycles] = allSimpleCycles(G.Underlying, maxNumCycles,...
maxCycleLength, minCycleLength);
end
catch e
if e.identifier == "MATLAB:nomem"
error(message('MATLAB:graphfun:allcycles:nomem'));
else
rethrow(e);
end
end
[names, hasNodeNames] = getNodeNames(G);
names = names.';
if hasNodeNames
for i = 1:size(cycles, 1)
cycles{
i} = names(cycles{
i});
end
end
end
function [maxNumCycles, maxCycleLength, minCycleLength] = parseInputs(varargin)
names = {
'MaxNumCycles', 'MaxCycleLength', 'MinCycleLength'};
maxNumCycles = Inf;
maxCycleLength = Inf;
minCycleLength = 1;
for i = 1:2:numel(varargin)
opt = validatestring(varargin{
i}, names);
if i+1 > numel(varargin)
error(message('MATLAB:graphfun:allcycles:KeyWithoutValue', opt));
end
switch opt
case 'MaxNumCycles'
maxNumCycles = varargin{
i+1};
validateattributes(maxNumCycles, {
'numeric'}, {
'scalar', 'real', 'nonnegative', 'integer'}, '', 'MaxNumCycles')
case 'MaxCycleLength'
maxCycleLength = varargin{
i+1};
validateattributes(maxCycleLength, {
'numeric'}, {
'scalar', 'real', 'positive', 'integer'}, '', 'MaxCycleLength')
case 'MinCycleLength'
minCycleLength = varargin{
i+1};
validateattributes(minCycleLength, {
'numeric'}, {
'scalar', 'real', 'positive', 'integer'}, '', 'MinCycleLength')
end
end
end
Do a little novel Ming
Calculate all periods in a directed graph
CYCLES = ALLCYCLES(G) Computing digraphs G All cycles in
Cell array , among CYCLES{ i} Is a numerical node id Vector ( If G
No node name ) Or a cell array of character vectors ( If G
The name of the node ). CYCLES Every cycle in starts with the smallest node
Indexes . If G It's acyclic , that CYCLES It's empty . The cycle is
The order of lexicography .
[CYCLES, EDGECYCLES] = ALLCYCLES(G) Also returns an array of cells
EDGECYCLES, among EDGECYCLES{ i} Include the edges on the loop
cycle { I } Of G.
[… = ALLCYCLES(G, Name, Value) Specify one or more additional values
Use the name - Value to parameter options . The available options are :
MaxNumCycles- A scalar that specifies the maximum number
Period of output .
MaxCycleLength- A scalar that specifies the maximum period
Cycle length in output .
MinCycleLength - A scalar that specifies the minimum period
Cycle length in output .
边栏推荐
- Ssm+jsp realizes enterprise management system (OA management system source code + database + document +ppt)
- Introduction to the PureMVC series
- 《原动力 x 云原生正发声 降本增效大讲堂》第三讲——Kubernetes 集群利用率提升实践
- ESG Global Leaders Summit | Intel Wang Rui: coping with global climate challenges with the power of science and technology
- [multi threading exercise] write a multi threading example of the producer consumer model.
- Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
- What is CGI, IIS, and VPS "suggested collection"
- kivy教程之设置窗体大小和背景(教程含源码)
- [team learning] [phase 34] Baidu PaddlePaddle AI talent Creation Camp
- Five years of automated testing, and finally into the ByteDance, the annual salary of 30W is not out of reach
猜你喜欢

Win11 control panel shortcut key win11 multiple methods to open the control panel

Digital chemical plant management system based on Virtual Simulation Technology

Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry

计数排序基础思路

Camera calibration (I): robot hand eye calibration

Basic idea of counting and sorting

图灵诞辰110周年,智能机器预言成真了吗?

Network Security Learning - Information Collection

Common methods of list and map

mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
随机推荐
Practice Guide for interface automation testing (middle): what are the interface testing scenarios
True global ventures' newly established $146million follow-up fund was closed, of which the general partner subscribed $62million to invest in Web3 winners in the later stage
[knife-4j quickly build swagger]
Both primary and secondary equipment numbers are 0
acwing 843. N-queen problem
Vscode 如何使用内置浏览器?
Organize five stages of actual attack and defense drill
On the 110th anniversary of Turing's birth, has the prediction of intelligent machine come true?
buildroot的根文件系统提示“depmod:applt not found”
Mathematical analysis_ Notes_ Chapter 10: integral with parameters
Fix the problem that the highlight effect of the main menu disappears when the easycvr Video Square is clicked and played
Basic idea of counting and sorting
关于01背包个人的一些理解
The request request is encapsulated in uni app, which is easy to understand
MySQL split method usage
A series of shortcut keys for jetbrain pychar
Gpt-3 is a peer review online when it has been submitted for its own research
赠票速抢|行业大咖纵论软件的质量与效能 QECon大会来啦
Network Security Learning - Information Collection
[team learning] [34 sessions] Alibaba cloud Tianchi online programming training camp