AI Lecture 7-8
AI Lecture 7-8
AI Lecture 7-8
(CS-401)
Lecture 4:
Heuristic Informed Search
Algorithms
5
Best-first search
Idea: use an evaluation function f(n) for each node
– family of search methods with various evaluation functions
(estimate of "desirability“)
– usually gives an estimate of the distance to the goal
– often referred to as heuristics in this context
→Expand most desirable unexpanded node
→A heuristic function ranks alternatives at each branching step
based on the available information (heuristically) in order to
make a decision about which branch to follow during a search.
Implementation:
Order the nodes in fringe in decreasing order of desirability.
Special cases:
– Greedy best-first search
– A* search 5
Romania with step costs in km
6
Greedy best-first search
• Greedy best-first search expands the node that appears
to be closest to goal heuristically.
8
Greedy best-first search example
8
Greedy best-first search example
9
Greedy best-first search example
10
Greedy best-first search
11
Properties of greedy best-first search
Optimal: No
b branching factor
m maximum depth of the
search tree
12
A* search
Idea: avoid expanding paths that are already expensive.
Evaluation function = path cost + estimated cost
to the goal
f(n) = g(n) + h(n)
-g(n) = cost so far to reach n
-h(n) = estimated cost from n to goal
-f(n) = estimated total cost of path through n to goal
13
A* search example Example from [1]
16
A* search example
15
A* search example
16
A* search example
17
A* search example
18
A* search example
19
A* Algorithm
20
Greedy Best-First Exercise
21
Solution to Greedy Best-First Exercise
22
A* Exercise
23
A* Exercise
A (5,9) 8.0
B (3,8) 7.3
C (8,8) 7.6
D (5,7) 6.0
E (7,6) 5.4
F (4,5) 4.1
G (6,5) 4.1
H (3,3) 2.8
I (5,3) 2.0
J (7,2) 2.2
K (5,1) 0.0
24
Solution to A* Exercise
25
Another Exercise
Do 1) A* Search and 2) Greedy Best-Fit Search
28
Admissible Heuristics
A heuristic h(n) is admissible if for every node n, h(n) ≤ h*(n),
where h*(n) is the true cost to reach the goal state from n.
27
Optimality of A* (proof)
Recall that f(n) = g(n) + h(n)
Now, suppose some suboptimal goal G2 has been generated and is in the
fringe. Let n be an unexpanded node in the fringe such that n is on a
shortest path to an optimal goal G.
Start
We want to prove:
f(n) < f(G2)
(then A* will prefer n over G2) n
28
Optimality of A* (proof)
G G2
In other words:
f(G2) = g(G2) + h(G2) = g(G2) > C*,
since G2 is a goal on a non-optimal path (C* is the optimal cost)
f(n) = g(n) + h(n) ≤ C*, since h is admissible
f(n) ≤ C* < f(G2), so G2 will never be expanded
→ A* will not expand goals on sub-optimal paths
29
Properties of A*
• Complete: Yes
unless there are infinitely many nodes with f ≤ f(G)
• Time: Exponential
because all nodes such that f(n) ≤ C* are expanded!
• Optimal: Yes
30
Memory Bounded Heuristic Search
31
Simple Memory Bounded A* (SMA*)
• This is like A*, but when memory is full we delete the worst
node (largest f-value).
32
SMA* pseudocode
Based on [2]
Queue MAKE-QUEUE({MAKE-NODE(INITIAL-STATE[problem])})
loop do
if Queue is empty then return failure
n deepest least-f-cost node in Queue
if GOAL-TEST(n) then return success
s NEXT-SUCCESSOR(n)
if s is not a goal and is at maximum depth then
f(s)
else
f(s) MAX(f(n),g(s)+h(s))
if all of n’s successors have been generated then
update n’s f-cost and those of its ancestors if necessary
if SUCCESSORS(n) all in memory then remove n from Queue
if memory is full then
delete shallowest, highest-f-cost node in Queue
remove it from its parent’s successor list
insert its parent on Queue if necessary
insert s in Queue
end
33
Simple Memory-bounded A* (SMA*)
How it works:
• Like A*, it expands the best leaf until memory is full.
• Drops the worst leaf node- the one with the highest f-value.
• SMA* then backs up the value of the forgotten node to its parent.
34
Simple Memory-bounded A* (SMA*)
(Example with 3-node memory)
Progress of SMA*. Each node is labeled with its
current f-cost. Values in parentheses show the value of
Search space
the best forgotten descendant.
A
f = g+h = goal A A
13[15]
A
12 12
A 13
G
0+12=12
13
10 8
B G B
B G
10+5=15 8+5=13 15
18 H
10 10 8 16
15 13
C D H I
20+5=25 16+2=18 A A A
15[15] 15[24] 20[24]
20+0=20 24+0=24
10 10 A 8
8 8 15
E F J K B B
G
15 20[]
24[]
30+5=35 30+0=30 24+0=24 24+5=29
B G
I D
15 24 C 25
24
20
38
Recursive Best First Search (RBFS)
best alternative
over fringe nodes,
which are not children:
do I want to back up?
If the rules are relaxed so that a tile can move to any near
square, then h2(n) gives the shortest solution.
40