Sie sind auf Seite 1von 8

Artificial Intelligence

Informed search
Chapter 4, AIMA

Romania Romania

Romania problem
Initial state: Arad
Find the minimum
distance path to
Bucharest.

1
Informed search Example heuristic function h(n)
Searching for the goal and knowing something
about in which direction it is.

Evaluation function: f(n)


- Expand the node with minimum f(n)

Heuristic function: h(n)


- Our estimated cost of the path from node n to
the goal.
hSLD Straight-line distances (km) to Bucharest

Assignment: Expand the


Greedy best-first (GBFS) nodes in the greedy-best-
first order, beginning from
Arad and going to Bucharest

Expand the node that appears to be closest


to the goal: f(n) = h(n)

Incomplete (infinite paths, loops)


Not optimal (unless the heuristic function
is a correct estimate)
These are the h(n)
Space and time complexity ~ O(bd) values.

Map

Romania problem: GBFS


Initial state: Arad
Find the minimum
distance path to
Bucharest.

374

253

329

Path cost = 450 km

2
Romania problem: GBFS Romania problem: GBFS
Initial state: Arad Initial state: Arad
Find the minimum Find the minimum
distance path to distance path to
Bucharest. Bucharest.
380

366

176 253

193

Not the optimal solution


Path cost = 450 km

Assignment: Expand the


A and A* best-first search nodes in the A* order,
beginning from Arad and
going to Bucharest

A: Improve greedy search by discouraging


wandering off: f(n) = g(n) + h(n)

Here g(n) is the cost to get to node n from the start


position.
This penalizes taking steps that dont improve
things considerably.
These are the g(n)
A*: Use an admissible heuristic, i.e. a heuristic values.
h(n) that never overestimates the true cost for
reaching the goal from node n. These are the h(n)
values.

= g(n) + h(n)
The straight-line distance = g(n) + h(n)
The straight-line distance
never overestimates the never overestimates the
true distance; it is an true distance; it is an
admissible heuristic. admissible heuristic.
A* on the Romania problem. A* on the Romania problem.

Rimnicu-Vilcea is expanded before Rimnicu-Vilcea is expanded before


Fagaras. Fagaras.
The gain from expanding Fagaras is too The gain from expanding Rimnicu-Vilcea
small so the A* algorithm backs up is too small so the A* algorithm
and expands Fagaras. backs up and expands Fagaras.
None of the descentants of Fagaras is None of the descentants of Fagaras is
better than a path through Rimnicu- better than a path through Rimnicu-
Vilcea; the algorithm goes back to Vilcea; the algorithm goes back to
Rimnicu-Vilcea and selects Pitesti. Rimnicu-Vilcea and selects Pitesti.

The final path cost = 418 km The final path cost = 418 km
This is the optimal solution. This is the optimal solution.

3
= g(n) + h(n)
The straight-line distance = g(n) + h(n)
The straight-line distance
never overestimates the never overestimates the
true distance; it is an true distance; it is an
admissible heuristic. admissible heuristic.
A* on the Romania problem. A* on the Romania problem.

Rimnicu-Vilcea is expanded before Rimnicu-Vilcea is expanded before


Fagaras. Fagaras.
The gain from expanding Rimnicu-Vilcea The gain from expanding Rimnicu-Vilcea
is too small so the A* algorithm is too small so the A* algorithm
backs up and expands Fagaras. backs up and expands Fagaras.
None of the descentants of Fagaras is None of the descentants of Fagaras is
better than a path through Rimnicu- better than a path through Rimnicu-
Vilcea; the algorithm goes back to Vilcea; the algorithm goes back to
Rimnicu-Vilcea and selects Pitesti. Rimnicu-Vilcea and selects Pitesti.

The final path cost = 418 km The final path cost = 418 km
This is the optimal solution. This is the optimal solution.

Romania problem: A* Theorem: A* tree-search is optimal


Initial state: Arad A and B are two nodes on the
Find the minimum
fringe.
Op

distance path to
ti m

Bucharest. A is a suboptimal goal node


al
pa

B and B is a node on the


th

optimal path.
A Optimal path cost = C

The optimal solution


Path cost = 418 km

Theorem: A* tree-search is optimal Theorem: A* tree-search is optimal


A and B are two nodes on the A and B are two nodes on the
fringe. fringe.
Op

Op
ti m

ti m

A is a suboptimal goal node A is a suboptimal goal node


al

al
pa

pa

B and B is a node on the B and B is a node on the


th

th

optimal path. optimal path.


A Optimal path cost = C A Optimal path cost = C
h(A) = 0

f ( A) = g ( A) + h( A) = g ( A) > C f ( A) = g ( A) + h( A) = g ( A) > C
f ( B ) = g ( B ) + h( B ) C f ( B ) = g ( B ) + h( B ) C
h(n) is admissive heuristic No suboptimal goal node will be selected before the optimal goal node

4
A* graph search with consistent
Is A* graph-search optimal?
heuristic is optimal
Previous proof works only for tree-search Theorem:
For graph-search we add the requirement If the consistency condition on h(n) is
of consistency (monotonicity): satisfied, then when A* expands a node n,
m it has already found an optimal path to n.
h ( n ) c ( n, m ) + h ( m )
h(m)
c(n,m)

n h(n) goal
This follows from the fact that consistency
means that f(n) is nondecreasing along a
c(n,m) = step cost for going from node n to path in the graph
node m (n comes before m) f ( m ) = g ( m ) + h ( m ) = g ( n ) + c ( n, m ) + h ( m ) g ( n ) + h ( n ) = f ( n )
if m comes after n along a path

Proof Proof
A* has reached node m along the A* has reached node m along the
alternative path B. alternative path B.

Path A is the optimal path to node m. Path A is the optimal path to node m.
A A
gA(m) gB(m) gA(m) gB(m)
B Node n precedes m along the optimal B Node n precedes m along the optimal
n path A. n path A.
fA(n) fA(m) fA(n) fA(m)
O

O
pt

pt
im

im
al

al
p

p
at

at

m m
Both n and m are on the fringe and Both n and m are on the fringe and
h

A* is about to expand m. A* is about to expand m.


fB(m) fA(n) fB(m) fA(n)

Proof A*
f B ( m) = g B ( m) + h( m) g A ( n) + h( n) = f A ( n ) Optimal
h(n) c A ( n, m) + h(m)
Complete
A
Optimally efficient
g B (m) g A (n) + c A (n, m) = g A (m)
B (no algorithm expands fewer nodes)
n Memory requirement exponential...(bad)
O

But path A is optimal to reach m why


pt
im

gA(m) gB(m)
al
p at

m
A* expands all nodes with f(n) < C
h

Thus, either m = n or contradiction. A* expands some nodes with f(n) = C


A* graph-search with consistent heuristic always finds the optimal path

5
Romania problem: A* Romania problem: A*
Initial state: Arad Initial state: Arad Never tested nodes
Find the minimum Find the minimum
distance path to distance path to
Bucharest. Bucharest.

The optimal solution The optimal solution


Path cost = 418 km Path cost = 418 km

Variants of A* Heuristic functions 8-puzzle


Iterative deepening A* (IDA*) (uses f cost) 2 8 3 h1 = The number of
Recursive best-first search (RBFS) 1 6 4
misplaced tiles.

Depth-first but keep track of best f-value so 7 5


h2 = The sum of the
far above. h1 = 5, h2 = 5
distances of the tiles from
their respective goal
Memory-bounded A* (MA*/SMA*) 1 2 3 positions (Manhattan
Drop old/bad nodes when memory gets full. distance).
8 4

7 6 5
Best of these is SMA* Goal state
Both are admissive

A* on 8-puzzle, h1 heuristic

Heuristic functions 8-puzzle


Initial state
Only nodes in shaded
2 8 3 h1 = The number of area are expanded

1 6 4
misplaced tiles. Goal reached
in node #13
7 5

h1 = 5, h2 = 5
Assignment: Expand the first
three levels of the search
1 2 3 tree using A* and the
8 4
heuristic h1.
7 6 5

Goal state

Image from G. F. Luger, Artificial Intelligence (4th ed.) 2002

6
Domination Local search
It is obvious from the definitions that In many problems, one does not care
h1(n) h2(n). about the path only the goal state is of
We say that h2 dominates h1.
interest.
Use local searches that only keep track of
h1 (n) h2 (n) true path cost to node n the last state (saves memory).

All nodes expanded with h2 are also expanded


with h1 (but not vice versa). Thus, h2 is better.

Example: N-queens Hill-climbing


From initial state (in N N chessboard), try Current node = ni.
to move to other configurations such that
Grab a neighbor node ni+1 and move there
the number of conflicts is reduced.
if it improves things, i.e.
if f = f(ni) - f(ni+1) > 0

Simulated annealing
Current node = ni.
Grab a neighbor node ni+1 and move there
if there is improvement or if the decrease
is small in relation to the temperature.
Accept the move with probability p
p = min[1, exp( f / T )]
Heuristic: Number of pairs of queens that threat each other. (This is a common and useful algorithm)
Best moves are marked.
Yields Boltzmann statistics
f (t + 1) = f (t ) + f (t )

7
Local beam search Genetic algorithms
Start with k random states Start with k random states
Expand all k states and test their children Selective breeding by mating the best
states. states (with mutation)
Keep the k best children states
Repeat until goal state is found