1.1.1 • Published 5 years ago
eko-graph v1.1.1
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-graphBasic 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 installThen run the example
$ node ./example/get-delivery-cost.jsAPI
Get delivery cost
Calculate the cost from given route.
// graph.getDelivertCost(route);
const cost = graph.getDelivertCost([ 'A', 'B', 'E' ]); // -> 4In the case of non existing route, it will throw an error with
No Such Routemessage.
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 }); // -> 4Properties
| 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'); // -> 9Tests
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