All Projects → albertorestifo → Node Dijkstra

albertorestifo / Node Dijkstra

Licence: mit
A NodeJS implementation of Dijkstra's algorithm

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Dijkstra

LightOSM.jl
A Julia package for downloading and analysing geospatial data from OpenStreetMap APIs.
Stars: ✭ 32 (-76.3%)
Mutual labels:  dijkstra
Algods
Implementation of Algorithms and Data Structures, Problems and Solutions
Stars: ✭ 3,295 (+2340.74%)
Mutual labels:  dijkstra
Algorithms
A collection of algorithms and data structures
Stars: ✭ 11,553 (+8457.78%)
Mutual labels:  dijkstra
Pathfinder
A pathfinder visualizer in Flutter. Create mazes, generate random walls, or draw your own walls and see the pathfinding algorithms in action
Stars: ✭ 14 (-89.63%)
Mutual labels:  dijkstra
Graphhopper
Open source routing engine for OpenStreetMap. Use it as Java library or standalone web server.
Stars: ✭ 3,457 (+2460.74%)
Mutual labels:  dijkstra
Matlabrobotics
MATLAB sample codes for mobile robot navigation
Stars: ✭ 332 (+145.93%)
Mutual labels:  dijkstra
coursera robotics
Contains coursera robotics specialization assignment codes
Stars: ✭ 65 (-51.85%)
Mutual labels:  dijkstra
Dijkstra
Fastest golang Dijkstra path finder
Stars: ✭ 107 (-20.74%)
Mutual labels:  dijkstra
Hipster
Hipster4j is a lightweight and powerful heuristic search library for Java and Android. It contains common, fully customizable algorithms such as Dijkstra, A* (A-Star), DFS, BFS, Bellman-Ford and more.
Stars: ✭ 301 (+122.96%)
Mutual labels:  dijkstra
Path planning
This repository contains path planning algorithms in C++ for a grid based search.
Stars: ✭ 70 (-48.15%)
Mutual labels:  dijkstra
Dijkstra.NET
Graph processing library
Stars: ✭ 92 (-31.85%)
Mutual labels:  dijkstra
unity-dijkstras-pathfinding
Dijkstra's Pathfinding Algorithm Unity Implementation. (Not being maintained by me, it is just an experiment.)
Stars: ✭ 80 (-40.74%)
Mutual labels:  dijkstra
Competitive Programming Repository
Competitive Programming templates that I used during the past few years.
Stars: ✭ 367 (+171.85%)
Mutual labels:  dijkstra
Graph-Theory
The Repository is All about the Graph Algorithms. I am Still Working On it. I am trying to Note down all the variations of Popular graph Algorithms. I am also keeping the solution to the problems of Different Online Judges according to the topic. I hope you can find it useful.
Stars: ✭ 16 (-88.15%)
Mutual labels:  dijkstra
Erdos
modular and modern graph-theory algorithms framework in Java
Stars: ✭ 104 (-22.96%)
Mutual labels:  dijkstra
mahjong
开源中文分词工具包,中文分词Web API,Lucene中文分词,中英文混合分词
Stars: ✭ 40 (-70.37%)
Mutual labels:  dijkstra
Pathfinding
Pathfinding library for rust
Stars: ✭ 324 (+140%)
Mutual labels:  dijkstra
Java Ds Algorithms
Data Structures and Algorithms in Java
Stars: ✭ 125 (-7.41%)
Mutual labels:  dijkstra
Valhalla
Open Source Routing Engine for OpenStreetMap
Stars: ✭ 1,794 (+1228.89%)
Mutual labels:  dijkstra
Dijkstra Cartography
Using Dijkstra's algorithm ("finding the shortest paths between nodes in a graph") to draw maps 🌍.
Stars: ✭ 1,112 (+723.7%)
Mutual labels:  dijkstra

node-dijkstra

Build Status codecov.io Dependency Status

Fast JavaScript implementation of the Dijkstra's shortest path problem for NodeJS

Installation

Since version 2 this plugin uses some ES6 features. You can run the latest version on NodeJS v4.0.0 or newer

npm install node-dijkstra --save

NodeJS prior v4.0.0

On versions of NodeJS prior v4.0.0, although less performant, it's safe to use the version 1.1.3 that you can install as follows:

npm install [email protected] --save

You can then refer to the v1.1.3 documentation

Usage

Basic example:

const Graph = require('node-dijkstra')

const route = new Graph()

route.addNode('A', { B:1 })
route.addNode('B', { A:1, C:2, D: 4 })
route.addNode('C', { B:2, D:1 })
route.addNode('D', { C:1, B:4 })

route.path('A', 'D') // => [ 'A', 'B', 'C', 'D' ]

API

Graph([nodes])

Parameters

  • Object|Map nodes optional: Initial nodes graph.

A nodes graph must follow this structure:

{
  node: {
    neighbor: cost Number
  }
}
{
  'A': {
    'B': 1
  },
  'B': {
    'A': 1,
    'C': 2,
    'D': 4
  }
}

Example

const route = new Graph()

// or with pre-populated graph
const route = new Graph({
  'A': { 'B': 1 },
  'B': { 'A': 1, 'C': 2, 'D': 4 }
})

It's possible to pass the constructor a deep Map. This allows using numbers as keys for the nodes.

const graph = new Map()

const a = new Map()
a.set('B', 1)

const b = new Map()
b.set('A', 1)
b.set('C', 2)
b.set('D', 4)

graph.set('A', a)
graph.set('B', b);

const route = new Graph(graph)

Graph#addNode(name, edges)

Add a node to the nodes graph

Parameters

  • String name: name of the node
  • Object|Map edges: object or Map containing the name of the neighboring nodes and their cost

Returns

Returns this allowing chained calls.

const route = new Graph()

route.addNode('A', { B: 1 })

// chaining is possible
route.addNode('B', { A: 1 }).addNode('C', { A: 3 });

// passing a Map directly is possible
const c = new Map()
c.set('A', 4)

route.addNode('C', c);

Graph#removeNode(name)

Removes a node and all its references from the graph

Parameters

  • String name: name of the node to remove

Returns

Returns this allowing chained calls.

const route = new Graph({
  a: { b: 3, c: 10 },
  b: { a: 5, c: 2 },
  c: { b: 1 },
});

route.removeNode('c');
// => The graph now is:
// {
//   a: { b: 3 },
//   b: { a: 5 },
// }

Graph#path(start, goal [, options])

Parameters

  • String start: Name of the starting node
  • String goal: Name of out goal node
  • Object options optional: Addittional options:
    • Boolean trim, default false: If set to true, the result won't include the start and goal nodes
    • Boolean reverse, default false: If set to true, the result will be in reverse order, from goal to start
    • Boolean cost, default false: If set to true, an object will be returned with the following keys:
      • Array path: Computed path (subject to other options)
      • Number cost: Total cost for the found path
    • Array avoid, default []: Nodes to be avoided

Returns

If options.cost is false (default behaviour) an Array will be returned, containing the name of the crossed nodes. By default it will be ordered from start to goal, and those nodes will also be included. This behaviour can be changes with options.trim and options.reverse (see above)

If options.cost is true, an Object with keys path and cost will be returned. path follows the same rules as above and cost is the total cost of the found route between nodes.

When to route can be found, the path will be set to null.

const Graph = require('node-dijkstra')

const route = new Graph()

route.addNode('A', { B: 1 })
route.addNode('B', { A: 1, C: 2, D: 4 })
route.addNode('C', { B: 2, D: 1 })
route.addNode('D', { C: 1, B: 4 })

route.path('A', 'D') // => ['A', 'B', 'C', 'D']

// trimmed
route.path('A', 'D', { trim: true }) // => [B', 'C']

// reversed
route.path('A', 'D', { reverse: true }) // => ['D', 'C', 'B', 'A']

// include the cost
route.path('A', 'D', { cost: true })
// => {
//       path: [ 'A', 'B', 'C', 'D' ],
//       cost: 4
//    }

Upgrading from v1

  • The v2 release in not compatible with NodeJS prior to the version 4.0
  • The method Graph#shortestPath has been deprecated, use Graph#path instead
  • The method Graph#addVertex has been deprecated, use Graph#addNode instead

Testing

npm test

js-standard-style

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].