Giter Site home page Giter Site logo

gurknathe / pathfinding-algorithms Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 3.0 65.4 MB

A Python implementation and visualization of various pathfinding and graph search algorithms.

Home Page: https://gurknathe.github.io/Pathfinding-Algorithms/

License: GNU General Public License v3.0

Python 77.93% Shell 0.30% HTML 0.31% TypeScript 21.00% CSS 0.46%
graph-algorithms pathfinding a-star-algorithm b-star beam-search bellman-ford-algorithm best-first-search bidirectional-bfs breadth-first-search depth-first-search

pathfinding-algorithms's Introduction

Pathfinding/Graph Search Algorithms License: GPL 3.0

This is a Python (3.10+) implementation and visualization of various pathfinding algorithms.

There is also a web version of this at this hyperlink. However, there are a number of features that are missing including node-to-node updating. So, the final grid will display basically immediately after you click Run. Additionally, not every algorithm is implemented yet.

The graph used is a static, undirected, unweighted, strongly connected graph (aka, a grid that doesn't change while algorithm is running).

The visualization is implemented using PyGame. Credits to Tech With Tim.

A maze generator is implemented, it has at least one valid path from the start to end node. The implementation is based on this.

A* + Maze

See the explanations for the implemented algorithms here.

Warning: There is an issue with PyGame that can cause the program to crash. On my system running Linux Mint, the update display function causes a segmentation fault. Non-Windows users seem to be the group affected by this, so if you're using Windows, you should be fine.

Command line arguments

There are three optional command line arguments: width, # rows, algorithm type.

Disclaimer: Testing is done on default settings, there is no guarantee, as of now, that things work smoothly for different widths and rows.

width >= 2
rows >= 2
algorithm = astar, bfs, dfs, dijkstra, rand, yen [See Algorithms.py for full list]
./pathfinding.py <width> <# rows> <algorithm type>

Keydown Events

While an algorithm isn't running:

  • Press T to test algorithms
  • Press B to go to previous algorithm in list
  • Press N to go to next algorithm in list
  • Press Q to exit
  • Press C to clear grid
  • Press G to generate a new maze
  • Left Click to place Start, then End, then Obstacles
  • Right Click to remove Start, End, or Obstacles

After an algorithm has run:

  • W, Left Click, or Right Click to clear the Algorithm Mark-up

While an algorithm is running:

  • Press S key to stop the algorithm

Testing

The testing function runs every implemented algorithm for the current grid. It outputs the time it took to run the algorithm and the number of node checks while running. The results are written into a CSV file, which can be found in the main/testing/results directory. An example output is given for a randomly generated maze, with default settings.

The testing will take longer as the visitable nodes increases. For my system, and a randomly generated maze on default settings, it takes ~4 minutes to run and save the data. The Floyd-Warshall algorithm takes up the most time and can vary significantly in its execution time (e.g., most of the time I get a run time of ~260 seconds where as of writing this I record a run time of ~670 seconds).

Node Types

  • Start: where the search algorithm will start
  • End: where the search algorithm is trying to get to
  • Obstacle: a position the algorithms avoid
  • Check/Uncheck: markup for visualizing the algorithm
  • Path: markup for visualizing the found path
  • Default: a position that can be traversed

Algorithm Progress

Currently implemented algorithms (25/25):

- A*
- Beam Search
- Bellman Ford's Algorithm
- Best First Search
- Bidirectional A*
- Bidirectional search
- Breadth First Search (BFS)
- B*
- Depth First Search (DFS)
- Dijkstra's Algorithms
- Fast Marching Method (FMM)
- Flood Fill Algorithm
- Floyd-Warshall's algorithm
- Fringe search
- Greedy Best First Search (GBFS)
- Greedy Best Line Search (GBLS)
- Iterative Deepening (IDA*)
- Iterative Deepening DFS (IDDFS)
- Jump Point Search (JPS)
- Lexicographic BFS (LBFS)
- Lifelong Planning A* (LPA*)
- Random Walk
- Random Walk with LIFO Queue
- Shortest Path Faster Algorithm (SPFA)
- Theta*

Currently looking at:

- None

Planned algorithms (Going to look at them):

- None

Possible incorrectly implemented algorithms:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.