CS 188 Artificial Intelligence Fall 2008 Lecture 2 Queue Based Search 9 2 2008 Dan Klein UC Berkeley Many slides from either Stuart Russell or Andrew Moore Announcements Written assignments One mini homework each week 1 2 problems We ll drop your two lowest scores First one posted soon Lab Wednesday 11am to 4pm in Soda 275 Learn Python Come whatever times you like Project 1 1 posted soon too due 9 12 Today Agents that Plan Ahead Search Problems Uniformed Search Methods Depth First Search Breadth First Search Uniform Cost Search Heuristic Search Methods Greedy Search A Search Reflex Agents Reflex agents Choose action based on current percept and memory May have memory or a model of the world s current state Do not consider the future consequences of their actions Can a reflex agent be rational demo reflex optimal loop Goal Based Agents Goal based agents Plan ahead Decisions based on hypothesized consequences of actions Must have a model of how the world evolves in response to actions demo plan fast slow Search Problems A search problem consists of A state space A successor function N 1 0 E 1 0 A start state and a goal test A solution is a sequence of actions a plan which transforms the start state to a goal state Search Trees N 1 0 E 1 0 A search tree This is a what if tree of plans and outcomes Start state at the root node Children correspond to successors Nodes labeled with states correspond to PLANS to those states For most problems can never actually build the whole tree So have to find ways of using only the important parts of the tree State Space Graphs There s some big graph in which G a Each state is a node Each successor is an outgoing arc c b e d Important For most problems we could never actually build this graph How many states in Pacman f S h p q Laughably tiny search graph for a tiny search problem r Example Romania Another Search Tree Search Expand out possible plans Maintain a fringe of unexpanded plans Try to expand as few tree nodes as possible General Tree Search Important ideas Fringe Expansion Exploration strategy Detailed pseudocode is in the book Main question which fringe nodes to explore Example Tree Search G a c b e d S f h p q r State Graphs vs Search Trees G a Each NODE in in the search tree is an entire PATH in the problem graph c b e d S f h p r q S e d We almost always construct both on demand and we construct as little as possible b c a a h e h p q q c a r p f q G p q r q f c a G Review Depth First Search G a Strategy expand deepest node first c b e d Implementation Fringe is a LIFO stack S f h p r q S e d b c a a e h p q q c a h r p f q G p q r q f c a G Review Breadth First Search G a Strategy expand shallowest node first c b e d Implementation Fringe is a FIFO queue S f h p r q S e d Search Tiers b c a a h e h p q q c a r p f q G p q r q f c a G Search Algorithm Properties Complete Guaranteed to find a solution if one exists Optimal Guaranteed to find the least cost path Time complexity Space complexity Variables n Number of states in the problem b The average branching factor B the average number of successors C Cost of least cost solution s Depth of the shallowest solution m Max depth of the search tree DFS Algorithm Complete Optimal Time Space DFS N LMAX O B Infinite O LMAX Infinite Depth First Search N N N b START a GOAL Infinite paths make DFS incomplete How can we fix this DFS With cycle checking DFS is complete 1 node b b nodes b2 nodes m tiers bm nodes Algorithm DFS w Path Checking Complete Optimal Y N When is DFS optimal Time O bm 1 Space O bm BFS Algorithm DFS w Path Checking BFS Complete Optimal Y N O bm 1 O bm Y N O bs 1 O bs s tiers b Time Space 1 node b nodes b2 nodes bs nodes bm nodes When is BFS optimal Comparisons When will BFS outperform DFS When will DFS outperform BFS Iterative Deepening Iterative deepening uses DFS as a subroutine 1 Do a DFS which only searches for paths of length 1 or less DFS gives up on any path of length 2 2 If 1 failed do a DFS which only searches paths of length 2 or less 3 If 2 failed do a DFS which only searches paths of length 3 or less and so on Algorithm DFS w Path Checking Complete Optimal Time b Space Y N O bm 1 O bm BFS Y N O bs 1 O bs ID Y N O bs 1 O bs Costs on Actions GOAL a 2 2 c b 1 3 2 8 2 e d 3 9 8 START p 15 2 h 4 1 f 4 q 1 r Notice that BFS finds the shortest path in terms of number of transitions It does not find the least cost path We will quickly cover an algorithm which does find the least cost path Uniform Cost Search 2 b Expand cheapest node first b 4 c a 6 a 9 h 17 r 11 e 5 11 p 15 e 3 d p h 13 r 7 p f 8 q q q 11 c a G 10 2 9 2 e h 8 q f c a G f 1 1 r q 0 S Cost contours d S 1 c 8 1 3 Fringe is a priority queue G a p 1 q 16 Priority Queue Refresher A priority queue is a data structure in which you can insert and retrieve key value pairs with the following operations pq push key value inserts key value into the queue pq pop returns the key with the lowest value and removes it from the queue You can promote or demote keys by resetting their priorities Unlike a regular queue insertions into a priority queue are not constant time usually O log n We ll need priority queues for most cost sensitive search methods Uniform Cost Search Algorithm DFS w Path Checking Complete Optimal Time Space Y N O bm 1 O bm BFS Y N O bs 1 O bs UCS Y Y O C bC O bC C tiers b We ll talk more about uniform cost search s failure cases later Uniform Cost Problems Remember explores increasing cost contours c 1 c 2 c 3 The good UCS is complete and optimal The bad Explores options in every direction No information about goal location Start Goal demo ucs contours Heuristics …
View Full Document