Skip to content

Interactive Python script that visualizes various algorithms

Notifications You must be signed in to change notification settings

con-fucius/algorithms-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Pathfinding Algorithm Simulation

Features

The simulation currently implements and visualizes the following pathfinding algorithms:

  • Breadth-First Search (BFS): Explores the maze layer by layer, guaranteeing the shortest path in terms of the number of steps.
  • Depth-First Search (DFS): Explores as far as possible along each branch before backtracking. It does not guarantee the shortest path.
  • Greedy Best-First Search: Uses a heuristic (Manhattan distance to the goal) to prioritize exploration. It's often fast but doesn't guarantee the shortest path.
  • A Search (A-Star): Combines the cost from the start (g_score) and a heuristic (Manhattan distance to the goal, h_score) to find the shortest path efficiently. The heuristic must be admissible (never overestimate the true cost).
  • Dijkstra's Algorithm: Explores based on the cumulative cost from the start node. Guarantees the shortest path in terms of cost (number of steps in this unweighted grid).

How to Run

Prerequisites

  • Python 3.x
  • NumPy
  • Matplotlib
    • Ensure you have a suitable backend for Matplotlib that supports interactive plots (e.g., Tkinter, which is often included with Python, or others like Qt5Agg).

These dependencies can typically be installed using pip:

pip install numpy matplotlib

Running the Simulation

  1. Clone this repository or download the 'pathfinding-algo-simulation.py' script.

  2. Navigate to the directory containing the script in your terminal.

  3. Execute the script using Python:

    python pathfinding-algo-simulation.py

This will open a window displaying the maze and a set of radio buttons to select the algorithm for simulation.

Future Improvements

UX Enhancements

  1. Maze Generation
  • Allow generating new random mazes.
  • Allow a user to define their own mazes (maybe by clicking or loading from a simple text format).
  1. Speed Control
  • Add a slider or input to control the animation speed ('interval' in 'FuncAnimation').
  1. Reset Button Add a dedicated "Reset Algorithm" button that clears the current algorithm's state (visited, frontier, path) and restarts it without needing to re-select it from the radio buttons. This would be more intuitive than the current implicit reset.
  2. Execution Allow a user to step through the algorithm one step at a time.

About

Interactive Python script that visualizes various algorithms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages