bellman-short-path

Bellman-Ford's algorithm implentation by Node.js

Usage no npm install needed!

<script type="module">
  import bellmanShortPath from 'https://cdn.skypack.dev/bellman-short-path';
</script>

README

bellman-short-path

npm install bellman-short-path --save

Usage

Basic example:

const Graph = require('bellman-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', 2], ['C', 2]])); // Distance from  B->A can be different from A->B.
route.addNode('C', new Map([['D', 1]]));
route.addNode('D', new Map([['A', -1]]);

route.path('A', 'D'); // return => { cost:5 , path : [ 'A', 'B', 'C', 'D' ]}