Artificial Intelligence
Informed search methods
2
In which we see how information about
the state space can prevent algorithms
from blundering about in the dark.
3
Uninformed vs. Informed Search
• Uninformed search strategies
– Find solutions to problems by systematically
generating new states and testing for goal
– Most are incredibly inefficient
• Informed search strategies
– Use problem-specific knowledge
– Find solutions more efficiently
4
Informed Search
• Informed search strategy
– One that uses problem-specific knowledge beyond the problem definition itself
• General approach is called “Best First”search
– Node selected for expansion based on an evaluation function
• Measuring a distance to goal
– Node with lowest evaluation is selected
5
Techniques
• Best-first search
– Expand “minimum cost” nodes first
– Greedy search
• Minimize estimated cost to reach goal
– A* search
• Estimated total costs through node n to goal:
(actual cost to reach n) + (estimated cost from n to goal)
Best-First Search Methods
6
7
Best-First Search
• Try to expand node that is “closest” to goal
– Use evaluation function to estimate how desirable
• Open set
– Priority queue implementation
– Insert expanded nodes in decreasing order of
desirability (most desirable first)
• Special cases
– Greedy search: expand node closest to goal
– A* search: expand node on least-cost solution path
8
Greedy Search
• Simplest best-first search strategy
• Minimize estimated cost to reach goal
• Heuristic function h(n)
– Estimate of cost from node n to goal
• Require h(n) = 0 if n is goal
– e.g., For a road map, hSLD(n) = straight-line distance from city n to Bucharest
• Greedy search expands the node that appears to be closest to the goal
– Takes the “biggest bite” out of remaining cost to reach goal• Each step tries to get as close to goal as possible
– Though, will not consider if its action will be the best in the long run
9
Romania Step Costs in km
Oradea
Zerind
Arad
Timisoara
Lugoj
Mehadia
DebretaCraiova
Sibiu
Rimnicu Vilcea
Fagaras
Pitesti
Bucharest
Giurgiu Eforie
Urziceni
Hirsova
Vaslui
Iasi
Neamt
75
71
118
111
70
75
151
140 99
80
146
97
138
211
101
90
85
86
98
142
92
87
120
10
Straight-Line Distance to BucharestArad 366
Bucharest 0
Craiova 160
Dobreta 242
Eforie 161
Fagaras 176
Giurgiu 77
Hirsova 151
Iasi 226
Lugoj 244
Mehadia 241
Neamt 234
Oradea 380
Pitesti 100
Rimnicu Vilcea 193
Sibiu 253
Timisoara 329
Urziceni 80
Vaslui 199
Zerind 374
11
Greedy Search Example: Romania
Arad
366
Open = { Arad(366) }
12
Greedy Search Example: Romania
Zerind Timisoara
Arad
Sibu
366
374 253 329
Open = { Sibu(253), Timisoara(329), Zerind(374) }
13
Greedy Search Example: Romania
Rimnicu
VilceaArad Oradea
Zerind Timisoara
Arad
Sibu
Fagaras
366
374 253 329
366 380 176 193
Open = { Fagaras(176), RimnicuVilcea(193), Timisoara(329), Arad(366), Zerind(374), Oradea(380) }
14
Greedy Search Example: Romania
BucharestSibiu
Rimnicu
VilceaArad Oradea
Zerind Timisoara
Arad
Sibu
Fagaras
366
374 253 329
366 380 176 193
253 0
Open = { Bucharest(0), Fagaras(176), RimnicuVilcea(193), Sibu(253), Timisoara(329), Arad(366), Zerind(374), Oradea(380) }
15
Greedy Search Example: Romania
BucharestSibiu
Rimnicu
VilceaArad Oradea
Zerind Timisoara
Arad
Sibu
Fagaras
366
374 253 329
366 380 176 193
253 0
16
Properties of Greedy Search
• Not complete (can be bad)
– Can get stuck in loops
• Go from Iasi to Fagaras:
Iasi Neamt Iasi Neamt (only 1 link)
– Complete if check for repeated states
• Time (can be bad)
– O(bm), m=maximum depth (worst case, like DFS)
• Space (can be bad)
– O(bm), keeps all nodes in memory (worst case)
• Not optimal (can be bad)
– Heuristic is an estimate
But a good heuristic can give dramatic improvement!
17
A* Search• Minimizes total estimated path cost
• Avoids expanding paths already expensive
• Evaluation function f(n) = g(n) + h(n)
– Actual cost to reach node n so far g(n)
– Estimated cost from n to goal h(n)
– Estimated total cost through n to goal
f(n) = g(n) + h(n)
– A* search uses admissible heuristic
– i.e., h(n) h*(n) where h*(n) is true cost from n
to goal
– e.g., hSLD(n) never overestimates actual distance
18
A* Search Example: Romania
Arad
366
g(n): cost so far
f(n)=g(n)+h(n) = cost so far + estimated cost to goal
Open = { Arad(366) }
19
A* Search Example: Romania
Zerind Timisoara
Arad
Sibu
366
449 393 447
75
140 118
g(n): cost so far
f(n)=g(n)+h(n) = cost so far + estimated cost to goal
Open = { Sibu(393),
Timisoara(447), Zerind(449) }
f(Zerind)=75 + 374=449
20
A* Search Example: Romania
Arad Oradea
Zerind Timisoara
Arad
Sibu
Fagaras
366
449 393 447
646 671 415 413
Rimnicu
Vilcea
75
140 118
140 151 99 80
g(n): cost so far
f(n)=g(n)+h(n) = cost so far + estimated cost to goal
Open = { RimnicuVilcea(413),
Fagaras(415), Timisoara(447),
Zerind(449), Arad(646),
Oradea(671) }
f(Fagaras)=(140+99) + 176=415
21
A* Search Example: Romania
Arad Oradea
Zerind Timisoara
Arad
Sibu
Fagaras
366
449 393 447
646 671 415 413
Craiova Sibiu
526 417 553
Rimnicu
Vilcea
Pitesti
75
140 118
140 151 99 80
146 97
80
g(n): cost so far
f(n)=g(n)+h(n) = cost so far + estimated cost to goal
Open = { Fagaras(415), Pitesti(417),
Timisoara(447), Zerind(449),
Craiova(526), Sibu(553), Arad(646),
Oradea(671) }
22
A* Search Example: Romania
BucharestSibiu
Arad Oradea
Zerind Timisoara
Arad
Sibu
Fagaras
366
449 393 447
646 671 415 413
591 450
Craiova Sibiu
526 417 553
Rimnicu
Vilcea
Pitesti
75
140 118
140 151 99 80
99 211 146 97
80
g(n): cost so far
f(n)=g(n)+h(n) = cost so far + estimated cost to goal
Open = { Pitesti(417), Timisoara(447),
Bucharest(450), Zerind(449),
Craiova(526), Sibu(553), Sibu(591),
Arad(646), Oradea(671) }
23
A* Search Example: Romania
BucharestSibiu
Arad Oradea
Zerind Timisoara
Arad
Sibu
Fagaras
366
449 393 447
646 671 415 413
591 450
Craiova Sibiu
526 417 553
Craiova Bucharest
607 615 418
Rimnicu
Vilcea
Pitesti
75
140 118
140 151 99 80
99 211 146 97
80
97 138 101
g(n): cost so far
f(n)=g(n)+h(n) = cost so far + estimated cost to goal
Rimnicu
Vilcea
Open = { Bucharest(418), Timisoara(447),
Bucharest(450), Zerind(449), Craiova(526),
Sibu(553), Sibu(591), RimnicuVilcea(607),
Craiova(615), Arad(646), Oradea(671) }
24
A* Search Example: Romania
BucharestSibiu
Arad Oradea
Zerind Timisoara
Arad
Sibu
Fagaras
366
449 393 447
646 671 415 413
591 450
Craiova Sibiu
526 417 553
Craiova Bucharest
607 615 418
Rimnicu
Vilcea
Pitesti
75
140 118
140 151 99 80
99 211 146 97
80
97 138 101
g(n): cost so far
f(n)=g(n)+h(n) = cost so far + estimated cost to goal
Rimnicu
Vilcea
Recall that Greedy path was
[Arad, Sibu, Fagaras, Bucharest]
= 450
25
Admissible Heuristics (Not over-estimate path cost)
• 8-puzzle
• h1(n) = number of misplaced tiles
– Must move each misplaced tile at least once
• h2(n) = total Manhattan distance (city block)
– Number of squares from desired tile location (Horiz+Vert)
5 4
6 1 8
7 3 2
1 2
8
3
4
7 6 5
Start State Goal State
26
Admissible Heuristics
5 4
6 1 8
7 3 2
1 2
8
3
4
7 6 5
Start State Goal State
h1(Start) = 7 (# tiles misplaced)
h2(Start) = 2+3+3+2+4+2+0+2=18
(total Manhattan distance)[Typical solution about 20 steps, though varies with
initial state]
27
Heuristic Dominance
• If h2(n) h1(n) for all n (both admissible)
– Then h2 dominates h1, and h2 is better for search
• As the larger h2 is closer to the optimal/true
total cost h*, then A* using h2 will expand
fewer nodes (on average)
28
Repeated states in A*• Contrary to previous algorithms, avoiding
repeated states can actually harm A*
• Consider:
A(0+7=7) B(2+5=7) C(4+1=5) G(4+4+0=8)
• Goal is discovered before finding shortest path
to it!
• Depending on algorithm construction, could
return sub-optimal path
– At best, devolves to BFS-like performance
A
B
C G
2
4
1
4
7
5
1 0
Heuristic
29
Solutions to Repeated states in A*• Don’t bother
– Some problems have no possibility of repeated states (tree-like
structure)
• Modified closed set
– Store the estimated path cost for each state as well
– If a repeat has lower value, allow it (and update closed set)
– Still technically BFS-like performance (exponential) but effect
reduced in half on average
• Consistent heuristic!
30
Consistent Heuristics– Consistency: The difference in heuristic values between two
connected states is always smaller than (or equal to) the actual
cost:
𝑐𝑜𝑠𝑡 𝑥, 𝑦 ≥ ℎ 𝑥 − ℎ 𝑦
– Consistency ensures that the total estimated path cost always
increases (or stays the same) as we get closer to a goal state
• For this reason, sometimes also called a monotonic heuristic
• Guarantees that shortest path is always expanded first
– With a consistent heuristic, using a standard closed set for
repeated state avoidance is guaranteed to be both correct and
optimal
– Any consistent heuristic that has value 0 at goal states is also
admissible. However, many admissible heuristics are not
consistent!
– Though many common heuristics are consistent as well as
admissible
For two connected
states x and y
31
Properties of A*• Complete (good)
– Unless infinitely many nodes
• Time and space (not good)
– Still exponential in worst case (keeps all nodes in memory)
– Strongly depends on choice of heuristic
• Optimal (good)
– Expands fewest nodes
• Gaming: Sim City traffic
32
Summary
• Informed search strategies
• Best-first search
– Expand minimum cost nodes first
– Greedy search
• Minimize estimated cost to reach goal
– A* search
• Estimated total costs through n to goal
• (actual cost to reach n) + (estimated cost from n to goal)
• Admissible heuristic never overestimates actual distance to goal