Informed search

Heuristics

Checks a heuristic on a graph problem: h(n) against the true cost h*(n), every edge for consistency, dominance and the maximum of two heuristics, and the paths A* tree search, A* graph search, and weighted A* return with it.

  • Lecture reference: Informed Search · slides 25–30
  • Lecture reference: Informed Search · slides 35–38

Problem 20 states · 23 edges

h(n)
Straight-line distance to Bucharest
C*
418 · Arad → Sibiu → Rimnicu Vilcea → Pitesti → Bucharest

Romania: straight-line distance. Arad to Bucharest with the straight-line distance to Bucharest as h. A straight line is never longer than the road, so h never overestimates; it is also consistent. A* tree and graph search both return Arad → Sibiu → Rimnicu Vilcea → Pitesti → Bucharest (418).

Lecture reference: Informed Search · slide 6
Edit graph

Admissibility and consistency

Admissible

Yes

h(n) ≤ h*(n) at all 20 states.

An admissible heuristic never overestimates the cost to reach the goal: h(n) ≤ h*(n) for every node n, where h*(n) is the true cost to reach the goal state from n. Theorem: if h(n) is admissible, A* is optimal.

Lecture reference: Informed Search · slide 25
Proof sketch

Consistent

Yes

h(n) ≤ c(n, n') + h(n') on all 46 edge directions.

cost(A to C) + h(C) ≥ h(A) for every edge, i.e. cost(A to C) ≥ h(A) − h(C): the real cost is at least the cost implied by the heuristic. Consistency is stronger than admissibility. Consequences: the f value along a path never decreases, and A* graph search is optimal.

Lecture reference: Informed Search · slide 28
Optimality of A*
A*Optimal if h isThis hReturned
Tree search no repeated-state detectionOptimal if h is admissible (and non-negative)This h: yesReturned 418 = C*
Graph search repeated-state detectionOptimal if h is consistentThis h: yesReturned 418 = C*

Consistency implies admissibility. In general, most natural admissible heuristics tend to be consistent, especially if they come from relaxed problems. Lecture reference: Informed Search · slide 29

h(n) and h*(n) one row per state

h(n), the true cost h*(n), and their difference for every state
Stateh(n)h*(n)h*(n) − h(n)
start
418 h(n) ≤ h*(n): 52 h(n) ≤ h*(n): 52
goal
0 h(n) ≤ h*(n): 0 h(n) ≤ h*(n): 0
239 h(n) ≤ h*(n): 79 h(n) ≤ h*(n): 79
359 h(n) ≤ h*(n): 117 h(n) ≤ h*(n): 117
269 h(n) ≤ h*(n): 108 h(n) ≤ h*(n): 108
211 h(n) ≤ h*(n): 35 h(n) ≤ h*(n): 35
90 h(n) ≤ h*(n): 13 h(n) ≤ h*(n): 13
183 h(n) ≤ h*(n): 32 h(n) ≤ h*(n): 32
319 h(n) ≤ h*(n): 93 h(n) ≤ h*(n): 93
504 h(n) ≤ h*(n): 260 h(n) ≤ h*(n): 260
434 h(n) ≤ h*(n): 193 h(n) ≤ h*(n): 193
406 h(n) ≤ h*(n): 172 h(n) ≤ h*(n): 172
429 h(n) ≤ h*(n): 49 h(n) ≤ h*(n): 49
101 h(n) ≤ h*(n): 1 h(n) ≤ h*(n): 1
198 h(n) ≤ h*(n): 5 h(n) ≤ h*(n): 5
278 h(n) ≤ h*(n): 25 h(n) ≤ h*(n): 25
536 h(n) ≤ h*(n): 207 h(n) ≤ h*(n): 207
85 h(n) ≤ h*(n): 5 h(n) ≤ h*(n): 5
227 h(n) ≤ h*(n): 28 h(n) ≤ h*(n): 28
493 h(n) ≤ h*(n): 119 h(n) ≤ h*(n): 119

h*(n) is the cost of a cheapest path from n to a goal (∞ when no goal can be reached). Changing h rewrites the h: lines of the graph text, so Copy link keeps the values. h = h* gives states that cannot reach a goal the largest finite h*, which keeps it consistent.

  • Admissible yes
  • Consistent yes
  • A* tree 418 = C*
  • A* graph 418 = C*

State space with h(n)

  • Goal state
  • Cheapest path (C* = 418)
  • h(n)

Click a state to select its row.

Consistency h(n) ≤ c(n, n') + h(n') on every edge direction

Consistency check per edge direction, failed checks first
n → n'c(n, n')h(n)h(n')h(n) − h(n')c ≥ h(n) − h(n')
→ 75366374−8holds
→ 753743668holds
→ 140366253113holds
→ 140253366−113holds
→ 11836632937holds
→ 118329366−37holds
→ 71374380−6holds
→ 713803746holds
→ 151380253127holds
→ 151253380−127holds
→ 11132924485holds
→ 111244329−85holds
→ 702442413holds
→ 70241244−3holds
→ 75241242−1holds
→ 752422411holds
→ 12024216082holds
→ 120160242−82holds
→ 9925317677holds
→ 99176253−77holds
→ 8025319360holds
→ 80193253−60holds
→ 9719310093holds
→ 97100193−93holds
→ 14619316033holds
→ 146160193−33holds
→ 13816010060holds
→ 138100160−60holds
→ 2111760176holds
→ 2110176−176holds
→ 1011000100holds
→ 1010100−100holds
→ 90077−77holds
→ 9077077holds
→ 85080−80holds
→ 8580080holds
→ 9880151−71holds
→ 981518071holds
→ 86151161−10holds
→ 8616115110holds
→ 14280199−119holds
→ 14219980119holds
→ 92199226−27holds
→ 9222619927holds
→ 87226234−8holds
→ 872342268holds

Each undirected edge is checked in both directions. A failed check means f can drop along that edge: f(n') = f(n) − (h(n) − h(n') − c(n, n')). Lecture reference: Informed Search · slide 28

A* with this h

Tree search

no repeated-state detection

Cost 418 Optimal

Arad → Sibiu → Rimnicu Vilcea → Pitesti → Bucharest

Expanded
5
Generated
16
Step through it in the search tool

Graph search

explored set and frontier check

Cost 418 Optimal

Arad → Sibiu → Rimnicu Vilcea → Pitesti → Bucharest

Expanded
5
Generated
16
Step through it in the search tool

Nodes taken off the frontier by A* tree search, by f(n) = g(n) + h(n)

f(n) < C* 5
  1. Arad 366 (g = 0, h = 366)
  2. Sibiu 393 (g = 140, h = 253)
  3. Rimnicu Vilcea 413 (g = 220, h = 193)
  4. Fagaras 415 (g = 239, h = 176)
  5. Pitesti 417 (g = 317, h = 100)
f(n) = C* 1
  1. Bucharest 418 (g = 418, h = 0)
f(n) > C* 0
none

A* is optimally efficient: no other tree-based algorithm that uses the same heuristic can expand fewer nodes and still be guaranteed to find the optimal solution. A* expands all nodes for which f(n) ≤ C*.

Lecture reference: Informed Search · slide 30

A* gone wrong?

Lecture reference: Informed Search · slide 27
Show answer

Dominance and combining

h1(n) ≥ h2(n) for all n and both are admissible: h1 dominates h2.

  • h1 admissible
  • h2 admissible
  • max admissible
A* tree search with each heuristic
HeuristicExpandedCost
h1 Straight-line distance to Bucharest5418
h2 h = 052418
max{h1, h2} the larger value at each state5418
h1, h2 and max{h1, h2} for every state
Stateh1(n)h1 against h2h2(n)max
Arad366 (larger)0 366
Bucharest00 0
Craiova160 (larger)0 160
Dobreta242 (larger)0 242
Eforie161 (larger)0 161
Fagaras176 (larger)0 176
Giurgiu77 (larger)0 77
Hirsova151 (larger)0 151
Iasi226 (larger)0 226
Lugoj244 (larger)0 244
Mehadia241 (larger)0 241
Neamt234 (larger)0 234
Oradea380 (larger)0 380
Pitesti100 (larger)0 100
Rimnicu Vilcea193 (larger)0 193
Sibiu253 (larger)0 253
Timisoara329 (larger)0 329
Urziceni80 (larger)0 80
Vaslui199 (larger)0 199
Zerind374 (larger)0 374

If h1 and h2 are both admissible and h2(n) ≥ h1(n) for all n, then h2 dominates h1. A* search expands every node with f(n) < C*, or h(n) < C* − g(n); therefore A* search with h1 will expand more nodes.

Lecture reference: Informed Search · slide 35

With a collection of admissible heuristics h1(n), …, hm(n), none of which dominates the others: h(n) = max{h1(n), …, hm(n)}.

Lecture reference: Informed Search · slide 37

Weighted A*

f(n) = g(n) + 2·h(n)
Weighted A*CostExpandedA* expanded
Tree search45035
Graph search45035

C* = 418, α · C* = 2 × 418 = 836. Tree: within α · C*Graph: within α · C*

h is admissible and consistent, so the slide’s bound applies to both searches: the solution costs at most α · C*.

Take an admissible heuristic, “inflate” it by a multiple α > 1, and then perform A* search as usual. Fewer nodes tend to get expanded, but the resulting solution may be suboptimal (its cost will be at most α times the cost of the optimal solution).

Lecture reference: Informed Search · slide 38