Professional Documents
Culture Documents
Principles of Artificial
Intelligence
Course Code CS321
Lecturer:Wedad Al-Sorori
Search 2022 1/90
CS321: Principles of Artificial Intelligence
Informed (Heuristic)
Search Algorithms
Chapter Objectives
Introduction (1/7)
Introduction (2/7)
• With knowledge, one can search the state space as if he was given “hints”
when exploring a maze.
• Heuristic information in search = Hints
• Leads to dramatic speed up in efficiency.
A
B C D E
F G H I J
Introduction (3/7)
• In any search problem where there are at most b choices at each node and a depth
of d at the goal node, a naive search algorithm would have to, in the worst case,
search around O(bd) nodes before finding a solution (Exponential Time
Complexity).
Introduction (4/7)
• f measures the estimated cost of getting to the goal from the current state:
• f(n) = h(n) where h(n) = an estimate of the cost to get from n to a goal
• f measures the estimated cost of getting to the goal state from the current state
and the cost of the existing path to it. Often, in this case, we decompose f:
• f(n) = g(n) + h(n) where g(n) = the cost to get to n (from initial state)
Introduction (5/7)
• N-Queens
• Example: the number of queens under attack …
Introduction (6/7)
Introduction (7/7)
• A* search
• Expands the node on the least cost solution path, i.e., f (n) = g(n) + h(n).
• Best first search using an “admissible” heuristic function f that takes into account the
current cost g
• Always returns the optimal solution path
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 16/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 17/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I
f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 18/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I
f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 19/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I
f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 20/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I
f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 21/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I
f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 22/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 23/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I
f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 24/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I
f(n) = hSLD (n) = straight-line distance heuristic
Search 2022 25/90
CS321: Principles of Artificial Intelligence
Start
A
Start
A 75
118
[329] C 140 [374] B
[253] E
Start
A 75
118
[329] C 140 [374] B
[253] E
80 99
[193] G F [178]
[366] A
Start
A 75
118
[329] C 140 [374] B
[253] E
80 99
[193] G F [178]
[366] A
211
[253] E I [0]
Goal
Search 2022 29/90
CS321: Principles of Artificial Intelligence
Start
A 75
118
[329] C 140 [374] B
[253] E
80 99
[193] G F [178]
[366] A
211
140 B B 374
C
111 C 329
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I f(n) = h (n) = straight-line distance heuristic
Goal dist(A-E-G-H-I) =140+80+97+101=418
Search 2022 31/90
CS321: Principles of Artificial Intelligence
140 B B 374
C
111 ** C 250
E
D D 244
80 99
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I
f(n) = h (n) = straight-line distance heuristic
Goal
Search 2022 32/90
CS321: Principles of Artificial Intelligence
Start
A
Start
A 75
118
[250] C 140 [374] B
[253] E
Start
A 75
118
[250] C 140 [374] B
111 [253] E
[244] D
Start
A 75
118
[250] C 140 [374] B
111 [253] E
[244] D
Infinite Branch !
[250] C
Start
A 75
118
[250] C 140 [374] B
111 [253] E
[244] D
Infinite Branch !
[250] C
[244] D
Start
A 75
118
[250] C 140 [374] B
111 [253] E
[244] D
Infinite Branch !
[250] C
[244] D
Greedy Search
A* (A Star)
• Greedy Search minimizes a heuristic h(n) which is an estimated cost
from a node n to the goal state. Greedy Search is efficient but it is
not optimal nor complete.
• Uniform Cost Search minimizes the cost g(n) from the initial state to
n. UCS is optimal and complete but not efficient.
A* (A Star)
• g(n) is the exact cost to reach node n from the initial state.
A* (A Star)
g(n)
f(n) = g(n)+h(n) n
h(n)
A* Search
Start
A 75 State Heuristic: h(n)
118
A 366
140 B
C B 374
111 C 329
E
D 80 99 D 244
E 253
G F F 178
97 G 193
H 211 H 98
101 I 0
I f(n) = g(n) + h (n)
Goal
g(n): is the exact cost to reach node n from the initial state.
Search 2022 45/90
CS321: Principles of Artificial Intelligence
A Start
A Start
118 75
140
C E [393] B [449]
[447]
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
97
[415] H
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
97
[415] H
101
I
Goal [418]
Search 2022 50/90
CS321: Principles of Artificial Intelligence
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
97
[415] H I [450]
101
Goal I [418]
Search 2022 51/90
CS321: Principles of Artificial Intelligence
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
97
[415] H I [450]
101
Goal I [418]
Search 2022 52/90
CS321: Principles of Artificial Intelligence
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
97
[415] H I [450]
101
I
Goal [418]
Search 2022 53/90
CS321: Principles of Artificial Intelligence
A Start
A Start
118 75
140
C E [393] B [449]
[447]
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
97
[455] H
A Start
118 75
140
C E [393] B [449]
[447]
80 99
[413] G F [417]
97
[455] H I [450]
Goal
A Start
118 75
140
C E [393] B [449]
[447]
80 99
97
[455] H I [450]
Goal
A Start
118 75
140
C E [393] B [449]
[447]
80 99
97
[455] H I [450]
Goal
A Start
118 75
140
C E [393] B [449]
[447]
80 99
97
[455] H I [450]
Goal
A Start
118 75
140
C E [393] B [449]
[447]
80 99
97
[455] H I [450]
Goal
A* Algorithm
A* with systematic checking for repeated states …
A* Algorithm
A* Algorithm
⚫ Complete? Yes (unless there are infinitely many nodes with f ≤ f(G) )
⚫ Time? Exponential
⚫ Space? Keeps all nodes in memory
⚫ Optimal? Yes
A* Search: Analysis
Start
A 75
118
140 B
C • A* is complete except if there is an infinity of nodes with f
111 E
< f(G).
D 80 99 • A* is optimal if heuristic h is admissible.
• Time complexity depends on the quality of heuristic but is
G F still exponential.
101
I
Goal
Search 2022 68/90
CS321: Principles of Artificial Intelligence
Consistent Heuristic
• The admissible heuristic h is consistent (or satisfies the
monotone restriction) if for every node N and every
successor N’ of N:
N
71
Search 2022 71/90
CS321: Principles of Artificial Intelligence
IDA* Algorithm
• In the first iteration, we determine a “f-cost limit” – cut-off value
f(n0) = g(n0) + h(n0) = h(n0), where n0 is the start node.
• We expand nodes using the depth-first algorithm and backtrack whenever f(n) for an expanded
node n exceeds the cut-off value.
• If this search does not succeed, determine the lowest f-value among the nodes that were visited
but not expanded.
• Use this f-value as the new limit value – cut-off value and do another depth-first search.
4
Cutoff=4
6
Search 2022 73/90
CS321: Principles of Artificial Intelligence
4
Cutoff=4 4
6 6
Search 2022 74/90
CS321: Principles of Artificial Intelligence
8-Puzzle
f(N) = g(N) + h(N)
with h(N) = number of misplaced tiles
4
Cutoff=4 4 5
6 6
Search 2022 75/90
CS321: Principles of Artificial Intelligence
4
Cutoff=4 4 5
6 6
Search 2022 76/90
CS321: Principles of Artificial Intelligence
6 5
4
Cutoff=4 4 5
6 6
Search 2022 77/90
CS321: Principles of Artificial Intelligence
8-Puzzle
f(N) = g(N) + h(N)
with h(N) = number of misplaced tiles
4
Cutoff=5
6
Search 2022 78/90
CS321: Principles of Artificial Intelligence
THANKS