Professional Documents
Culture Documents
2
Example of Heuristic Function
• A heuristic function at node n is an estimate of
the optimum cost current node to goal.
Denoted by h(n).
H(n) = estimated cost of the cheapest path from node n to
goal node.
• Example:
– Want path form Jalandhar to chandigarh.
– Heuristic to chandigarh may be staright line distance
between jalandhar to chandigarh.
– H(jalandhar) = euclideandistance(jalandhar,
chandigarh). 3
Informed Search
B C D
3 5 1
Best-First Search (OR Graphs)
A A A
B C D B C D
3 5 1 3 5
E F
4 6
Best-First Search (OR Graphs)
A A A
B C D B C D
3 5 1 3 5
E F
4 6
A
B C D
5
G H E F
6 5 4 6
Best-First Search (OR Graphs)
A A A
B C D B C D
3 5 1 3 5
E F
4 6
A A
B C D B C D
5 5
G H E F G H E F
6 5 4 6 6 5 6
I J
2 1
Best-First Search
• OPEN: nodes that have been generated, but have not
examined.
This is organized as a priority queue.
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
Example: Find Path from S to G in
State-Space Graph
Greedy Best-First Search
S
h=5
• Not complete 2 2
A B
• Not optimal/admissible h=3 h=4
Greedy search finds the left goal 1 2
(solution cost of 7) C D
h=3 h=1
Optimal solution is the path to the 1 1
right goal (solution cost of 5) E G
h=2 goal
3
G
goal
Best-First Search
• Algorithm A* (Hart et al., 1968):
f(n) = g(n) + h(n)
1 A 3
S G
5
h=7 h=0
Algorithm A Search
S
h=5
• Not complete 2 1
A B
Not optimal/admissible h=3 h=1
Algorithm A never expands 1 1
E because f(E) is bigger than all C D
h=3 h=1
nodes below F
1 1
E F
h=∞ h=1
99
…
G
h=0
Algorithm A* Search
• Use the same evaluation function used by Algorithm A,
except add the constraint that for all nodes n in the
search space, h(n) ≤ h*(n), where h*(n) is the actual
cost of the minimum-cost path from n to a goal
• Complete
• Optimal / Admissible
Example
Zerind 87
151
75
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
380
to Bucharest
Oradea
71 234
Neamt
374
75
Zerind 151
87 226
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 160 90 161
Craiova Giurgiu 77 Eforie