l1-path-finder is a fast path planner for grids

Install

You can install l1-path-finder using :

> npm install l1-path-finder

It works great with !

Usage

Given a binary ndarray encoding a grid, calling l1-path-finder constructs a data structure for shortest path queries.

You can then query the planner by calling .search(), which computes the shortest path between a pair of points. That's it!

Example

var ndarray = require('ndarray')
var createPlanner = require('l1-path-finder')

//Create a maze as an ndarray
var maze = ndarray([
  0, 1, 0, 0, 0, 0, 0,
  0, 1, 0, 1, 0, 0, 0,
  0, 1, 0, 1, 1, 1, 0,
  0, 1, 0, 1, 0, 0, 0,
  0, 1, 0, 1, 0, 0, 0,
  0, 1, 0, 1, 0, 0, 0,
  0, 1, 0, 1, 0, 1, 1,
  0, 0, 0, 1, 0, 0, 0,
], [8, 7])

//Create path planner
var planner = createPlanner(maze)

//Find path
var path = []
var dist = planner.search(0,0,  7,6,  path)

//Log output
console.log('path length=', dist)
console.log('path = ', path)

Theory

l1-path-finder is based on sound computer science:

Click to interact

Benchmarks

l1-path-finder is also extremely fast in practice.

On the grid path planning challenge [4] data set, it outperforms all other JavaScript path planning libraries by orders of magnitude:


The JavaScript implementation of l1-path-finder is even competitive with state of the art native C++ codes.

The following chart is a comparison to the Dan Harabor's implementation of jump point search [5]:

To see for yourself, you can run a limited interactive benchmark right in your browser:

BENCHMARK

References

  1. K. Clarkson, S. Kapoor, P. Vaidya. (1987) "Rectilinear shortest paths through polygonal obstacles in O(n log2(n)) time" Proceedings of the third annual Symposium on Computational Geometry (SoCG).
  2. A. Goldberg, H. Kaplan, R. Werneck. (2007) "Better landmarks within reach" Lecture notes in computer science, Volume 4525.
  3. M. Fredman, R. Sedgewick, D. Sleator, R. Tarjan. (1986) "The pairing heap: A new form of self-adjusting heap" Algorithmica 1
  4. N. Sturtevant. (2012) "Benchmarks for grid-based path finding" Transactions on Computational Intelligence and AI in Games
  5. D. Harabor, A. Grastein. (2011) "Online graph pruning for pathfinding on grid maps" In Proceedings of the 25th National Conference on Artificial Intelligence (AAAI).
  6. A. Patel. (2015) "Amit Patel's path finding notes"
  7. 0fps blog post (COMING SOON)

Acknowledgements

Thanks to Amit Patel for many useful conversations on path finding. Also, Hugh S. Kennedy, Matt DesLauriers and Elija Insua for feedback on design.
© 2015 Mikola Lysenko | @mikolalysenko | 0fps.net