0% found this document useful (0 votes)
69 views71 pages

Informed (Heuristic) Search: Mona Leeza Email: Monaleeza - Bukc@Bahria - Edu.Pk

The document discusses different types of informed search algorithms. It compares uninformed versus informed search, with informed search using heuristics to guide the search towards more promising paths. It describes best-first search as selecting nodes for expansion based on an evaluation function f(n). Greedy best-first search specifically uses f(n)=h(n), selecting the node with the lowest heuristic value. The document provides an example of greedy search to find the shortest route between cities in Romania.

Uploaded by

Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views71 pages

Informed (Heuristic) Search: Mona Leeza Email: Monaleeza - Bukc@Bahria - Edu.Pk

The document discusses different types of informed search algorithms. It compares uninformed versus informed search, with informed search using heuristics to guide the search towards more promising paths. It describes best-first search as selecting nodes for expansion based on an evaluation function f(n). Greedy best-first search specifically uses f(n)=h(n), selecting the node with the lowest heuristic value. The document provides an example of greedy search to find the shortest route between cities in Romania.

Uploaded by

Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 71

Lecture 04

Informed (Heuristic) Search

Mona Leeza
Email : [email protected]
Outline
• Informed Search
• Uninformed Versus Informed Search
• Best First Search
• Greedy Search
• A* Search
Informed Search
• Informed searches use domain knowledge
to guide selection of the best path to continue
searching
• Heuristics are used, which are informed
guesses
• Heuristic means "serving to aid discovery“
• A heuristic is a function that estimates the
cost of reaching a goal from a given state
Informed Search
• Define a heuristic function, h(n)
– uses domain-specific information in some way
– is computable from the current state description
– it estimates
• the "goodness" of node n
• how close node n is to a goal
• the cost of minimal cost path from node n to a goal
state
Informed Search
• h(n) ≥ 0 for all nodes n
• h(n) close to 0 means we think n is close to a goal state
• h(n) very big means we think n is far from a goal state

• All domain knowledge used in the search is encoded in


the heuristic function, h
• An example of a “weak method” for AI because of the
limited way that domain-specific information is used to
solve a problem
Uninformed versus Informed
Uninformed search Informed search
• does not have any additional • heuristically informed search
information on the quality of uses a certain kind of
states. information about states in
• So, it is impossible to order to guide search along
determine which state is the promising branches within a
better than others. As a result, state space.
search efficiency depends only
on the structure of a state • Using problem specific
space knowledge as hints to guide
• look for solutions by the search.
systematically generating new
states and checking each of
them against the goal.
Uninformed versus Informed (cont)
Uninformed search Informed search
1. It is very inefficient in most 1. They are almost always more
cases. efficient than uninformed
strategies.
2. Most successor states are 2. May reduce time and space
“obviously” a bad choice. complexities.
3. Evaluation function f(n)
3. Such strategies do not use measures distance to the goal.
problem-specific knowledge 4. Order nodes in Frontier
according to f(n) and decide
which node to expand next.
Best-First Search
An informed search strategy uses problem-specific knowledge
beyond the definition of the problem itself, so it can find
solutions more efficiently than an uninformed strategy.
Best-first search is an instance of the general TREE-SEARCH or
GRAPH-SEARCH algorithm in which a node is selected for
expansion based on an evaluation function, f (n) .

• A key component of these algorithms is a heuristic function


denoted h(n) :

h(n) = estimated cost of the cheapest path from node n to a


goal node, if n is a goal node, then h(n) = 0.
Best-First Search
Special cases:
• Greedy Best first search
• “Always chooses the successor node with the best f
value” where f(n) = h(n)
• We choose the one that is nearest to the final state
among all possible choices

• A* search
• Best first search using an “admissible” heuristic function f
that takes into account the current cost g
• Always returns the optimal solution path
Greedy Best First Search
eval-fn: f(n) = h(n)
Greedy Best-First Search
• Greedy best-first search tries to expand the node
that is closest to the goal, on the grounds that it is
likely to lead to a solution quickly.
• Thus, it evaluates nodes by using just the heuristic
function; that is, f(n)=h(n).
• Evaluation function
f(n) = h(n) (heuristic) = estimate of cost from n to goal

• Assume hSLD(n) = straight line distance from n to


Bucharest, so Greedy best-first search expands the
node that appears to be closest to goal
Romania
Romania
Romania
Map of Romania
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search
Start State Heuristic: h(n)
A 75
118 A 366

C 140 B 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
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search – Tree Search
Start State Heuristic
A : h(n)
A 366
B 374
C 329
D 244
E 253
F 178
G 193
H 98
I 0
Greedy Search – Tree Search
Start State Heuristic
118
A 75 : h(n)
A 366
[329] 140 [374] B
C B 374
[253] E C 329
D 244
E 253
F 178
G 193
H 98
I 0
Greedy Search – Tree Search
Start State Heuristic
118
A 75 : h(n)
A 366
[329] 140 [374] B
C B 374
[253] E C 329
80 99
D 244
[193] [178] E 253
G F
[366] A F 178
G 193
H 98
I 0
Greedy Search – Tree Search
Start State Heuristic
118
A 75 : h(n)
A 366
[329] 140 [374] B
C B 374
[253] E C 329
80 99
D 244
[193] [178] E 253
G F
[366] A F 178
211
G 193
H 98
[253] I [0]
E I 0
Goal
Greedy Search – Tree Search
Start
A 75
118
State Heuristic
[374] B
[329] C 140 : h(n)
A 366
[253] E
80 99 B 374
C 329
[193] [178]
G F D 244
[366] A
211 E 253
F 178
[253] I [0] G 193
E
H 98
Goal
I 0
Path cost(A-E-F-I) = 253 + 178 + 0 = 431
dist(A-E-F-I) = 140 + 99 + 211 = 450
Greedy Search: Optimal ?
State Heuristic: h(n)
Start A 366
A
118 75 B 374

140 B C 329
C
111 D 244
E
D 80 99 E 253
F 178
G F G 193
97 H 98
H 211 I 0

101 f(n) = h (n) = straight-line distance heuristic


I
Goal dist(A-E-G-H-I) = 140 + 80 + 97 + 101 = 418
Greedy Search: Complete ?
State Heuristic:
Start
A h(n)
118 75
A 366
140 B B 374
C
111 ** C 250
E
D 80 99 D 244
E 253
G F F 178
97 G 193
H H 98
211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
Greedy Search: Tree Search
State Heuristic:
Start
A h(n)
A 366
B 374
** C 250
D 244
E 253
F 178
G 193
H 98
I 0
Greedy Search: Tree Search
State Heuristic:
Start
A h(n)
118 75
A 366
[250] 140 [374] B B 374
C
** C 250
[253] E
D 244
E 253
F 178
G 193
H 98
I 0
Greedy Search: Tree Search
State Heuristic:
Start
A h(n)
118 75
A 366
[250] 140 [374] B B 374
C
** C 250
[253] E
111 D 244
[244] D E 253
F 178
G 193
H 98
I 0
Greedy Search: Tree Search
State Heuristic:
Start
A h(n)
118 75
A 366
[250] 140 [374] B B 374
C
** C 250
[253] E
111 D 244
[244] D E 253
F 178
Infinite Branch !
[250] G 193
C
H 98
I 0
Greedy Search: Tree Search
State Heuristic:
Start
A h(n)
118 75
A 366
[250] 140 [374] B B 374
C
** C 250
[253] E
111 D 244
[244] D E 253
F 178
Infinite Branch !
[250] G 193
C
H 98
I 0
[244] D
Greedy Search: Tree Search
State Heuristic:
Start
A h(n)
118 75
A 366
[250] 140 [374] B B 374
C
** C 250
[253] E
111 D 244
[244] D E 253
F 178
Infinite Branch !
[250] G 193
C
H 98
I 0
[244] D
Greedy Search: Time and Space Complexity ?
• Greedy search is not optimal.
Start
A
118 75 • Greedy search is incomplete
C 140 B without systematic checking of
111
E repeated states.
D 80 99
• In the worst case, the Time and
G F Space Complexity of Greedy
97 Search are both O(bm)
H Where b is the branching factor and m the maximum
211
path length
101
I
Goal
A* Search
eval-fn: f(n) = g(n) + h(n)
A* (A Star)
o 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.

o Uniform Cost Search minimizes the cost g(n) from the


initial state to n. UCS is optimal and complete but not
efficient.

o New Strategy: Combine Greedy Search and UCS to


get an efficient algorithm which is complete and
optimal.
A* (A Star)
• A* uses a heuristic function which combines
g(n) and h(n): f(n) = g(n) + h(n)

• g(n) is the exact cost to reach node n from


the initial state.

• h(n) is an estimation of the remaining cost


to reach the goal.
A* (A Star)

g(n)

f(n) = g(n)+h(n) n

h(n)
A* Search
State Heuristic: h(n)
Start A 366
A
118 75 B 374

140 B C 329
C
111 D 244
E
D 80 99 E 253
F 178
G F G 193
97 H 98
H 211 I 0

101 f(n) = g(n) + h (n)


I g(n): is the exact cost to reach node n from the initial state.
Goal
A* Search: Tree Search
Start State Heuristic:
A
h(n)
A 366
B 374
C 329
D 244
E 253
F 178
G 193
H 98
I 0
A* Search: Tree Search
Start State Heuristic:
A
h(n)
118 75
140 A 366
B 374
E [393] B [449]
[447] C C 329
D 244
E 253
F 178
G 193
H 98
I 0
A* Search: Tree Search
Start State Heuristic:
A
h(n)
118 75
140 A 366
B 374
E [393] B [449]
[447] C C 329
80 99
D 244
[413] G F [417] E 253
F 178
G 193
H 98
I 0
A* Search: Tree Search
Start Stat Heuristic:
A
e h(n)
118 75
140 A 366
B 374
E [393] B [449]
[447] C C 329
80 99
D 244
[413] G F [417] E 253
F 178
97
G 193
[415] H
H 98
I 0
A* Search: Tree Search
Start State Heuristic:
A
h(n)
118 75
140 A 366
B 374
E [393] B [449]
[447] C C 329
80 99
D 244
[413] G F [417] E 253
F 178
97
G 193
[415] H
H 98
101 I 0
Goal I [418]
A* Search: Tree Search
Start State Heuristic:
A
h(n)
118 75
140 A 366
B 374
E [393] B [449]
[447] C C 329
80 99
D 244
[413] G F [417] E 253
211 F 178
97
G 193
[415] H I [450]
H 98
101 I 0
Goal I [418]
A* Search: Tree Search
Start State Heuristic:
A
h(n)
118 75
140 A 366
B 374
E [393] B [449]
[447] C C 329
80 99
D 244
[413] G F [417] E 253
211 F 178
97
G 193
[415] H I [450]
H 98
101 I 0
Goal I [418]
A* Search: Tree Search
Start State Heuristic:
A
h(n)
118 75
140 A 366
B 374
E [393] B [449]
[447] C C 329
80 99
D 244
[413] G F [417] E 253
211 F 178
97
G 193
[415] H I [450]
H 98
101 I 0
Goal I [418]
A* with f() not Admissible
h() overestimates the cost to reach the goal state
A* Search: h not admissible !
State Heuristic: h(n)
Start
A 75 A 366
118
B B 374
C 140
C 329
111
E D 244
D 80 99
E 253
G F F 178

97 G 193

H H 138
211
I 0
101
I f(n) = g(n) + h (n) – (H-I) Overestimated
Goal
g(n): is the exact cost to reach node n from the initial state.
A* Search: Tree Search

A Start
A* Search: Tree Search

A Start

118 75
140

E [393] B [449]
[447] C
A* Search: Tree Search

A Start

118 75
140

E [393] B [449]
[447] C
80 99

[413] G F [417]
A* Search: Tree Search

A Start

118 75
140

E [393] B [449]
[447] C
80 99

[413] G F [417]

97
[455] H
A* Search: Tree Search

A Start

118 75
140

E [393] B [449]
[447] C
80 99

[413] G F [417]

97
[455] H Goal I [450]
A* Search: Tree Search

A Start

118 75
140

E [393] B [449]
[447] C
80 99

[473] [413] G F [417]


D
211
97
[455] H Goal I [450]
A* Search: Tree Search

A Start

118 75
140

E [393] B [449]
[447] C
80 99

[473] [413] G F [417]


D
211
97
[455] H Goal I [450]
A* Search: Tree Search

A Start

118 75
140

E [393] B [449]
[447] C
80 99

[473] [413] G F [417]


D
211
97
[455] H Goal I [450]
A* Search: Tree Search

A Start

118 75
140

E [393] B [449]
[447] C
80 99

[473] [413] G F [417]


D
211
97
[455] H Goal I [450]

A* not optimal !!!


A* Search

A* with systematic checking for


repeated states …
A* Algorithm
1. Search queue Q is empty.
2. Place the start state s in Q with f value h(s).
3. If Q is empty, return failure.
4. Take node n from Q with lowest f value.
(Keep Q sorted by f values and pick the first element).
5. If n is a goal node, stop and return solution.
6. Generate successors of node n.
7. For each successor n’ of n do:
a) Compute f(n’) = g(n) + cost(n,n’) + h(n’).
b) If n’ is new (never generated before), add n’ to Q.
c) If node n’ is already in Q with a higher f value, replace it with
current f(n’) and place it in sorted order in Q.
End for
8. Go back to step 3.
A* Search: Analysis
Start
•A* is complete except if there is an
A 75 infinity of nodes with f < f(G).
118

140 B •A* is optimal if heuristic h is


C
111 admissible.
E
D 80 99 •Time complexity depends on the
quality of heuristic but is still
G F
exponential.
97
•For space complexity, A* keeps all
H 211 nodes in memory. A* has worst case
101 O(bd) space complexity, but an iterative
I deepening version is possible (IDA*).
Goal
Conclusions
• Frustration with uninformed search led to the
idea of using domain specific knowledge in a
search so that one can intelligently explore
only the relevant part of the search space that
has a good chance of containing the goal state.
These new techniques are called informed
(heuristic) search strategies.
• Even though heuristics improve the
performance of informed search algorithms,
they are still time consuming especially for
large size instances.
TUTORIAL 04
1. Define informed/heuristic search strategy.
2. What is the difference between
a) Informed and Uninformed Search
b) Greedy best first and A* algorithms
3. Prove that Uniform-cost search is a special case of A∗ search..
4. Prove that if a heuristic is consistent, it must be admissible.
Construct an admissible heuristic that is not consistent.
5. Are Greedy best first and A* algorithms optimal and complete?
6. What is the time and space complexity of Greedy best first and A*
algorithms?
Tutorial 04 A 240
B 186
C 182
7. D 163
E 170
F 150
G 165
H 139
I 120
J 130
K 122
L 104
M 100
N 77
O 72
P 65
Q 65
R 0

Goal
TUTORIAL 04 A 56
B 22
8. Consider the following map (not drawn to scale). C 30
D 29
E 29
F 30
G 14
H 10
I 8
J 5
K 30
L 15
M 0

Use the A* algorithm to work out a route from town A to town M. Use the following cost functions.
•G(n) = The cost of each move as the distance between each town (shown on map).
•H(n) = The Straight Line Distance between any town and town M. These distances are given in the
table to right of map.
•Provide the search tree for your solution, showing the order in which the nodes were expanded
and the cost at each node. You should not re-visit a town that you have just come from.
•State the route you would take and the cost of that route.

You might also like