findCycles only finds longest cycle when there is some overlap
See original GitHub issueConsider this example:
g2 = new graphlib.Graph({directed: true});
g2.setNode("1");
g2.setNode("2");
g2.setNode("3");
g2.setEdge("1", "2");
g2.setEdge("2", "3");
g2.setEdge("3", "1");
graphlib.alg.findCycles(g2);
// [ [ '3', '2', '1' ] ]
g2.setNode("4");
g2.setEdge("3", "4");
g2.setEdge("4", "1");
graphlib.alg.findCycles(g2);
// [ [ '4', '3', '2', '1' ] ]
Surely the cycle [3, 2, 1] should also be found by the last statement?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:7
Top Results From Across the Web
Finding all cycles in undirected graphs - Stack Overflow
For an undirected graph the standard approach is to look for a so called cycle base : a set of simple cycles from...
Read more >Find cycles in an undirected graph - MATLAB Answers
It uses graph theoretic functions only. Here is its application to the data example that you provided. Each partitioned polygon is contained in...
Read more >Approximating the Longest Cycle Problem in Sparse Graphs
We first consider the problem of finding long cycles in 3-connected cubic graphs whose edges have weights $w_i\geq 0$. We find cycles of ......
Read more >FindCycle - Wolfram Language Documentation
FindCycle [g] finds a cycle in the graph g. FindCycle[g, k] finds a cycle of length at most k in the graph g....
Read more >Finding cycles in a directed Graph - Codeforces
Lets say the graph had 2 OVERLAPPING cycles, so answer should be 3 along with their lengths. We must find smaller as well...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looking at the source code, the findCycles() implementation is the following:
tarjan(g)
returns an array with all the strongly connected components of the graph We filter that array ,removing singleton arrays whose nodes have no self edges, and return it. So, the returned array is just the strongly connected components filtered.This falsely assumes that a strongly connected component contains only one cycle.
Finding all the simple cycles in a graph is a bit more complex, we need to run Johnson’s Algorithm I will try to implement it and open a pull request
This is a severe bug because “findCycles” simply does not return all cycles and users like me have a hard time to figure out why our projects break! Please fix this and until then, make clear in the wiki that it’s only “findSomeCycles” at the moment!