当前位置:网站首页>【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
2022-07-06 22:13: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
-一个指定最小周期的标量
输出中的周期长度。
边栏推荐
- Both primary and secondary equipment numbers are 0
- Comment les tests de logiciels sont - ils effectués sur le site Web? Testez la stratégie!
- EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
- 微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
- leetcode 53. Maximum Subarray 最大子数组和(中等)
- Win11远程桌面连接怎么打开?Win11远程桌面连接的五种方法
- How do test / development programmers get promoted? From nothing, from thin to thick
- Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist
- VIM - own active button indent this command "suggestions collection"
- leetcode 53. Maximum Subarray 最大子数组和(中等)
猜你喜欢
视频融合云平台EasyCVR视频广场左侧栏列表样式优化
Kivy tutorial of setting the size and background of the form (tutorial includes source code)
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
How do test / development programmers get promoted? From nothing, from thin to thick
[written to the person who first published the paper] common problems in writing comprehensive scientific and Technological Papers
Win11截图键无法使用怎么办?Win11截图键无法使用的解决方法
Network Security Learning - Information Collection
[team learning] [phase 34] Baidu PaddlePaddle AI talent Creation Camp
EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
随机推荐
VM virtual machine operating system not found and NTLDR is missing
Easycvr cannot be played using webrtc. How to solve it?
英特尔与信步科技共同打造机器视觉开发套件,协力推动工业智能化转型
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
Advertising attribution: how to measure the value of buying volume?
leetcode 53. Maximum Subarray 最大子数组和(中等)
一度辍学的数学差生,获得今年菲尔兹奖
EasyCVR平台接入RTMP协议,接口调用提示获取录像错误该如何解决?
The root file system of buildreoot prompts "depmod:applt not found"
Ssm+jsp realizes the warehouse management system, and the interface is called an elegant interface
NFT meta universe chain diversified ecosystem development case
Jetson nano配置pytorch深度学习环境//待完善
[system management] clear the icon cache of deleted programs in the taskbar
See Gardenia minor
Fix the problem that the highlight effect of the main menu disappears when the easycvr Video Square is clicked and played
英特尔David Tuhy:英特尔傲腾技术成功的原因
The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly
What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
抖音或将推出独立种草社区平台:会不会成为第二个小红书
NTU notes 6422quiz review (1-3 sections)