当前位置:网站首页>【數模】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 -一個指定最小周期的標量
輸出中的周期長度。
边栏推荐
- Oracle -- 视图与序列
- Jetson nano configures pytorch deep learning environment / / to be improved
- Unit test asp Net MVC 4 Application - unit testing asp Net MVC 4 apps thoroughly
- 每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报
- 掌握软件安全测试方法秘笈,安全测试报告信手捏来
- Common methods of list and map
- kivy教程之设置窗体大小和背景(教程含源码)
- EasyCVR视频广场点击播放时,主菜单高亮效果消失问题的修复
- On the 110th anniversary of Turing's birth, has the prediction of intelligent machine come true?
- 数学分析_笔记_第10章:含参变量积分
猜你喜欢

mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi

DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)

The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?

Vscode 如何使用内置浏览器?

What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash

Win11截图键无法使用怎么办?Win11截图键无法使用的解决方法

Intel David tuhy: the reason for the success of Intel aoten Technology

各路行业大佬称赞的跨架构开发“神器”,你get同款了吗?

Ssm+jsp realizes enterprise management system (OA management system source code + database + document +ppt)

图灵诞辰110周年,智能机器预言成真了吗?
随机推荐
【实践出真理】import和require的引入方式真的和网上说的一样吗
测试/开发程序员怎么升职?从无到有,从薄变厚.......
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!
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
EasyCVR无法使用WebRTC进行播放,该如何解决?
This "advanced" technology design 15 years ago makes CPU shine in AI reasoning
Two divs are on the same line, and the two divs do not wrap "recommended collection"
leetcode 53. Maximum Subarray 最大子数组和(中等)
案例大赏:英特尔携众多合作伙伴推动多领域AI产业创新发展
What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
JetBrain Pycharm的一系列快捷键
mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi
A detailed explanation of head pose estimation [collect good articles]
Win11图片打不开怎么办?Win11无法打开图片的修复方法
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
See Gardenia minor
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
MySQL forgot how to change the password
Wechat can play the trumpet. Pinduoduo was found guilty of infringement. The shipment of byte VR equipment ranks second in the world. Today, more big news is here