当前位置:网站首页>【數模】Matlab allcycles()函數的源代碼(2021a之前版本沒有)
【數模】Matlab allcycles()函數的源代碼(2021a之前版本沒有)
2022-07-07 04:40:00 【Dream of Grass】
Matlaballcycles()
函數的源代碼
在之前的這篇博文裏用程序求出有向圖的所有有向圈(有向環)並可視化中用到了一個allcycles
函數,這個函數只有2021a才有,如果matlab版本不高就用不了這個函數,所以為了方便大家使用,我把allcycles
的內置函數找到然後分享給大家。
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
做一點點小說明
計算有向圖中的所有周期
CYCLES
= ALLCYCLES
(G
)計算有向圖G中的所有周期
單元格數組,其中CYCLES
{ i
}是一個數值節點id的向量(如果G
沒有節點名稱)或字符向量的單元格數組(如果G
節點名稱)。 CYCLES
中的每個周期都從最小的節點開始
索引。 如果G是無環的,那麼CYCLES為空。 周期在
辭典編纂的秩序。
[CYCLES
, EDGECYCLES
] = ALLCYCLES
(G
)也返回一個單元格數組
EDGECYCLES
,其中EDGECYCLES
{ i
}包含循環上的邊
周期{我}的G。
[… = ALLCYCLES
(G
, Name
, Value
)指定一個或多個附加值
使用名稱-值對參數的選項。 可用選項有:
MaxNumCycles
-一個指定最大數目的標量
輸出的周期。
MaxCycleLength
-一個指定最大周期的標量
輸出中的周期長度。
MinCycleLength
-一個指定最小周期的標量
輸出中的周期長度。
边栏推荐
- How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
- Both primary and secondary equipment numbers are 0
- NFT meta universe chain diversified ecosystem development case
- NTU notes 6422quiz review (1-3 sections)
- Mathematical analysis_ Notes_ Chapter 10: integral with parameters
- Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
- EasyCVR无法使用WebRTC进行播放,该如何解决?
- On the 110th anniversary of Turing's birth, has the prediction of intelligent machine come true?
- Win11玩绝地求生(PUBG)崩溃怎么办?Win11玩绝地求生崩溃解决方法
- [ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
猜你喜欢
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
This "advanced" technology design 15 years ago makes CPU shine in AI reasoning
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
Mathematical analysis_ Notes_ Chapter 10: integral with parameters
[team learning] [34 sessions] Alibaba cloud Tianchi online programming training camp
Intel and Xinbu technology jointly build a machine vision development kit to jointly promote the transformation of industrial intelligence
Common methods of list and map
In cooperation with the research team of the clinical trial center of the University of Hong Kong and Hong Kong Gangyi hospital, Kexing launched the clinical trial of Omicron specific inactivated vacc
The request request is encapsulated in uni app, which is easy to understand
随机推荐
Intel David tuhy: the reason for the success of Intel aoten Technology
You can't sell the used lithography machine to China! The United States unreasonably pressured the Dutch ASML, and domestic chips were suppressed again
EasyCVR平台接入RTMP协议,接口调用提示获取录像错误该如何解决?
微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi
C # use Siemens S7 protocol to read and write PLC DB block
Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist
接口自动化测试实践指导(中):接口测试场景有哪些
Two divs are on the same line, and the two divs do not wrap "recommended collection"
英特尔David Tuhy:英特尔傲腾技术成功的原因
Have you got the same "artifact" of cross architecture development praised by various industry leaders?
Poor math students who once dropped out of school won the fields award this year
Meaning of 'n:m' and '1:n' in database design
What is CGI, IIS, and VPS "suggested collection"
案例大赏:英特尔携众多合作伙伴推动多领域AI产业创新发展
Different meat customers joined hands with Dexter to launch different hamburgers in some stores across the country
Nanopineo use development process record
【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
Vscode 如何使用内置浏览器?