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
I have a graph with cycle on the root node as shown below:
1 --> 2 --> 3 --> 1
Now when I try to print the order of graph (graph.overallOrder()), this returns empty.
But it works fine with below scenario
0 -->1 --> 2 --> 3 --> 1
Here is the code:
const GRAPH = require('dependency-graph').DepGraph;
// Working
let a = new GRAPH({ circular: true });
a.addNode(0);
a.addNode(1);
a.addNode(2);
a.addNode(3);
a.addDependency(0,1);
a.addDependency(1,2);
a.addDependency(2,3);
a.addDependency(3,1);
console.log(a.overallOrder()); // returns correct order
/*
**************************
*/
// Not working
let a = new GRAPH({ circular: true });
a.addNode(1);
a.addNode(2);
a.addNode(3);
a.addDependency(1,2);
a.addDependency(2,3);
a.addDependency(3,1);
console.log(a.overallOrder()); // returns empty array
The text was updated successfully, but these errors were encountered:
I'll take a look when I get a bit of time - I think it's because there are no clear starting points (nodes with nothing depending on them) to run the DFS from.
Currently the circular option just suppresses the error that happens when a cycle is detected. A true topological ordering (what overallOrder does) is really only possible when the graph is acyclic.
That being said - I can probably make it return some ordering in this case when circular is true) rather than an empty array.
I have a graph with cycle on the root node as shown below:
1 --> 2 --> 3 --> 1
Now when I try to print the order of graph (graph.overallOrder()), this returns empty.
But it works fine with below scenario
0 -->1 --> 2 --> 3 --> 1
Here is the code:
The text was updated successfully, but these errors were encountered: