dijkstra-short-path
v1.0.3
Published
Dijkstra's algorithm implentation by Node.js
Downloads
6
Maintainers
Readme
dijkstra-short-path
npm install dijkstra-short-path --save
Usage
Basic example:
const Graph = require('dijkstra-short-path');
const route = new Graph();
route.addNode('A', new Map([['B', 2], ['C', 5]])); // Distance list should be Map
route.addNode('B', new Map([['A', 1], ['C', 2]])); // Distance from B->A can be different from A->B.
route.addNode('C', new Map([['D', 1]]));
route.path('A', 'D'); // return => { cost:5 , path : [ 'A', 'B', 'C', 'D' ]}