-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graphs: isCyclic Digraph
sometimes fails to detect cycles
#3626
Comments
This fixes the detection of cycles in directed graphs (see issue Macaulay2#3626) by not relying on the numbers from DFS but by attempting a topological sort. It succeeds if and only if the graph is acyclic. This reuses existing code as much as possible. Also added tests that document previous bugs which are now fixed.
This fixes the detection of cycles in directed graphs (see issue Macaulay2#3626) by not relying on the numbers from DFS but by attempting a topological sort. It succeeds if and only if the graph is acyclic. This reuses existing code as much as possible. Also added tests that document previous bugs which are now fixed.
The implementation of E = {{1,3},{1,4},{3,2},{4,3}};
-- The two hash tables are equal:
print depthFirstSearch(digraph(E)); -- acyclic
print depthFirstSearch(digraph(E|{{2,4}})); -- cyclic Here, the edge The |
The
Graphs
package has a methodisCyclic
to detect whether aDigraph
contains a directed cycle. It often works:But on other small examples, it fails, reporting a graph as acyclic when it has a cycle
isCyclic digraph({{1,3},{1,4},{2,4},{3,2},{4,3}}) --> false (incorrect: 2 -> 4 -> 3 -> 2)
The text was updated successfully, but these errors were encountered: