320 likes | 471 Views
Informed Search I (Beginning of AIMA Chapter 4.1). CIS 391 Fall 2008. Outline. 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?
E N D
Informed Search I (Beginning of AIMA Chapter 4.1) CIS 391 Fall 2008
Outline 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!!
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
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
Is Uniform Cost Search the best we can do? Consider finding a route from Bucharest to Arad.. Arad 118
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
Arad 118 Romania with city-to-city distances & straight-line distances in km
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 thenh(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
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
Greedy best-first search example Open queue: Arad • Initial State = Arad • Goal State = Bucharest
Greedy best-first search example Open queue: Sibiu Timisoara Zerind
Greedy best-first search example Open queue: Fararas Rimnicu Vilcea Timisoara Arad Zerind Oradea
Greedy best-first search example Open queue: Bucharest Rimnicu Vilcea Timisoara Sibiu Arad Zerind Oradea Goal reached !!
Arad 118 Properties of greedy best-first search • Optimal? • No! • Found: Arad Sibiu Fagaras Bucharest (450km) • Shorter: Arad Sibiu Rimnicu Vilcea Pitesti Bucharest (418km)
Properties of greedy best-first search • Complete? • No – can get stuck in loops, • e.g., Iasi Neamt Iasi Neamt … Initial Goal
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
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 nwith minimum f(n)
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
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.
A* search example 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.
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.
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.
A* search example Open queue: Fagaras Pitesti Timisoara Zerind Craiova Sibiu Arad Oradea We expand Rimricu Vicea.
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.
A* search example Open 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.
A* search example Open queue: Pitesti Timisoara Zerind Bucharest Craiova Sibiu Sibiu Arad Oradea It looks like Pitesti is the next node we should expand.
A* search example Open 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.
A* search example Open 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…
A* search example Open 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.)