Post on 17-Jan-2016
Informed Search I (Beginning of AIMA Chapter 4.1)
CIS 391
Fall 2008
CIS 391 - Intro to AI 2
OutlinePART I Informed = use problem-specific knowledge Best-first search and its variants A* - Optimal Search using Knowledge
Proof of Optimality of A* A* for maneuvering AI agents in games Heuristic functions? How to invent them
PART II Local search and optimization
• Hill climbing, local beam search, genetic algorithms,… Local search in continuous spaces Online search agents
Today!!
CIS 391 - Intro to AI 3
Breadth First Search for Games, Robots, …
Pink: Starting Point Blue: Goal Teal: Scanned squares
• Darker: Closer to starting point…
Graphics from http://theory.stanford.edu/~amitp/GameProgramming/
(A great site for practical AI & game Programming
CIS 391 - Intro to AI 4
An optimal informed search algorithm
We add a heuristic estimate of distance to the goal
Yellow: examined nodes with high estimated distance Blue: examined nodes with low estimated distance
CIS 391 - Intro to AI 5
Breadth first in a world with obstacles
CIS 391 - Intro to AI 6
Informed search in a world with obstacles
CIS 391 - Intro to AI 7
Is Uniform Cost Search the best we can do? Consider finding a route from Bucharest to Arad..
Arad
118
CIS 391 - Intro to AI 8
A Better Idea… Node expansion based on some estimate of distance to
the goal, extending current path
General approach of informed search:• Best-first search: node is selected for expansion based on an
evaluation function f(n)
Implementation:• Sort fringe queue in decreasing order of desirability.
• Special cases: greedy search, A* search
CIS 391 - Intro to AI 9
Arad
118
Romania with city-to-city distances & straight-line distances in km
CIS 391 - Intro to AI 10
A heuristic function
Let evaluation function f(n) = h(n) (heuristic)• h(n) = estimated cost of the cheapest path from node n to
goal node.• If n is goal then h(n)=0
Here: hSLD(n) = straight-line distance from n to Bucharest
[dictionary]“A rule of thumb, simplification, or educated guess that reduces or limits the search for solutions in domains that are difficult and poorly understood.”
Heuristic knowledge is useful, but not necessarily correct.Heuristic algorithms use heuristic knowledge to solve a problem.A heuristic function here takes a state and returns an estimate of the distance to the goal.
Heureka! ---Archimedes
CIS 391 - Intro to AI 11
Greedy best-first search (BFS)
Expands the node that appears to be closest to goal
Expands nodes based on f(n) = h(n)• (Again, h(n)): Some heuristic estimate of cost from n to goal)
Ignores cost so far to get to that node (g(n)) Here, h(n) = hSLD(n) = straight-line distance from n
to Bucharest
CIS 391 - Intro to AI 12
Greedy best-first search example
Initial State = Arad Goal State = Bucharest
Open queue:
Arad
CIS 391 - Intro to AI 13
Greedy best-first search exampleOpen queue:
Sibiu
Timisoara
Zerind
CIS 391 - Intro to AI 14
Greedy best-first search exampleOpen queue:
Fararas
Rimnicu Vilcea
Timisoara
Arad
Zerind
Oradea
CIS 391 - Intro to AI 15
Greedy best-first search example
Goal reached !!
Open queue:
Bucharest
Rimnicu Vilcea
Timisoara
Sibiu
Arad
Zerind
Oradea
CIS 391 - Intro to AI 16
Properties of greedy best-first search
Optimal? • No!
—Found: Arad Sibiu Fagaras Bucharest (450km) —Shorter: Arad Sibiu Rimnicu Vilcea Pitesti Bucharest (418km)
Arad
118
CIS 391 - Intro to AI 17
Properties of greedy best-first search Complete?
• No – can get stuck in loops,
• e.g., Iasi Neamt Iasi Neamt …
GoalInitial
CIS 391 - Intro to AI 18
Properties of greedy best-first search
Complete? • No – can get stuck in loops, • e.g., Iasi Neamt Iasi Neamt
Time? • O(bm) – worst case (like Depth First Search)• But a good heuristic can give dramatic improvement
Space? • O(bm) – keeps all nodes in memory
Optimal? No
CIS 391 - Intro to AI 19
A* search
Best-known form of best-first search. Key Idea: avoid expanding paths that are already
expensive. Evaluation function f(n)=g(n) + h(n)
• g(n) the cost (so far) to reach the node
• h(n) estimated cost to get from the node to the goal
• f(n) estimated total cost of path through n to goal
Implementation: Expand the node n with minimum f(n)
CIS 391 - Intro to AI 20
Admissible heuristics
h(n) must be an admissible heuristic • A heuristic is admissible if it never overestimates
the cost to reach the goal; i.e. it is optimistic• Formally:
n, where n is a node:
1. h(n) h*(n) where h*(n) is the true cost from n
2. h(n) 0 so h(G)=0 for any goal G.
• Example:
hSLD(n) never overestimates the actual road
distance
Theorem: If h(n) is admissible, A* using Tree Search is optimal
CIS 391 - Intro to AI 21
A* search exampleOpen queue:
Arad
We start with our initial state Arad. We make a node and add it to the open queue. Since it’s the only thing on the open queue, we expand the node.
Implementation: The open queue is just a priority queue (or heap) that sorts the nodes inside of it according to their g()+h() score.
CIS 391 - Intro to AI 22
A* search exampleOpen queue:
Sibiu
Timisoara
Zerind
We add the three nodes we found to the open queue.
We sort them according to the g()+h() calculation.
CIS 391 - Intro to AI 23
A* search exampleOpen queue:
Rimricu Vicea
Fagaras
Timisoara
Zerind
Arad
Oradea
When we expand Sibiu, we run into Arad again. Note that we’ve already expanded this node once; but we still add it to the open queue again.
CIS 391 - Intro to AI 24
A* search exampleOpen queue:
Rimricu Vicea
Fagaras
Timisoara
Zerind
Arad
Oradea
We see that Rimricu Vicea is at the top of the open queue; so, it’s the next node we will expand.
CIS 391 - Intro to AI 25
A* search exampleOpen queue:
Fagaras
Pitesti
Timisoara
Zerind
Craiova
Sibiu
Arad
Oradea
We expand Rimricu Vicea.
CIS 391 - Intro to AI 26
A* search exampleOpen queue:
Fagaras
Pitesti
Timisoara
Zerind
Craiova
Sibiu
Arad
Oradea
Fagaras will be the next node we should expand – it’s at the top of the sorted open queue.
CIS 391 - Intro to AI 27
A* search exampleOpen queue:
Pitesti
Timisoara
Zerind
Bucharest
Craiova
Sibiu
Sibiu
Arad
Oradea
When we expand Fagaras, we find Bucharest, but we’re not done. The algorithm doesn’t end until we “expand” the goal node – it has to be at the top of the open queue.
CIS 391 - Intro to AI 28
A* search exampleOpen queue:
Pitesti
Timisoara
Zerind
Bucharest
Craiova
Sibiu
Sibiu
Arad
Oradea
It looks like Pitesti is the next node we should expand.
CIS 391 - Intro to AI 29
A* search exampleOpen queue:
Bucharest
Timisoara
Zerind
Bucharest
Craiova
Rimricu Vicea
Sibiu
Sibiu
Craiova
Arad
Oradea
Note that we just found a better value for Bucharest! We also found a worse value for Craiova.
CIS 391 - Intro to AI 30
A* search exampleOpen queue:
Bucharest
Timisoara
Zerind
Bucharest
Craiova
Rimricu Vicea
Sibiu
Sibiu
Craiova
Arad
Oradea
Now it looks like Bucharest is at the top of the open queue…
CIS 391 - Intro to AI 31
A* search exampleOpen queue:
Bucharest
Timisoara
Zerind
Bucharest
Craiova
Rimricu Vicea
Sibiu
Sibiu
Craiova
Arad
Oradea
Now we “expand” the node for Bucharest.
We’re done! (And we know the path that we’ve found is optimal.)