1.1.1 • Published 4 years ago

eko-graph v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Graph

Table of Content

  1. Features
  2. Installation
  3. Basic usage
  4. Example
  5. API
  6. Tests
  7. License

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

Using NPM or YARN

# 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

PropertyDefaultDescription
maxStopundefinedThe 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

License

MIT

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago