当前位置:网站首页>[digital analog] source code of MATLAB allcycles() function (not available before 2021a)
[digital analog] source code of MATLAB allcycles() function (not available before 2021a)
2022-07-07 04:41:00 【Dream of Grass】
Matlaballcycles()
Function source code
In this previous blog post Use a program to find all the directed cycles of a directed graph ( Directed ring ) And visualize There's one used in allcycles
function , This function has only 2021a Only then , If matlab If the version is not high, you can't use this function , So for the convenience of everyone , I put allcycles
Find the built-in function of and share it with you .
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
Do a little novel Ming
Calculate all periods in a directed graph
CYCLES
= ALLCYCLES
(G
) Computing digraphs G All cycles in
Cell array , among CYCLES
{ i
} Is a numerical node id Vector ( If G
No node name ) Or a cell array of character vectors ( If G
The name of the node ). CYCLES
Every cycle in starts with the smallest node
Indexes . If G It's acyclic , that CYCLES It's empty . The cycle is
The order of lexicography .
[CYCLES
, EDGECYCLES
] = ALLCYCLES
(G
) Also returns an array of cells
EDGECYCLES
, among EDGECYCLES
{ i
} Include the edges on the loop
cycle { I } Of G.
[… = ALLCYCLES
(G
, Name
, Value
) Specify one or more additional values
Use the name - Value to parameter options . The available options are :
MaxNumCycles
- A scalar that specifies the maximum number
Period of output .
MaxCycleLength
- A scalar that specifies the maximum period
Cycle length in output .
MinCycleLength
- A scalar that specifies the minimum period
Cycle length in output .
边栏推荐
- Easycvr cannot be played using webrtc. How to solve it?
- How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
- AI landing new question type RPA + AI =?
- 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
- Poor math students who once dropped out of school won the fields award this year
- Different meat customers joined hands with Dexter to launch different hamburgers in some stores across the country
- 论文上岸攻略 | 如何快速入门学术论文写作
- 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
- 视频融合云平台EasyCVR视频广场左侧栏列表样式优化
- MySQL null value processing and value replacement
猜你喜欢
Win11玩绝地求生(PUBG)崩溃怎么办?Win11玩绝地求生崩溃解决方法
The root file system of buildreoot prompts "depmod:applt not found"
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
Vscode 如何使用内置浏览器?
Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
This "advanced" technology design 15 years ago makes CPU shine in AI reasoning
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚
On the 110th anniversary of Turing's birth, has the prediction of intelligent machine come true?
[on automation experience] the growth path of automated testing
随机推荐
广告归因:买量如何做价值衡量?
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
这项15年前的「超前」技术设计,让CPU在AI推理中大放光彩
Detect when a tab bar item is pressed
How do test / development programmers get promoted? From nothing, from thin to thick
Digital chemical plant management system based on Virtual Simulation Technology
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
Kivy tutorial of setting the size and background of the form (tutorial includes source code)
案例大赏:英特尔携众多合作伙伴推动多领域AI产业创新发展
关于01背包个人的一些理解
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
Network Security Learning - Information Collection
ACL2022 | 分解的元学习小样本命名实体识别
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
图灵诞辰110周年,智能机器预言成真了吗?
树与图的深度优先遍历模版原理
Video fusion cloud platform easycvr video Plaza left column list style optimization
Surpassing postman, the new generation of domestic debugging tool apifox is elegant enough to use
[coded font series] opendyslexic font
leetcode 53. Maximum Subarray 最大子数组和(中等)