当前位置:网站首页>【数模】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
-一个指定最小周期的标量
输出中的周期长度。
边栏推荐
- [knife-4j quickly build swagger]
- Five years of automated testing, and finally into the ByteDance, the annual salary of 30W is not out of reach
- Detect when a tab bar item is pressed
- 用CPU方案打破内存墙?学PayPal堆傲腾扩容量,漏查欺诈交易量可降至1/30
- Kivy tutorial of setting the size and background of the form (tutorial includes source code)
- A picture to understand! Why did the school teach you coding but still not
- Up to 5million per person per year! Choose people instead of projects, focus on basic scientific research, and scientists dominate the "new cornerstone" funded by Tencent to start the application
- POJ training plan 2253_ Frogger (shortest /floyd)
- 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?
- AI 落地新题型 RPA + AI =?
猜你喜欢
Have you got the same "artifact" of cross architecture development praised by various industry leaders?
Win11远程桌面连接怎么打开?Win11远程桌面连接的五种方法
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
Continuous learning of Robotics (Automation) - 2022-
What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
Intel David tuhy: the reason for the success of Intel aoten Technology
Mathematical analysis_ Notes_ Chapter 10: integral with parameters
[knife-4j quickly build swagger]
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
【ArcGIS教程】专题图制作-人口密度分布图——人口密度分析
随机推荐
[coded font series] opendyslexic font
EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
[untitled]
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
Win11远程桌面连接怎么打开?Win11远程桌面连接的五种方法
A picture to understand! Why did the school teach you coding but still not
赠票速抢|行业大咖纵论软件的质量与效能 QECon大会来啦
SSM+jsp实现仓库管理系统,界面那叫一个优雅
VIM - own active button indent this command "suggestions collection"
[ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
Intel David tuhy: the reason for the success of Intel aoten Technology
ACL2022 | 分解的元学习小样本命名实体识别
Unit test asp Net MVC 4 Application - unit testing asp Net MVC 4 apps thoroughly
How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
[OA] excel document generator: openpyxl module
Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
leetcode 53. Maximum Subarray 最大子数组和(中等)
食堂用户菜品关系系统(C语言课设)
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚
Jetson nano配置pytorch深度学习环境//待完善