当前位置:网站首页>[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 .
边栏推荐
- Win11图片打不开怎么办?Win11无法打开图片的修复方法
- Master the secrets of software security testing methods, and pinch the security test report with your hands
- Is there any way to bookmark the code in the visual studio project- Is there a way to bookmark code in a Visual Studio project?
- 【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ
- C#使用西门子S7 协议读写PLC DB块
- Intel David tuhy: the reason for the success of Intel aoten Technology
- SQL where multiple field filtering
- 赠票速抢|行业大咖纵论软件的质量与效能 QECon大会来啦
- Jetson nano configures pytorch deep learning environment / / to be improved
- Highly paid programmers & interview questions. Are you familiar with the redis cluster principle of series 120? How to ensure the high availability of redis (Part 1)?
猜你喜欢
[system management] clear the icon cache of deleted programs in the taskbar
Break the memory wall with CPU scheme? Learn from PayPal to expand the capacity of aoteng, and the volume of missed fraud transactions can be reduced to 1/30
EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
Win11图片打不开怎么办?Win11无法打开图片的修复方法
Introduction to the PureMVC series
数学分析_笔记_第10章:含参变量积分
This "advanced" technology design 15 years ago makes CPU shine in AI reasoning
英特尔与信步科技共同打造机器视觉开发套件,协力推动工业智能化转型
Camera calibration (I): robot hand eye calibration
AI 落地新题型 RPA + AI =?
随机推荐
Both primary and secondary equipment numbers are 0
【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
ESG Global Leaders Summit | Intel Wang Rui: coping with global climate challenges with the power of science and technology
Dab-detr: dynamic anchor boxes are better queries for Detr translation
【实践出真理】import和require的引入方式真的和网上说的一样吗
图灵诞辰110周年,智能机器预言成真了吗?
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
EasyCVR集群版本添加RTSP设备提示服务器ID错误,该如何解决?
Golang compresses and decompresses zip files
[team learning] [34 sessions] Alibaba cloud Tianchi online programming training camp
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚
On the 110th anniversary of Turing's birth, has the prediction of intelligent machine come true?
日常工作中程序员最讨厌哪些工作事项?
EasyCVR无法使用WebRTC进行播放,该如何解决?
leetcode 53. Maximum Subarray 最大子数组和(中等)
Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
NTU notes 6422quiz review (1-3 sections)
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
Acl2022 | decomposed meta learning small sample named entity recognition