Informed Search I (Beginning of AIMA Chapter 4.1) CIS 391 Fall 2008
Today!! Outline A* - Optimal Search using Knowledge PART 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
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
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
Breadth first in a world with obstacles CIS 391 - Intro to AI
Informed search in a world with obstacles CIS 391 - Intro to AI
Is Uniform Cost Search the best we can do Is Uniform Cost Search the best we can do? Consider finding a route from Bucharest to Arad.. Arad 118 CIS 391 - Intro to AI
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
Romania with city-to-city distances & straight-line distances in km Arad 118 Romania with city-to-city distances & straight-line distances in km CIS 391 - Intro to AI
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
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
Greedy best-first search example Open queue: Arad Initial State = Arad Goal State = Bucharest CIS 391 - Intro to AI
Greedy best-first search example Open queue: Sibiu Timisoara Zerind CIS 391 - Intro to AI
Greedy best-first search example Open queue: Fararas Rimnicu Vilcea Timisoara Arad Zerind Oradea CIS 391 - Intro to AI
Greedy best-first search example Open queue: Bucharest Rimnicu Vilcea Timisoara Sibiu Arad Zerind Oradea Goal reached !! CIS 391 - Intro to AI
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
Properties of greedy best-first search Complete? No – can get stuck in loops, e.g., Iasi Neamt Iasi Neamt … Initial Goal CIS 391 - Intro to AI
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
A* search Implementation: Expand the node n with minimum f(n) 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
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: h(n) h*(n) where h*(n) is the true cost from n 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
A* search example Open 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
A* search example We add the three nodes we found to the open 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
A* search example Open 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
A* search example Open 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
A* search example We expand Rimricu Vicea. Open queue: Fagaras Pitesti Timisoara Zerind Craiova Sibiu Arad Oradea We expand Rimricu Vicea. CIS 391 - Intro to AI
A* search example Open 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
A* search example Open queue: Pitesti Timisoara Zerind Bucharest Craiova 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
A* search example Open queue: Pitesti Timisoara Zerind Bucharest Craiova Sibiu Arad Oradea It looks like Pitesti is the next node we should expand. CIS 391 - Intro to AI
A* search example Open queue: Bucharest Timisoara Zerind Craiova Rimricu Vicea Sibiu 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
A* search example Open queue: Bucharest Timisoara Zerind Craiova Rimricu Vicea Sibiu Arad Oradea Now it looks like Bucharest is at the top of the open queue… CIS 391 - Intro to AI
A* search example Now we “expand” the node for Bucharest. Open queue: Bucharest Timisoara Zerind Craiova Rimricu Vicea Sibiu Arad Oradea Now we “expand” the node for Bucharest. We’re done! (And we know the path that we’ve found is optimal.) CIS 391 - Intro to AI