Chapter 3 - Part - 4
Chapter 3 - Part - 4
A* Search
• Greedy search minimizes the estimated
cost h(n) from the node n to the goal. So, it
reduces considerably the search cost. But it
is neither optimal nor complete
• Uniform-cost search minimizes the cost g(n)
from the initial state to the node n. It is
optimal and complete. But, generally it is
not efficient
1
Fundamentals of Ar tificial Intelligence
A* Search
• A* combines the two algorithms in order to minimize
the total cost f(n) through the node n
• Evaluation function f(n) = g(n) + h(n)
– g(n) = cost so far to reach n
2
Fundamentals of Ar tificial Intelligence
A* Search
s
g(n): actual
cost
Heuristic f(n)
n
f(n)= g(n) + h(n)
h(n): estimated
cost
g
3
Fundamentals of Ar tificial Intelligence
A* Search: Example
8 S
1 5 8
9 A 4 B 3 C
3 9
7 4 5
11 D 10 E 0 G
4
Fundamentals of Ar tificial Intelligence
A* Search: Example
Stage 0: Starting from node S
f(s) = g(s) + h(s) = 0 + 8 = 8
8 S
5
Fundamentals of Ar tificial Intelligence
A* Search: Example
10 A 9 B 11 C
6
Fundamentals of Ar tificial Intelligence
A* Search: Example
Stage 2: Selecting node G (the goal)
f(G) = (5 + 4) + 0 = 9
8 S
1 5 8
8 A 4 B 3 C
4
9 G
7
Fundamentals of Ar tificial Intelligence
A* Search: Properties
• Complete: Yes
• Time: exponential
• Optimal: Yes
8
Fundamentals of Ar tificial Intelligence
9
Fundamentals of Ar tificial Intelligence
1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial state Final state
10
Fundamentals of Ar tificial Intelligence
11
Fundamentals of Ar tificial Intelligence
12
Fundamentals of Ar tificial Intelligence
h2(n) = 18 5 4
6 1 8
h1(n) = 2 + 3 + 3 + 2 + 4 + 2
+ 0 + 2 = 18 7 3 2
13
Fundamentals of Ar tificial Intelligence
Dominance
14
Fundamentals of Ar tificial Intelligence
Dominance
• Comparison of the search cost and the
effective branching factor (d) for the Iterative
Deepening Search (IDS) and A* algorithms with
heuristics h1, h2
d IDS A*(h1) A*(h2)
14 3473941 539 113
24 Too 39135 1641
many
The numbers in red represents number of visited
nodes for the 8-puzzle problem
15
Fundamentals of Ar tificial Intelligence
8-Puzzle Example
• To solve this problem, we use the heuristic h1
(number of tiles badly placed)
16
Fundamentals of Ar tificial Intelligence
8-Puzzle Example
Step 0
1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
17
Fundamentals of Ar tificial Intelligence
8-Puzzle Example
Step 1
1 2 3
h(n) = 3 8 6
7 5 4
18
Fundamentals of Ar tificial Intelligence
8-Puzzle Example
Step 2
1 2 3 h(n) = 3
8 6
7 5 4
h(n) = 2 h(n) = 4
h(n) = 3
1 2 3 1 2
1 2 3
8 6 4 8 6 3
8 6
7 5 7 5 4
7 5 4
19
Fundamentals of Ar tificial Intelligence
8-Puzzle Example
Step 3 1 2 3 h(n) = 3
8 6
7 5 4
h(n) = 2 h(n) = 4
h(n) = 3
1 2 3 1 2
1 2 3
8 6 4 8 6 3
8 6
7 5 7 5 4
7 5 4
h(n) = 3 h(n) = 1
1 2 3 1 2 3
8 6 8 6 4
7 5 4 7 5
20
1 2 3 h(n)Fundamentals
=3 of Ar tificial Intelligence
Step 4
8 6
7 5 4
21