Grid Search and Graph Planning
Once you have a clean 2D map — either a floorplan for a wheeled robot or a 2-joint C-space grid — the next question is simple: how does software actually find a path from Start to Goal without wandering around forever?
Core ideas covered in this module
- Occupancy grids & costmaps
- BFS, Dijkstra & A* heuristics
- Admissibility & search frontier
Turning a continuous floor into a checkerboard
Computers prefer discrete steps over infinite continuous rooms, so mobile robots slice the floor into a grid of small squares called an occupancy grid. Each cell holds a belief: open floor, solid wall, or unknown territory.
In real warehouse and home robots, you rarely want to hug walls at zero clearance. So we layer a costmap on top of the occupancy grid — inflating obstacles slightly and adding a soft penalty to cells right next to furniture so the planner naturally stays near the middle of hallways.
BFS, Dijkstra, and why A* feels so much smarter
With a grid in hand, three classic graph search algorithms show up everywhere:
- Breadth-First Search (BFS): expands outward in even rings like ripples in a pond. It finds the fewest-step path on an unweighted grid, but ignores movement costs and looks equally hard in the wrong direction.
- Dijkstra's Algorithm: expands the lowest total cost-so-far first. It handles variable terrain or wall-proximity costs cleanly, though it still searches blindly in every direction around the start.
- A* Search: keeps Dijkstra's exact cost-so-far g(n), then adds a guess h(n) — usually straight-line or Manhattan distance — for how far the goal still is. Sorting by f(n) = g(n) + h(n) pulls the search cone straight toward the goal.
Interactive lab
BFS, Dijkstra, A*, and RRT Pathfinding Visualizer
Canvas / SVG· LiveWhy the heuristic cannot lie too much
You might wonder: if adding a heuristic speeds things up, why not multiply h(n) by 10 to race straight for the goal? You can, and weighted A* often runs much faster — but you give up optimality.
A* only guarantees the true shortest path when its heuristic h(n) never overestimates the real remaining cost (called an admissible heuristic). Straight-line Euclidean distance never overestimates because you can never travel shorter than a crow flies. Once h(n) stays optimistic, A* explores far fewer cells than Dijkstra while still finding the exact optimal path.
The A* priority score
f(n) = g(n) + h(n) with 0 ≤ h(n) ≤ h*(n)
g(n) is the known cost paid from start to cell n, and h(n) is an admissible estimate of the remaining cost to the goal. Keeping h(n) ≤ true remaining cost h*(n) guarantees A* returns an optimal path.
On a U-shaped cul-de-sac pointing toward the goal, what happens to standard A* compared to a naive greedy search that only follows h(n)?
Grid planners like Nav2's Smac Planner (Hybrid A*) still power most autonomous mobile robots in warehouses and hospitals, extending 2D A* with heading angle θ so cars and forklifts don't try to slide sideways.
Hands-On Python Notebook
02 · Grid Search, Dijkstra & A* Heuristics Lab
Implement BFS, Dijkstra, and A* on 2D occupancy grids with obstacle costmaps and compare expanded node counts side-by-side.
Try this on your own inside the notebook
- Test an inadmissible (over-weighted) heuristic and compare path optimality
- Add soft obstacle inflation costs near walls
In Google Colab, use File → Save a copy in Drive to keep your own edits and notes. Or download the files directly:
uvx marimo edit --sandbox notebooks/course-3/02_grid_search_astar.pyWrap up this module
Saved automatically in your browser profile so you can pick up right where you left off.