fkling / JSNetworkX

Build, process and analyze graphs in JavaScript (port of NetworkX)
https://felix-kling.de/jsnetworkx/
Other
757 stars 185 forks source link

jsnx.allPairsDijkstraPath fails with complex node types #57

Open darendt opened 8 years ago

darendt commented 8 years ago

The following code will work when nodes are primitive objects, but not when complex objects.

function test(p) {
    var G = new jsnx.Graph();
    G.addStar(p, {weight: 1.0});
    return jsnx.allPairsDijkstraPath(G)
}

test([1,2,3,4]); // works
test([{name: "cat"},{name: "dog"},{name: "mouse"}]); // fails
test([[0,0],[0,1],[1,0]]); // fails

The error message is

Uncaught TypeError: Cannot read property 'toString' of undefined(…) n @ jsnetworkx.js:1 d @ jsnetworkx.js:3 s @ jsnetworkx.js:3 b @ jsnetworkx.js:3

Note, that the code will work when allPairsDijkstraPath is replaced with allPairsShortestPath.