Implementations of A* pathfinding algorithms for robotics applications, featuring standard A* with varying complexity levels and bidirectional A* for enhanced performance.
- Overview
- Features
- Requirements
- Installation
- Repository Structure
- Usage
- Algorithm Descriptions
- Visualizations
- Performance Considerations
- Advanced Topics
- Contributing
- License
This repository provides three distinct implementations of the A* pathfinding algorithm, designed for robotics path planning applications. Each implementation demonstrates different aspects of the algorithm, from basic concepts to advanced optimization strategies.
A* (A-star) is a graph traversal and pathfinding algorithm widely used in robotics, video games, and AI applications. It finds the shortest path between two points while avoiding obstacles by using a heuristic function to guide its search.
Core Concept:
f(n) = g(n) + h(n)
- g(n): Actual cost from start to node n
- h(n): Estimated cost from node n to goal (heuristic)
- f(n): Total estimated cost through node n
- Three Progressive Implementations: Simple maze, complex maze, and bidirectional search
- Real-time Visualization: Animated search process showing frontier expansion
- Optimized Performance: Batch rendering for smooth animation without slowdown
- Interactive Controls: ESC key for clean program exit
- Comprehensive Documentation: Extensively commented code explaining every step
- Flexible Configuration: Adjustable grid resolution, animation speed, and obstacle density
- Path Metrics: Automatic calculation of path length and waypoint count
Python 3.7+
numpy>=1.19.0
matplotlib>=3.3.0-
Clone the repository:
git clone https://github.com/Kiran1510/A-Star-Algorithm-for-Robotics-Path-Planning.git cd A-Star-Algorithm-for-Robotics-Path-Planning -
Install dependencies:
pip install numpy matplotlib
-
Run an implementation:
python A_Star.py # or python A_Star_Complex.py # or python Bidirectional_A_Star.py
A-Star-Algorithm-for-Robotics-Path-Planning/
├── A_Star.py # Basic A* with simple maze
├── A_Star_Complex.py # A* with dense, challenging maze
├── Bidirectional_A_Star.py # Dual-direction search implementation
├── LICENSE # MIT License
└── README.md # This file
- Purpose: Introduction to A* pathfinding concepts
- Environment: Simple maze with two interior walls
- Grid: 2.0m cell resolution
- Start: (10, 10)
- Goal: (50, 50)
- Best for: Learning the basics, understanding core algorithm
- Purpose: Demonstrates robustness in constrained environments
- Environment: Dense maze with 30+ obstacle elements
- Grid: 1.0m cell resolution for precise navigation
- Start: (10, 10)
- Goal: (140, 80)
- Features: Multiple wall segments, scattered pillars, narrow corridors
- Best for: Testing algorithm performance, seeing complex path planning
- Purpose: Enhanced performance through simultaneous exploration
- Environment: Random obstacle generation (configurable density)
- Grid: 60x60 with random obstacles
- Start: (1, 1) - bottom-left corner
- Goal: (59, 59) - top-right corner
- Optimization: ~2x faster than standard A* in open spaces
- Best for: Understanding advanced search strategies, performance optimization
Simply run any implementation:
python A_Star.pyThe visualization will open showing:
- Initial environment with obstacles
- Real-time search exploration
- Final path highlighted in red
grid_size = 2.0 # Larger = faster but less precise
grid_size = 1.0 # Smaller = slower but more accuratesx = 10.0 # Start X coordinate [meters]
sy = 10.0 # Start Y coordinate [meters]
gx = 50.0 # Goal X coordinate [meters]
gy = 50.0 # Goal Y coordinate [meters]robot_radius = 1.0 # Obstacle inflation radius [meters]animation_delay = 0.05 # Seconds between visualization updates
# 0.2 = Slow, educational viewing
# 0.05 = Smooth, balanced (default)
# 0.01 = Fast executionmain(obstacle_number=800) # ~22% density (default, good success rate)
main(obstacle_number=1200) # ~33% density (challenging)
main(obstacle_number=1500) # ~40% density (very difficult)While the program is running:
- ESC: Clean exit and close all windows
- Window Close Button: Standard close
Algorithm Steps:
- Initialize open set with start node (f = g + h)
- Select node with minimum f-value from open set
- If selected node is goal, reconstruct path and exit
- For each neighbor of selected node:
- Calculate tentative g-value
- If neighbor not in open set, add it
- If neighbor in open set but new path is cheaper, update it
- Move selected node to closed set
- Repeat from step 2
Heuristic Function: Euclidean distance
h(n) = √((x₂-x₁)² + (y₂-y₁)²)- Admissible (never overestimates)
- Optimal for 8-connected grid movement
Movement Model: 8-connected grid (like chess king)
- Cardinal moves (↑↓←→): cost = 1.0
- Diagonal moves (↗↘↖↙): cost = √2 ≈ 1.414
Key Optimizations:
- Batch rendering: Updates display every 50 nodes instead of every node
- Dictionary-based sets: O(1) lookup for open/closed membership
- Obstacle inflation: Single collision check per node
Algorithm Steps:
- Initialize two searches: forward (from start) and backward (from goal)
- Expand forward search toward backward search's best node
- Expand backward search toward forward search's best node
- Check if searches have met (any node in both closed sets)
- If met, reconstruct complete path by joining both segments
- Repeat from step 2
Heuristic Function: Manhattan distance
h(n) = |x₂-x₁| + |y₂-y₁|- Faster computation than Euclidean
- Still admissible for grid-based search
Performance Advantage:
- Each search explores roughly half the space
- Meeting point typically near the midpoint
- ~2x speedup in open or symmetric environments
Visualization: Updates every 5 iterations for smooth animation
Standard A (A_Star.py, A_Star_Complex.py)*
- 🟢 Green Circle: Start position
- 🔵 Blue X: Goal position
- 🟦 Cyan X: Explored nodes (search frontier)
- ⬛ Black Dot: Obstacle
- 🔴 Red Line: Final optimal path
Bidirectional A (Bidirectional_A_Star.py)*
- 🔺 Blue Triangle: Start position
- ⭐ Blue Star: Goal position
- 🟡 Yellow Circle: Forward search exploration (start→goal)
- 🟢 Green Circle: Backward search exploration (goal→start)
- ⬛ Black Square: Obstacle
- 🔴 Red Line: Complete path
- ❌ Red X: Blocking boundary (when no path exists)
Simple Maze (A_Star.py):
Path found! Total distance: 67.48 meters
Waypoints: 35
Exploration pattern: Focused beam toward goal
Complex Maze (A_Star_Complex.py):
Path found! Total distance: 165.82 meters
Waypoints: 112
Exploration pattern: Dense exploration through narrow corridors
Bidirectional (Bidirectional_A_Star.py):
Start: [1, 1] → Goal: [59, 59]
Diagonal distance: ~82.0 units
Meeting point: ~[30, 30] (approximate midpoint)
Path length: Varies with random obstacle distribution
Time Complexity: O(b^d)
- b = branching factor (8 for 8-connected grid)
- d = depth of optimal solution
Space Complexity: O(b^d)
- Storage for open and closed sets
-
Batch Rendering
- Standard A*: Updates every 50 nodes
- Bidirectional A*: Updates every 5 iterations
- Result: ~100x reduction in rendering overhead
-
Dictionary-Based Sets
- O(1) lookup time for node membership
- Much faster than list-based searching
-
Grid Resolution Trade-offs
- Coarse (2.0m): Faster, suitable for initial planning
- Fine (1.0m): Slower but more accurate paths
For faster execution:
ENABLE_VISUALIZATION = False # Disable animationFor educational viewing:
animation_delay = 0.2 # Slow down to watch behaviorFor large environments:
# Update visualization less frequently
if len(closed_set) % 100 == 0:
plt.plot(explored_x, explored_y, "xc", markersize=2)-
Weighted A (ε-A)**
heuristic_weight = 1.5 # > 1.0 for faster but suboptimal paths h = heuristic_weight * euclidean_distance(current, goal)
-
Jump Point Search (JPS)
- Skip intermediate nodes on straight paths
- 10-40x speedup for uniform grids
-
Theta*
- Any-angle paths (not restricted to grid)
- Smoother, more natural trajectories
-
Dynamic Replanning
- Integrate D* or D* Lite
- Handle moving obstacles
- Mobile Robotics: Warehouse navigation, autonomous delivery
- Autonomous Vehicles: Urban path planning with traffic
- Drones: Extend to 3D for aerial navigation
- Mars Rovers: NASA uses Field D* (based on A*)
- Video Games: NPC pathfinding, RTS unit movement
Contributions are welcome! Potential improvements:
- Additional heuristic functions (Chebyshev, Octile)
- 3D pathfinding extension
- Dynamic obstacle handling
- Path smoothing post-processing
- Integration with ROS
- Performance benchmarking suite
- Additional maze configurations
This project is licensed under the MIT License - see the LICENSE file for details.
Kiran
- Master's in Robotics - Northeastern University
- GitHub: @Kiran1510
- Original A* algorithm: Hart, Nilsson & Raphael (1968)
- Bidirectional search: Russell & Norvig, "AI: A Modern Approach"
- Visualization inspired by PythonRobotics repository
- Hart, P. E., Nilsson, N. J., & Raphael, B. (1968). "A Formal Basis for the Heuristic Determination of Minimum Cost Paths"
- Russell, S., & Norvig, P. "Artificial Intelligence: A Modern Approach" (4th Edition)
- LaValle, S. M. "Planning Algorithms" - Cambridge University Press
- Koenig, S., & Likhachev, M. "D* Lite" - AAAI 2002
- Very high obstacle density (>40%) may result in no path found
- Large grids (>200x200) may slow visualization
- Matplotlib window requires manual close on some systems
Last Updated: January 2026