README
Graph
Table of Content
Features
- Make on the weighted graph and the directed graph concept.
- Calculate the cost from given path
- Calculate the cheapest cost from the point to the another point
Installation
# NPM
$ npm install eko-graph --save
# YARN
$ yarn add eko-graph
Basic usage
'use strict';
const { Graph } = require('eko-graph');
const graph = new Graph();
// to add vertex and its neighbor and weight on the edge
graph.addAdjacency('AB1');
graph.addAdjacency('AC4');
console.log(graph.adjacency);
// { A: [{ val: 'B', weight: 1 }, { val: 'C', weight: 4 }] }
Example
To view the example, clone this repo and install dependencies
$ git clone git@github.com:JPooban/eko-graph.git
$ cd eko-graph
$ npm install
Then run the example
$ node ./example/get-delivery-cost.js
API
Get delivery cost
Calculate the cost from given route.
// graph.getDelivertCost(route);
const cost = graph.getDelivertCost([ 'A', 'B', 'E' ]); // -> 4
In the case of non existing route, it will throw an error with
No Such Route
message.
Get possible delivery route number
Calculate the number of possible delivery route that can be construct by the given conditions.
// graph.getPossibleDeliveryRoute(start, end, options);
const possibleNumber = graph.getPossibleDeliveryRoute('E', 'D', { maxStop: 4 }); // -> 4
Properties
Property | Default | Description |
---|---|---|
maxStop |
undefined |
The maximum stop of each path. (count the path which is length is less than or equal maxStop + 1 ) |
Get cheapest delivery cost
Calculate the cheapest delivery route between two vertex.
// graph.getCheapestCost(start, end);
const cheapestCost = graph.getCheapestCost('E', 'D'); // -> 9
Tests
To run unit test suite, must install the dependencies. Use Jest as the test framework.
# install dependencies
$ npm install
# run the unit test
$ npm run test