Skip to content

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

License

Notifications You must be signed in to change notification settings

syncblob/Pathfinding-Algorithms

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pathfinding/Graph Search Algorithms License: GPL 3.0

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

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.

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.

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 (19/30):

- A*
- Beam Search
- Bellman Ford's Algorithm
- Best First Search
- Bidirectional search
- Branch & Bound
- Breadth First Search (BFS)
- B*
- Depth First Search (DFS)
- Dijkstra's Algorithms
- Floyd-Warshall's algorithm
- Greedy Best First Search (GBFS)
- Greedy Best Line Search (GBLS)
- Iterative Deepening (IDA*)
- Iterative Deepening DFS (IDDFS)
- Jump Point Search (JPS)
- Lexicographic BFS
- Random Walk
- Theta*

Currently looking at:

- None

Planned algorithms (Going to look at them):

- Fast Iterative Method
- Fast Marching Method
- Fast Sweeping Method
- Fringe search

- Johnson's

- Kruskal's

- Lifelong Planning A* (LPA*)

- SMA*
- SUB

- Viterbi algorithm

- Yen's k-Shortest Paths

Possible incorrectly implemented algorithms:

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.5%
  • Shell 0.5%