You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I simply want to detect cycles in my graph, and in case I find them, I want to report which are the offending cycles.
I've never used QuikGraph but it seemed like it would be a good fit. I made basic unit tests to start testing it out, but I'm not being able to run DFS.
To Reproduce
Self-contained xUnit test code.
usingFluentAssertions;usingQuikGraph;usingQuikGraph.Algorithms;usingStateQLTest.helpers;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingXunit.Abstractions;namespaceStateQLTest{publicclassGraphCyclesTest:BaseTest{AdjacencyGraph<string,IEdge<string>>graph=newAdjacencyGraph<string,IEdge<string>>();stringa="a";stringb="b";stringc="c";publicGraphCyclesTest(ITestOutputHelperlogger):base(logger)// Simply assigns logger to a protected member `logger`.{}[Fact]publicvoidNoCyclesReturnsFalse(){graph.AddVertexRange(newList<string>{a,b,c});graph.AddEdge(newEdge<string>("a","b"));graph.AddEdge(newEdge<string>("a","c"));graph.AddEdge(newEdge<string>("b","c"));HasCycles(graph).Should().BeFalse();}[Fact]publicvoidWithCyclesReturnsTrue(){graph.AddVertexRange(newList<string>{a,b,c});graph.AddEdge(newEdge<string>("a","b"));graph.AddEdge(newEdge<string>("a","c"));graph.AddEdge(newEdge<string>("b","c"));graph.AddEdge(newEdge<string>("c","a"));// Forms a loop.HasCycles(graph).Should().BeTrue();}privateboolHasCycles<T>(QuikGraph.AdjacencyGraph<T,IEdge<T>>graph){IEnumerable<T>?roots=graph.Roots();if(roots==null)returnfalse;foreach(varrootinroots){vargetPaths=graph.TreeDepthFirstSearch(root);if(getPaths==null)continue;IEnumerable<IEdge<T>>paths;boolsuccess=getPaths(root,outpaths);if(!success)thrownewInvalidProgramException("Couldn't compute quikgraph paths!");if(paths==null)returnfalse;// TODO: if any path contains a repeated node, store that and return that collection of cycles at the end.logger.WriteLine(paths.ToString());}returnfalse;}}}
Expected behavior
Both tests should pass, but I get success==false, so I must be doing something wrong.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
AlbertoEAF
changed the title
Need help with finding cycles -- not sure I'm seeing a bug or misusing the API
Need help running Depth First Search -- doesn't seem to be working
Mar 22, 2023
AlbertoEAF
changed the title
Need help running Depth First Search -- doesn't seem to be working
[Question] running Depth First Search -- doesn't seem to be working
Mar 22, 2023
Describe the bug
I simply want to detect cycles in my graph, and in case I find them, I want to report which are the offending cycles.
I've never used QuikGraph but it seemed like it would be a good fit. I made basic unit tests to start testing it out, but I'm not being able to run DFS.
To Reproduce
Self-contained xUnit test code.
Expected behavior
Both tests should pass, but I get
success==false
, so I must be doing something wrong.Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: