Re: finding all cycles in a graph
py implementation: https://gist.github.com/joe-jordan/6548029
ref: https://cs.stackexchange.com/questions/7216/find-the-simple-cycles-in-a-directed-graph
Re: finding all cycles in a graph
From: Juan Pablo Carbajal
Subject: Re: finding all cycles in a graph
Date: Wed, 25 Jan 2012 19:43:48 +0100
On Wed, Jan 25, 2012 at 2:52 PM, Moreno Marzolla
address@hidden wrote:
On 01/24/2012 08:55 PM, Francesco Potortì wrote:
First of all, thanks to you and to those that have answered previously.
Has anyone an Octave program for finding all cycles in a graph?
You're of course aware that there are exponentially many cycles in
general? There usually are better ways to accomplish whatever you need
than looking for all cycles of a graph.That's what I suspect too. I have been made this request by a colleague
of mine, and anyway I think it may be a useful way of starting to
understand the problem, which anyway involves small graphs only.Hello,
you might be interested in the algorithm described here:
Donald B. Johnson, "Finding all the elementary circuits of a directed
graph", SIAM J. Comput vol. 4 n. 1 march 1975http://dutta.csc.ncsu.edu/csc791_spring07/wrap/circuits_johnson.pdf
The running time is O( (n+e)(c+1) ) where n=number of nodes, e=number of
edges, c=number of elementary circuits in the graph. However, as said above,
there can be an exponential number of elementary loops in the graph.I don't know if there are Octave implementations of the algorithm above.
Moreno.
--
Moreno Marzolla
EMail: address@hidden
WWW : http://www.moreno.marzolla.name/
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave
Hi Francesco & Paolo,
Definitely the '75 algorithm is worth to be checked. In case you want
to see my code (disclaimer: naive, and highly non-efficient
implementation) of the '68 paper you can get it from here
http://octave.svn.sf.net/viewvc/octave/trunk/octave-forge/main/geometry/devel/graphs/
Here a example of use:
% Create adjacency matrix (in any way you want. I use unvech from the
package general >= 1.2.2 to create a symmetric matrix)
v=round(rand(1,10)>0.4);
A=unvech(v);
[x y]=find(A==1);
i=sub2ind(size(A),x,y);
B=A;
B(i)=y;
Ac=graph2cell(A,'adj');
Bc=graph2cell(B,'varadj');
P=cellmatprod(Bc,Ac);
[P cycles]=simplepath(P);
As you can see even the interface is not the best.
If you re-implement or improve the code, please let us know.
Cheers,
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
2020-06-08 CAJ to PDF