简体   繁体   中英

Detect cycles in undirected graph using quick graph

is there anyway to detect all the cycles in an undirected graph generated with quick graph and print the list of cycles. I "googled" a little bit and I came to know that cycles in a graph can be detected using "Depth First Search Algorithm". I then tried something like this:

var g = new UndirectedGraph<int, TaggedUndirectedEdge<int, int>>();

var e1 = new TaggedUndirectedEdge<int, int>(1, 2, 57);//dem(1, 2, 57).
var e2 = new TaggedUndirectedEdge<int, int>(1, 4, 65);//dem(1, 4, 65).
var e3 = new TaggedUndirectedEdge<int, int>(2, 3, 155);//dem(2, 3, 155). 
var e4 = new TaggedUndirectedEdge<int, int>(2, 4, 129);//dem(2, 4, 129).
var e5 = new TaggedUndirectedEdge<int, int>(3, 4, 78);// dem(3, 4, 78).
var e6 = new TaggedUndirectedEdge<int, int>(3, 5, 200);// dem(3, 5, 200).

g.AddVerticesAndEdge(e1);
g.AddVerticesAndEdge(e2);
g.AddVerticesAndEdge(e3);
g.AddVerticesAndEdge(e4);
g.AddVerticesAndEdge(e5);
g.AddVerticesAndEdge(e6);

var dfs = new UndirectedDepthFirstSearchAlgorithm<int, TaggedUndirectedEdge<int, int>>(g);

dfs.Compute();

Now I am looking for a way to print the cycles. (I am not sure if my code is correct this is the first time I deal with quick graph, the first time I even deal with graph in general).

Thank you for your help.

There is a test project in the QuickGraph source, where you can find sample code of the QuickGraph methods. There are also a few implementations of DFS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM