Artificial Intelligence/Informed Search
55 / 67

10/2021Artificial Intelligence

Informed Search

Navigating a robot through a grid maze with A-star and greedy best-first search, using Manhattan and Euclidean distance as admissible heuristics.

╌╌╌╌

Informed search uses a heuristic estimate of the cost remaining to the goal to decide which state to expand next, reaching the goal after touching far fewer states than blind search. This project drives a robot across a grid maze of obstacles to a target cell, comparing A* search against greedy best-first search.

Each frontier state is scored by

where is the cost already paid to reach and estimates the cost from to the goal. A-star always expands the state of lowest . Greedy search drops the term and expands by alone — quicker to commit, but with no account of the path so far it can settle for an expensive route.

A* scores each frontier node by f = g + h, the cost paid plus the estimate remaining, and expands the smallest. Edge labels are step costs; the accent route S-A-C-G is the optimal path the search returns.

On a grid the estimate is a distance to the goal cell. For four-connected movement, Manhattan distance

counts axis-aligned steps; when diagonal moves are allowed, Euclidean distance fits the true geometry. Both are admissible — never overestimating the real remaining cost — which is exactly the condition under which A-star returns an optimal path.

Two properties of a heuristic control what A* guarantees:

  • Admissible. at every node, where is the true remaining cost. The estimate never overshoots.
  • Consistent. across every edge — a triangle inequality on the estimate. Consistency implies admissibility, and it makes nondecreasing along any path, so A* settles each node's optimal the first time it expands it and never reopens one.

Admissibility is enough for optimality, and the argument is short. Let be the optimal cost and suppose a suboptimal goal with sits on the frontier. Some node on an optimal path is on the frontier too, and there

A* expands the smaller first, so it reaches — and eventually the true goal — before it would ever remove . Overestimating breaks this: an larger than can inflate a good node's past a bad goal's and let the bad goal out first.

Among admissible heuristics, larger is better. If everywhere, dominates , and A* with expands no more nodes than with : every node A* can safely skip under it also skips under . The pointwise maximum of two admissible heuristics is itself admissible and dominates both, which is why heuristics are often combined by taking their max.

Algorithm:A-Star(start,goal)\textsc{A-Star}(start, goal) — least-cost-first search on f=g+hf = g + h
  1. 1
    input: a start cell, a goal cell, a heuristic hh
  2. 2
    frontier \gets priority queue holding startstart with key h(start)h(start)
  3. 3
    g[start]0g[start] \gets 0
  4. 4
    while frontier is not empty do
  5. 5
    nn \gets remove the state of least key from frontier
  6. 6
    if n=goaln = goal then return the path traced back to startstart
  7. 7
    for each neighbor mm of nn do
  8. 8
    cg[n]+cost(n,m)c \gets g[n] + \operatorname{cost}(n, m)
  9. 9
    if mm is unseen or c<g[m]c < g[m] then
  10. 10
    g[m]cg[m] \gets c; set mm's parent to nn
  11. 11
    insert mm into frontier with key c+h(m)c + h(m)
  12. 12
    return failure

Greedy search often expands fewer states, since it heads straight at the goal, but it gives up optimality: a heuristic that points toward a dead end walks the robot into it. A-star pays for more expansions with a guarantee — under an admissible heuristic the first goal it removes from the frontier sits on a shortest path. Setting collapses A-star to uniform-cost search, and a sharper narrows the search toward the goal without breaking that guarantee.

A-star and greedy best-first, live on a random grid maze. Cells light up as the search visits them (green) and holds them on the frontier (yellow); the found route is traced in orange. A-star expands by g + h and always returns a shortest path; greedy chases h alone — watch it touch fewer cells but sometimes hand back a longer route. The note keeps score against the true shortest path.
A-star search
frontiervisitedpathwall

References

  1. Project repository
  2. Reference notes: Informed Search and A*
  3. Reference notes: Heuristic Functions and Memory-Bounded Search

╌╌ END ╌╌