Skip to content

Using Dijkstra and A*s algorithm, find the shortest distance between two nodes. A lightweight javascript package built to handle that using algorithmic approach

License

Notifications You must be signed in to change notification settings

Ojochogwu866/pathfindr

Repository files navigation

Pathfindr

A high-performance TypeScript pathfinding library implementing multiple algorithms including Dijkstra and A* (A-star).

Features

  • Multiple pathfinding algorithms:
    • Dijkstra's Algorithm
    • A* (A-starAlgorithm
  • Flexible graph representation
  • Type-safe with full TypeScript support
  • Comprehensive test coverage
  • Performance benchmarking tools
  • Detailed documentation

Installation

npm install pathfindr

Quick Start

import { Graph, AStar, Dijkstra } from 'pathfindr';

// Create a graph
const graph = new Graph();

// Add some edges
graph.addEdge('A', 'B', 4);
graph.addEdge('A', 'C', 2);
graph.addEdge('B', 'D', 3);
graph.addEdge('C', 'D', 1);

// Find shortest path using Dijkstra's algorithm
const path = Dijkstra.findShortestPath(graph, 'A', 'D');
console.log(path.path); // ['A', 'C', 'D']
console.log(path.totalCost); // 3

Documentation

For detailed documentation, see:

Advanced Usage

The library supports custom configurations for pathfinding:

const options = {
    maxIterations: 1000,
    heuristic: (a: string, b: string=> {
        // Custom heuristic function for A*
        return 0;
    },
};

const path = AStar.findShortestPath(graph, 'start', 'end', options);

Performance

Benchmarks comparing different algorithms are available in the benchmarks directory. Run them using:

npm run benchmark

Contributing

We welcome contributions! Please see our [Contributing Guide](./docs/contributing.mdfor details.

License

MIT

Support

  • Open an issue for bugs/feature requests
  • Star the repo if you find it useful!

Repository: https://github.com/Ojochogwu866/pathfindr

About

Using Dijkstra and A*s algorithm, find the shortest distance between two nodes. A lightweight javascript package built to handle that using algorithmic approach

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published