Skip to content
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

Graph broken with cyclic dependencies #33

Closed
himanshisrivastava opened this issue Nov 25, 2019 · 2 comments · Fixed by #34
Closed

Graph broken with cyclic dependencies #33

himanshisrivastava opened this issue Nov 25, 2019 · 2 comments · Fixed by #34
Labels

Comments

@himanshisrivastava
Copy link

himanshisrivastava commented Nov 25, 2019

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
@jriecken
Copy link
Owner

jriecken commented Nov 29, 2019

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.

@jriecken jriecken added the bug label Nov 29, 2019
jriecken added a commit that referenced this issue Dec 3, 2019
Including when there are several disconnected subgraphs, one or more of them having a cycle.

Fixes #33
@jriecken
Copy link
Owner

jriecken commented Dec 3, 2019

Should be fixed in version 0.8.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants