当前位置:网站首页>[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 .
边栏推荐
- Thesis landing strategy | how to get started quickly in academic thesis writing
- 赠票速抢|行业大咖纵论软件的质量与效能 QECon大会来啦
- 【实践出真理】import和require的引入方式真的和网上说的一样吗
- What is CGI, IIS, and VPS "suggested collection"
- C#使用西门子S7 协议读写PLC DB块
- Kotlin compose text supports two colors
- NFT meta universe chain diversified ecosystem development case
- Video fusion cloud platform easycvr video Plaza left column list style optimization
- [team learning] [phase 34] Baidu PaddlePaddle AI talent Creation Camp
- B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
猜你喜欢
Have you got the same "artifact" of cross architecture development praised by various industry leaders?
Win11 control panel shortcut key win11 multiple methods to open the control panel
What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
EasyCVR视频广场点击播放时,主菜单高亮效果消失问题的修复
namespace基础介绍
Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
英特尔David Tuhy:英特尔傲腾技术成功的原因
程序员上班摸鱼,这么玩才高端!
[coded font series] opendyslexic font
随机推荐
acwing 843. n-皇后问题
Video fusion cloud platform easycvr video Plaza left column list style optimization
buildroot的根文件系统提示“depmod:applt not found”
过气光刻机也不能卖给中国!美国无理施压荷兰ASML,国产芯片再遭打压
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
Introduction to the PureMVC series
ESG全球领导者峰会|英特尔王锐:以科技之力应对全球气候挑战
Win11玩绝地求生(PUBG)崩溃怎么办?Win11玩绝地求生崩溃解决方法
图灵诞辰110周年,智能机器预言成真了吗?
Golang calculates constellations and signs based on birthdays
Gpt-3 is a peer review online when it has been submitted for its own research
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
食堂用户菜品关系系统(C语言课设)
案例大赏:英特尔携众多合作伙伴推动多领域AI产业创新发展
EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
NTU notes 6422quiz review (1-3 sections)
How do test / development programmers get promoted? From nothing, from thin to thick
1.19.11. SQL client, start SQL client, execute SQL query, environment configuration file, restart policy, user-defined functions, constructor parameters
acwing 843. N-queen problem
Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist