当前位置:网站首页>【数模】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
-一个指定最小周期的标量
输出中的周期长度。
边栏推荐
- EasyCVR集群版本添加RTSP设备提示服务器ID错误,该如何解决?
- 未婚夫捐5亿美元给女PI,让她不用申请项目,招150位科学家,安心做科研!
- [team learning] [34 issues] scratch (Level 2)
- Dab-detr: dynamic anchor boxes are better queries for Detr translation
- 图灵诞辰110周年,智能机器预言成真了吗?
- EasyCVR无法使用WebRTC进行播放,该如何解决?
- [written to the person who first published the paper] common problems in writing comprehensive scientific and Technological Papers
- NFT meta universe chain diversified ecosystem development case
- The request request is encapsulated in uni app, which is easy to understand
- Formation continue en robotique (automatisation) - 2022 -
猜你喜欢
英特尔David Tuhy:英特尔傲腾技术成功的原因
计数排序基础思路
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚
Win11图片打不开怎么办?Win11无法打开图片的修复方法
图灵诞辰110周年,智能机器预言成真了吗?
Common methods of list and map
NTU notes 6422quiz review (1-3 sections)
Continuous learning of Robotics (Automation) - 2022-
kivy教程之设置窗体大小和背景(教程含源码)
The root file system of buildreoot prompts "depmod:applt not found"
随机推荐
NanopiNEO使用开发过程记录
[coded font series] opendyslexic font
C # use Siemens S7 protocol to read and write PLC DB block
Have you got the same "artifact" of cross architecture development praised by various industry leaders?
【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ
广告归因:买量如何做价值衡量?
Win11截图键无法使用怎么办?Win11截图键无法使用的解决方法
A detailed explanation of head pose estimation [collect good articles]
一图看懂!为什么学校教了你Coding但还是不会的原因...
ESG全球领导者峰会|英特尔王锐:以科技之力应对全球气候挑战
1.19.11. SQL client, start SQL client, execute SQL query, environment configuration file, restart policy, user-defined functions, constructor parameters
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
Why does WordPress open so slowly?
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
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!
【自动化经验谈】自动化测试成长之路
Advertising attribution: how to measure the value of buying volume?
Unity3d can change colors and display samples in a building GL material
Kotlin compose text supports two colors