CompS333F Advanced Programming and AI
Algorithms
Lecture 5: Informed Search
Courtesy: ai.ucberkeley
Acknowledgment: Thanks for Mr. Jackey Cheung providing the lecture material
1
Informed Search
Search strategies that use problem-specific knowledge beyond the
definition of the problem itself
2
Today
▪ Informed Search
▪ Heuristics
▪ Greedy Search
▪ A* Search
3
Search Heuristics
▪ A heuristic is:
▪ A function that estimates how close a state is to a goal
▪ Designed for a particular searchproblem
▪ Examples: Manhattandistance, Euclidean distance for pathing
10
5
11.2
4
Example: Heuristic Function
h(x)
5
Greedy Search
JackeyCheungHKMU 6
Greedy Search
▪ Expand the node that seemsclosest…
▪ What can go wrong?
7
Greedy Search
b
▪ Strategy: expand a node that you think is …
closest to a goalstate
▪ Heuristic: estimate of distance to nearest goal for
each state
▪ A common case:
▪ Best-first takes you straight to a goal …
b
▪ Worst-case: like a badly-guided DFS
8
A* Search
9
A* Search
UCS Greedy
A*
10
Combining UCS and Greedy
▪ Uniform-cost orders by path cost, or backward cost g(n)
▪ Greedy orders by goal proximity, orforward cost h(n)
8 g =0
S
h=6
e h=1 g =1
h=5 a
1
1 3 2 g =2 g =9
S a d G b d g =4 e h=1
h=6 h=2
h=6 1 h=5
h=2 h=0
1 g =3 g =6
c b
h=7 c G d g =10
h=0 h=2
h=7 h=6
g =12
G
▪ A* Search orders by the sum: f(n) = g(n) + h(n) h=0
11
When should A* terminate?
▪ Should we stop when we enqueue a goal?
g =2
h =2
2 A 2 g =4
h =0
g =0
S h =3
G
g =5
2 B 3 h =0
g =2
h =1
▪ No: only stop when we dequeue a goal 12
Is A* Optimal?
g =1
h =6
1 A 3
g =4
h =0
g =0
S G
h =7
g =5
h =0
▪ What went wrong?
▪ We need estimates to be less than actual costs!
13
Admissible Heuristics
14
Idea: Admissibility
Inadmissible (pessimistic) heuristics break Admissible (optimistic) heuristics should slow
optimality by trapping good plans on the fringe down bad plans but never outweigh true costs
15
Admissible Heuristics
▪ Aheuristic h is admissible (optimistic) if:
where is the true cost to a nearest goal
▪ Example:
15
▪ Coming up with admissible heuristics is most of what’s involved
in using A* in practice.
16
Optimality of A* Tree Search
17
Optimality of A* Tree Search
Assume:
▪ A is an optimal goal node …
▪ Bis a suboptimal goal node
▪ h is admissible
Claim:
▪ Awill exit the fringe before B
Proof:
▪ Beyond this module
▪ We accept A* search is optimal
18
Properties of A*
Uniform-Cost A*
b b
… …
19
UCS vs A* Contours
▪ Uniform-cost expands equally inall
“directions”
Start Goal
▪ A* expands mainly toward the goal,
but does hedge its bets to ensure
optimality Start Goal
20
Comparison
Greedy UCS A*
21
A* History
▪ A* was invented by
researchers working on
Shakey the Robot's path
planning in 1968.
22
A* Applications
▪ Video games
▪ Pathing / routingproblems
▪ Resource planning problems
▪ Robot motion planning
▪ Language analysis
▪ Machine translation
▪ Speech recognition
▪ … Screenshot of Age ofEmpires
23
Graph Search
24
Tree Search: Extra Work!
▪ Failure to detect repeated states can cause exponentially more work.
State Graph Search Tree
25
Graph Search
▪ Idea: never expand a statetwice
▪ How to implement:
▪ Tree search + set of expanded states (“closed set” or “exploredset”)
▪ Expand the search tree node-by-node,but…
▪ Before expanding a node, check to make sure its state has never been expanded before
▪ If not new, skip it, if new add to closed set
26
Tree Search Pseudo-Code
27
Graph Search Pseudo-Code
28
A* Graph Search Gone Wrong?
State space graph Search tree
A S (0+2)
1
1
S h=4
C
h=1 A (1+4) B (1+1)
h=2 1
2
3 C (2+1) C (3+1)
B
h=1
G G (5+0) G (6+0)
h=0
29
Consistency of Heuristics
▪ Main idea: estimated heuristic costs ≤ actual costs
A ▪ Admissibility: heuristic cost ≤ actual cost to goal
1 h(A) ≤ actual cost from A to G
h=4 C h=1 ▪ Consistency: heuristic “arc” cost ≤ actual cost for each arc
h=2
h(A) – h(C) ≤ cost(A to C)
3
▪ Consequences of consistency:
▪ The f value along a path never decreases
G h(A) ≤ cost(A to C) + h(C)
▪ A* graph search is optimal
30
Optimality
▪ Tree search:
▪ A* is optimal if heuristic is admissible
▪ Graph search:
▪ A* optimal if heuristic is consistent
▪ Consistency implies admissibility
▪ In general, most naturaladmissible
heuristics tend to beconsistent
31
A*: Summary
32
A*: Summary
▪ A* uses both backward costs and (estimates of) forward costs
▪ A* is optimal with admissible /consistent heuristics
▪ Heuristic design is key
33
The One Queue
▪ All these search algorithms arethe
same except for fringestrategies
▪ Conceptually, all fringes are priority
queues (i.e. collections of nodeswith
attached priorities)
▪ Can even code oneimplementation
that takes a variable queuingobject
34
Recommended Reading
Stuart Russell, Peter Norvig: Artificial
Intelligence A Modern Approach
Chapter 3
35