当前位置:网站首页>[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 .
边栏推荐
- Lessons and thoughts of the first SQL injection
- [team learning] [34 issues] scratch (Level 2)
- 浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
- What is CGI, IIS, and VPS "suggested collection"
- EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
- 掌握软件安全测试方法秘笈,安全测试报告信手捏来
- Data security -- 12 -- Analysis of privacy protection
- Vscode 如何使用内置浏览器?
- Win11玩绝地求生(PUBG)崩溃怎么办?Win11玩绝地求生崩溃解决方法
- 日常工作中程序员最讨厌哪些工作事项?
猜你喜欢
The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?
视频融合云平台EasyCVR视频广场左侧栏列表样式优化
acwing 843. n-皇后问题
测试/开发程序员怎么升职?从无到有,从薄变厚.......
案例大赏:英特尔携众多合作伙伴推动多领域AI产业创新发展
R语言主成分pca、因子分析、聚类对地区经济研究分析重庆市经济指标
Win11控制面板快捷键 Win11打开控制面板的多种方法
[team learning] [phase 34] Baidu PaddlePaddle AI talent Creation Camp
DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
用CPU方案打破内存墙?学PayPal堆傲腾扩容量,漏查欺诈交易量可降至1/30
随机推荐
Golang calculates constellations and signs based on birthdays
Depth first traversal template principle of tree and graph
A series of shortcut keys for jetbrain pychar
Common methods of list and map
Different meat customers joined hands with Dexter to launch different hamburgers in some stores across the country
未婚夫捐5亿美元给女PI,让她不用申请项目,招150位科学家,安心做科研!
A detailed explanation of head pose estimation [collect good articles]
各路行业大佬称赞的跨架构开发“神器”,你get同款了吗?
Structure actual training camp | after class homework | module 6
日常工作中程序员最讨厌哪些工作事项?
广告归因:买量如何做价值衡量?
Master the secrets of software security testing methods, and pinch the security test report with your hands
Vscode 如何使用内置浏览器?
[system management] clear the icon cache of deleted programs in the taskbar
Ssm+jsp realizes the warehouse management system, and the interface is called an elegant interface
AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务
Detect when a tab bar item is pressed
Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
Fiance donated 500million dollars to female PI, so that she didn't need to apply for projects, recruited 150 scientists, and did scientific research at ease!
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash