当前位置:网站首页>[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 .
边栏推荐
- 食堂用户菜品关系系统(C语言课设)
- DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
- jvm是什么?jvm调优有哪些目的?
- How to conduct website testing of software testing? Test strategy let's go!
- [knife-4j quickly build swagger]
- Win11截图键无法使用怎么办?Win11截图键无法使用的解决方法
- Meaning of 'n:m' and '1:n' in database design
- 抖音或将推出独立种草社区平台:会不会成为第二个小红书
- Nanopineo use development process record
- Vscode 如何使用内置浏览器?
猜你喜欢
C # use Siemens S7 protocol to read and write PLC DB block
The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
Optimization of channel status offline of other server devices caused by easycvr cluster restart
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚
[team learning] [34 issues] scratch (Level 2)
[coded font series] opendyslexic font
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
Common methods of list and map
这项15年前的「超前」技术设计,让CPU在AI推理中大放光彩
随机推荐
A series of shortcut keys for jetbrain pychar
[written to the person who first published the paper] common problems in writing comprehensive scientific and Technological Papers
acwing 843. N-queen problem
1.19.11. SQL client, start SQL client, execute SQL query, environment configuration file, restart policy, user-defined functions, constructor parameters
什么是Web3
[on automation experience] the growth path of automated testing
未婚夫捐5亿美元给女PI,让她不用申请项目,招150位科学家,安心做科研!
Basic idea of counting and sorting
Have you got the same "artifact" of cross architecture development praised by various industry leaders?
[system management] clear the icon cache of deleted programs in the taskbar
视频融合云平台EasyCVR视频广场左侧栏列表样式优化
EasyCVR集群版本添加RTSP设备提示服务器ID错误,该如何解决?
Poor math students who once dropped out of school won the fields award this year
软件测试之网站测试如何进行?测试小攻略走起!
Video fusion cloud platform easycvr video Plaza left column list style optimization
Zero knowledge private application platform aleo (1) what is aleo
buildroot的根文件系统提示“depmod:applt not found”
数学分析_笔记_第10章:含参变量积分
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚