js-graph-algorithms icon indicating copy to clipboard operation
js-graph-algorithms copied to clipboard

BellmanFord and Dijkstra not working with undirected graphs.

Open oschakravarthi opened this issue 6 years ago • 2 comments

var g = new jsgraphs.WeightedGraph(2); g.addEdge(new jsgraphs.Edge(0, 1, 5.0)); var dijkstra = new jsgraphs.Dijkstra(g, 0); var has0To1 = idijkstra.hasPathTo(1); // True.. as expected

    dijkstra1 = new jsgraphs.Dijkstra(g, 1);
    var has1To0 = idijkstra.hasPathTo(0); //It is returning false. But it should return true as the graph is a Undirected graph

oschakravarthi avatar Nov 26 '18 04:11 oschakravarthi

Hi oschakravarthi,

I can not reproduce your problem. For me the hasPathTo function returns true in both cases. Though I had to change your 4th line of code (and in the code block), as it says idijkstra, instead of dijkstra (as declared).

So this code prints true two times on my machine:

const jsgraphs = require('js-graph-algorithms');

var g = new jsgraphs.WeightedGraph(2); 
g.addEdge(new jsgraphs.Edge(0, 1, 5.0));
var dijkstra = new jsgraphs.Dijkstra(g, 0);
var has0To1 = dijkstra.hasPathTo(1); 

console.log(has0To1); // true

dijkstra1 = new jsgraphs.Dijkstra(g, 1);
var has1To0 = dijkstra.hasPathTo(0);

console.log(has1To0); //true

I suggest to close this issue.

Greetings, sp1r1t

sp1r1t avatar Jul 21 '19 15:07 sp1r1t