Informed Search Strategies
Source: Unit 1 §4
Informed search uses problem-specific knowledge beyond the problem definition, and that is the whole reason it beats blind search. In a graph whose nodes carry geometric coordinates, for instance, you can prefer the neighbour that is closest to the target by straight-line distance - information no uninformed strategy is allowed to look at.
Best-first search: the general framework
Best-first search selects a node using an evaluation function , which takes a node and returns a positive number. The node with the lowest is expanded first.
The implementation is identical to uniform-cost search except that the priority queue is ordered by instead of . The choice of is the strategy - greedy search and A* are the same code with two lines changed.
Most best-first algorithms build out of a heuristic function :
Heuristics are arbitrary, non-negative and problem-specific, with exactly one hard constraint.
If is a goal node, then . A heuristic that reports a non-zero distance at the goal breaks every optimality proof that follows.
Greedy best-first search
Greedy search expands whichever node looks closest to the goal, which means it throws away entirely:
The Romania example
Using , the straight-line distance to Bucharest:
| City | h_SLD | City | h_SLD |
|---|---|---|---|
| Arad | 366 | Rimnicu Vilcea | 193 |
| Timisoara | 329 | Fagaras | 176 |
| Zerind | 374 | Bucharest | 0 |
| Sibiu | 253 | Oradea | 380 |
- Not optimal. For Arad → Bucharest it expands no off-path node at all, which is a wonderful search cost, but the Sibiu → Fagaras route is 32 km longer than the route through Rimnicu Vilcea and Pitesti. At each step it grabs the node that looks closest.
- Not complete, even in a finite space, exactly like DFS. Going from Iasi to Fagaras, the heuristic recommends Neamt, a dead end; expanding Neamt puts Iasi back on the frontier, Iasi still looks closer than Vaslui, and the search loops forever.
| Criterion | Greedy best-first |
|---|---|
| Complete? | No, it can get stuck in loops. |
| Time | O(bᵐ), though a good heuristic improves this dramatically. |
| Space | O(bᵐ), it keeps all nodes in memory. |
| Optimal? | No. |
A* search
The most widely known best-first search, and the one to know cold. A* adds the cost already paid to the cost still estimated:
- - the path cost from start to , which is known and actual.
- - the estimated cost from to the goal.
- - the estimated cost of the cheapest solution through .
The algorithm is UCS with the queue ordered by . Provided meets the conditions below, A* is both complete and optimal.
Condition 1: admissibility
An admissible heuristic never overestimates the cost to reach the goal. Since is the true cost to , an admissible means never overestimates the true cost of a solution through . Admissible heuristics are optimistic: they believe the goal is closer than it really is.
Straight-line distance is the model example. The shortest path between two points is a straight line, so can never overestimate.
- Admissibility is what you need for tree search to be optimal.
- Consistency is what you need for graph search to be optimal.
Condition 2: consistency (monotonicity)
A heuristic is consistent if, for every node and every successor reached by action :
Consistency ⇒ admissibility. Consistency is the stricter requirement, so every consistent heuristic is admissible, and the converse is not true.
A* worked through
Label each node (name, g, f) where . Expand the lowest first,
and goal-test on pop.
A* balances the cost already spent, , against the cost estimated as remaining, . Note that A is reached with but scores , the same as D at : a cheap path so far and a pessimistic heuristic can tie with an expensive path and an optimistic one, which is exactly the trade the sum is there to make.
| Criterion | A* |
|---|---|
| Complete? | Yes, unless there are infinitely many nodes with f ≤ f(G). |
| Time | Exponential in general. |
| Space | Keeps all nodes in memory, which is the practical bottleneck. |
| Optimal? | Yes, with an admissible (tree) or consistent (graph) heuristic. |
The heuristic is the controller
Everything about A*'s efficiency is decided by the choice of .
- is admissible, and reduces A* to UCS. Correct, and usually inefficient.
- The higher is while staying admissible, the fewer nodes A expands.* More informed means less searching, so push up to the admissibility ceiling.
- 8-puzzle, weak heuristic: , the number of misplaced tiles. Admissible, but a poor estimate.
- 8-puzzle, better heuristic: , the sum of the Manhattan distances of the tiles from home, ignoring the other tiles.
A more accurate heuristic prunes more nodes but costs more to compute per node. The right is the one that minimises total time, not the one that minimises expansions.
Use with . A large over-weights the heuristic and makes the search greedier and faster; a small gives it a more breadth-first character. In games you usually want a good path now rather than the best path later, so slightly inflating - a base cost of 1.5 instead of 1, say - stops A* obsessing over marginally cheaper terrain.
Choosing a heuristic on a grid
| Grid and movement | Recommended heuristic |
|---|---|
| Square grid, 4 directions | Manhattan distance (L1) |
| Square grid, 8 directions | Diagonal distance (L∞) |
| Square grid, any direction | Euclidean distance (L2) |
| Hexagonal grid, 6 directions | Manhattan adapted to hex grids |
| Multiple goals | h′(x) = min(h₁(x), h₂(x), h₃(x), …) |