Professional Documents
Culture Documents
Implementation:
Order the nodes in fringe in decreasing order of
desirability
Special cases:
greedy best-first search
A* search
1. Greedy Best-First Search
Heuristic Function
h(n)= estimated cost of the cheapest path from node n to a
goal node
Greedy Best-First Search
Selects the node to expand that is believed to be
closest (i.e., smallest f value) to a goal node
Greedy best-first search
Evaluation function f(n) = h(n)
(heuristic) = estimate of cost from n to goal
f(n) = h(n)
S
# of nodes tested: 0, expanded: 0 h=8
expnd. node Frontier
{S:8} 1 5 8
A B C
h=8 h=4 h=3
3 7 9 4 5
D E G
h=∞ h=∞ h=0
Greedy Best-First Search
f(n) = h(n)
S
# of nodes tested: 1, expanded: 1 h=8
expnd. node Frontier
{S:8} 1 5 8
S not goal {C:3,B:4,A:8} A B C
h=8 h=4 h=3
3 7 9 4 5
D E G
h=∞ h=∞ h=0
Greedy Best-First Search
f(n) = h(n)
S
# of nodes tested: 2, expanded: 2 h=8
expnd. node Frontier
{S:8} 1 5 8
S {C:3,B:4,A:8} A B C
C not goal {G:0,B:4,A:8} h=8 h=4 h=3
3 7 9 4 5
D E G
h=∞ h=∞ h=0
Greedy Best-First Search
f(n) = h(n)
S
# of nodes tested: 3, expanded: 2 h=8
expnd. node Frontier
{S:8} 1 5 8
S {C:3,B:4,A:8} A B C
C {G:0,B:4, A:8} h=8 h=4 h=3
G goal {B:4, A:8} not expanded
3 7 9 4 5
D E G
h=∞ h=∞ h=0
Greedy Best-First Search
f(n) = h(n)
S
# of nodes tested: 3, expanded: 2 h=8
expnd. node Frontier
{S:8} 1 5 8
S {C:3,B:4,A:8} A B C
C {G:0,B:4, A:8} h=8 h=4 h=3
G {B:4, A:8}
3 7 9 4 5
D E G
h=∞ h=∞ h=0
Fast but not optimal
path: S,C,G
cost: 13
Greedy Best-First Search
• Not complete
• Not optimal/admissible S
h=5
2 2
A B
Greedy search finds the left goal h=3 h=4
(solution cost of 7) 1 2
3
G
goal
Greedy Best-First Search
Greedy best-first search resembles depth-first search
in the way it prefers to follow a single path all the
way to the goal, but will back up when it hits a dead
end.
Optimal? No
2. A* search: Minimizing the total estimated
solution cost
Admissible heuristic
A* is optimal if h(n) is admissible heuristic.
h(n) never overestimates the actual cost to reach the
goal
A* search
• When h(n) ≤ h*(n) holds true for all n, h is called an
admissible heuristic function
3 7 9 4 5
D E G
h=∞ h=∞ h=0
A* Search
3 7 9 4 5
D E G
h=∞ h=∞ h=0
A* Search
Zerind 87
75 151
Iasi
Arad
140
92
Sibiu Fagaras
99
118
Vaslui
80
Rimnicu Vilcea
Timisoara
142
111 Pitesti 211
Lugoj 97
70 98
85 Hirsova
Mehadia 146 101 Urziceni
75 138 86
Bucharest
Drobeta 120
90
Craiova Eforie
Giurgiu
Heuristic: Straight-Line Distance to
Bucharest
380
Oradea
71 234
Neamt
374 Zerind 87
226
75 151
Iasi
Arad
366
140 253 176 92
Sibiu
99 Fagaras 199
118
Vaslui
80
329
Timisoara 193 Rimnicu Vilcea
75 138 86
Bucharest
Drobeta 120
242
90 161
Craiova 160 Giurgiu 77 Eforie
Example: Find Path from Arad to
Bucharest
Example: Find Path from Arad to
Bucharest
Example: Find Path from Arad to
Bucharest
Example: Find Path from Arad to
Bucharest
Example: Find Path from Arad to
Bucharest
Visualizing Search Methods
http://qiao.github.io/PathFinding.js/visual/