1CS 188: Artificial IntelligenceFall 2009Lecture 2: Queue-Based Search9/1/2009Dan Klein – UC BerkeleyMultiple slides from Stuart Russell, Andrew Moore Announcements Project 0: Python Tutorial Due tomorrow! There is a lab tomorrow from 1pm-3pm in Soda 275 The lab time is optional, but P0 itself is not On submit, you should get email from the autograder Project 1: Search On the web today Start early and ask questions. It’s longer than most! Other Section 107 was opened up, Fridays 1-2pm My OHs Monday were in the lab, Thursday back in 711 Soda GSI OHs on web site2Today Agents that Plan Ahead Search Problems Uninformed Search Methods (part review for some) Depth-First Search Breadth-First Search Uniform-Cost Search Heuristic Search Methods (new for all) Greedy SearchReflex Agents Reflex agents: Choose action based on current percept (and maybe memory) May have memory or a model of the world’s current state Do not consider the future consequences of their actions Act on how the world IS Can a reflex agent be rational?[demo: reflex optimal / loop ]3Goal Based Agents Goal-based agents: Plan ahead Ask “what if” Decisions based on (hypothesized) consequences of actions Must have a model of how the world evolves in response to actions Act on how the world WOULD BE[demo: plan fast / slow ]Search Problems A search problem consists of: A state space A successor function 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“N”, 1.0“E”, 1.04Example: Romania State space: Cities Successor function: Go to adj city with cost = dist Start state: Arad Goal test: Is state == Bucharest? Solution?State Space Graphs State space graph: A mathematical representation of a search problem For every search problem, there’s a corresponding state space graph The successor function is represented by arcs We can rarely build this graph in memory (so we don’t)SGdbpqcehafrRidiculously tiny search graph for a tiny search problem5State Space Sizes? Search Problem:Eat all of the food Pacman positions:10 x 12 = 120 Food count: 30 Ghost positions: 12 Pacman facing:up, down, left, rightSearch Trees A search tree: This is a “what if” tree of plans and outcomes Start state at the root node Children correspond to successors Nodes contain states, correspond to PLANS to those states For most problems, we can never actually build the whole tree“E”, 1.0“N”, 1.06Another Search Tree Search: Expand out possible plans Maintain a fringe of unexpanded plans Try to expand as few tree nodes as possibleGeneral Tree Search Important ideas: Fringe Expansion Exploration strategy Main question: which fringe nodes to explore?Detailed pseudocode is in the book!7Example: Tree SearchSGdbpqcehafrState Graphs vs. Search TreesSabdpacephfrqq cGaqephfrqq cGaSGdbpqcehafrWe construct both on demand – and we construct as little as possible.Each NODE in in the search tree is an entire PATH in the problem graph.8States vs. Nodes Nodes in state space graphs are problem states Represent an abstracted state of the world Have successors, can be goal / non-goal, have multiple predecessors Nodes in search trees are plans Represent a plan (sequence of actions) which results in the node’s state Have a problem state and one parent, a path length, a depth & a cost The same problem state may be achieved by multiple search tree nodesDepth 5Depth 6ParentNodeSearch NodesProblem StatesActionReview: Depth First SearchSabdpacephfrqq cGaqephfrqq cGaSGdbpqcehafrqphfdbacerStrategy: expand deepest node firstImplementation: Fringe is a LIFO stack9Review: Breadth First SearchSabdpacephfrqq cGaqephfrqq cGaSGdbpqcehafrSearchTiersStrategy: expand shallowest node firstImplementation: Fringe is a FIFO queueSearch 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 problemb The average branching factor B(the average number of successors)C* Cost of least cost solutions Depth of the shallowest solutionm Max depth of the search tree10DFS Infinite paths make DFS incomplete… How can we fix this?Algorithm Complete Optimal Time SpaceDFSDepth First SearchN NO(BLMAX) O(LMAX)STARTGOALabN N Infinite InfiniteDFS With cycle checking, DFS is complete.* When is DFS optimal?Algorithm Complete Optimal Time SpaceDFSw/ Path CheckingY NO(bm+1) O(bm)…b1 nodeb nodesb2nodesbmnodesm tiers* Or graph search – next lecture.11BFS When is BFS optimal?Algorithm Complete Optimal Time SpaceDFSw/ Path CheckingBFSY NO(bm+1) O(bm)…b1 nodeb nodesb2nodesbmnodess tiersY N*O(bs+1) O(bs)bsnodesComparisons When will BFS outperform DFS? When will DFS outperform BFS?12Iterative DeepeningIterative deepening uses DFS as a subroutine:1. Do a DFS which only searches for paths of length 1 or less. 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 Complete Optimal Time SpaceDFSw/ Path CheckingBFSIDY NO(bm+1) O(bm)Y N*O(bs+1) O(bs)Y N*O(bs+1) O(bs)…bCosts on ActionsNotice 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. STARTGOALdbpqcehafr2928182314415132213Uniform Cost SearchSabdpacephfrqq cGaqephfrqq cGaExpand cheapest node first:Fringe is a priority queueSGdbpqcehafr39116411571381011171106391128811512Cost contours2Priority Queue Refresherpq.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 decrease a key’s priority by pushing it again Unlike a regular queue, insertions aren’t constant time, usually O(log n) We’ll need priority queues for cost-sensitive search methods A priority queue is a data structure in which you can insert and retrieve (key, value) pairs with the following operations:14Uniform Cost SearchAlgorithm Complete Optimal Time SpaceDFSw/ Path CheckingBFSUCSY NO(bm+1) O(bm)…bC*/εtiersY NO(bs+1) O(bs)Y* YO(bC*/ε) O(bC*/ε)* UCS can fail
View Full Document