Learning Objectives At the end of the class you should be able to: define a directed graph represent a problem as a state-space graph explain how a generic searching algorithm works � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 1
Searching Often we are not given an algorithm to solve a problem, but only a specification of what is a solution — we have to search for a solution. A typical problem is when the agent is in one state, it has a set of deterministic actions it can carry out, and wants to get to a goal state. Many AI problems can be abstracted into the problem of finding a path in a directed graph. Often there is more than one way to represent a problem as a graph. � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 2
State-space Search flat or modular or hierarchical explicit states or features or individuals and relations static or finite stage or indefinite stage or infinite stage fully observable or partially observable deterministic or stochastic dynamics goals or complex preferences single agent or multiple agents knowledge is given or knowledge is learned perfect rationality or bounded rationality � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 3
Directed Graphs A graph consists of a set N of nodes and a set A of ordered pairs of nodes, called arcs . Node n 2 is a neighbor of n 1 if there is an arc from n 1 to n 2 . That is, if � n 1 , n 2 � ∈ A . A path is a sequence of nodes � n 0 , n 1 , . . . , n k � such that � n i − 1 , n i � ∈ A . The length of path � n 0 , n 1 , . . . , n k � is k . Given a set of start nodes and goal nodes, a solution is a path from a start node to a goal node. � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 4
Example Problem for Delivery Robot The robot wants to get from outside room 103 to the inside of room 123. r131 r129 r127 r125 r123 r121 r119 storage o129 o131 o127 o125 o123 o121 o119 r117 d1 o117 d2 c1 c2 c3 d3 o115 r115 b1 a1 b2 o113 r113 b3 b4 a2 a3 o101 o103 mail ts o105 o107 o109 o111 main stairs r101 r103 r105 r107 r109 r111 office � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 5
State-Space Graph for the Delivery Robot r123 storage 7 4 4 9 o125 o123 o119 c1 8 4 6 c2 c3 16 3 6 b1 b2 3 4 7 b3 b4 7 4 o111 4 6 8 12 mail ts o103 o109 � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 6
Partial Search Space for a Video Game Grid game: Rob needs to collect coins C 1 , C 2 , C 3 , C 4 , without running out of fuel, and end up at location (1 , 1): Fuel 9 Rob 8 7 C3 4 5 . � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 7
Partial Search Space for a Video Game Grid game: Rob needs to collect coins C 1 , C 2 , C 3 , C 4 , without running out of fuel, and end up at location (1 , 1): 9 Fuel 〈 5,8,6,f,t,f,f 〉 Rob 8 〈 5,9,5,f,t,f,f 〉 〈 5,7,5,f,t,t,f 〉 〈 6,8,5,f,t,f,f 〉 7 C3 〈 5,8,4,f,t,t,f 〉 〈 4,9,20,f,t,f,f 〉 4 5 〈 5,8,4,f,t,f,f 〉 〈 5,9,19,f,t,f,f 〉 State: Goal: 〈 X-pos,Y-pos,Fuel,C1,C2,C3,C4 〉 〈 1,1,?,t,t,t,t 〉 � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 8
Graph Searching Generic search algorithm: given a graph, start nodes, and goal nodes, incrementally explore paths from the start nodes. Maintain a frontier of paths from the start node that have been explored. As search proceeds, the frontier expands into the unexplored nodes until a goal node is encountered. The way in which the frontier is expanded defines the search strategy. � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 9
Problem Solving by Graph Searching ends of paths on frontier start node explored nodes unexplored nodes � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 10
Graph Search Algorithm Input: a graph, a set of start nodes, Boolean procedure goal ( n ) that tests if n is a goal node. frontier := {� s � : s is a start node } ; while frontier is not empty: select and remove path � n 0 , . . . , n k � from frontier ; if goal ( n k ) return � n 0 , . . . , n k � ; for every neighbor n of n k add � n 0 , . . . , n k , n � to frontier ; end while � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 11
Which value is selected from the frontier at each stage defines the search strategy. The neighbors define the graph. goal defines what is a solution. If more than one answer is required, the search can continue from the return. � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.1, Page 12
Learning Objectives At the end of the class you should be able to: demonstrate how depth-first search will work on a graph demonstrate how breadth-first search will work on a graph predict the space and time requirements for depth-first and breadth-first searches � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 1
Depth-first Search Depth-first search treats the frontier as a stack It always selects one of the last elements added to the frontier. If the list of paths on the frontier is [ p 1 , p 2 , . . . ] ◮ p 1 is selected. Paths that extend p 1 are added to the front of the stack (in front of p 2 ). ◮ p 2 is only selected when all paths from p 1 have been explored. � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 2
Illustrative Graph — Depth-first Search 1 2 3 13 4 12 14 5 7 15 16 6 8 10 9 11 � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 3
Which shaded goal will a depth-first search find first? Q W R T Y U V � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 4
Complexity of Depth-first Search Does depth-first search guarantee to find the shortest path or the path with fewest arcs? What happens on infinite graphs or on graphs with cycles if there is a solution? What is the time complexity as a function of length of the path selected? What is the space complexity as a function of length of the path selected? How does the goal affect the search? � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 5
Breadth-first Search Breadth-first search treats the frontier as a queue. It always selects one of the earliest elements added to the frontier. If the list of paths on the frontier is [ p 1 , p 2 , . . . , p r ]: ◮ p 1 is selected. Its neighbors are added to the end of the queue, after p r . ◮ p 2 is selected next. � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 6
Illustrative Graph — Breadth-first Search 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 7
Complexity of Breadth-first Search Does breadth-first search guarantee to find the shortest path or the path with fewest arcs? What happens on infinite graphs or on graphs with cycles if there is a solution? What is the time complexity as a function of the length of the path selected? What is the space complexity as a function of the length of the path selected? How does the goal affect the search? � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 8
Which shaded goal will a breadth-first search find first? Q W R T Y U V � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 9
Lowest-cost-first Search Sometimes there are costs associated with arcs. The cost of a path is the sum of the costs of its arcs. k � cost ( � n 0 , . . . , n k � ) = |� n i − 1 , n i �| i =1 An optimal solution is one with minimum cost. At each stage, lowest-cost-first search selects a path on the frontier with lowest cost. The frontier is a priority queue ordered by path cost. It finds a least-cost path to a goal node. When arc costs are equal = ⇒ breadth-first search. � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 10
Summary of Search Strategies Strategy Frontier Selection Complete Halts Space Depth-first Last node added Breadth-first First node added Lowest-cost-first Minimal cost ( p ) Complete — if there a path to a goal, it can find one, even on infinite graphs. Halts — on finite graph (perhaps with cycles). Space — as a function of the length of current path � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 11
Summary of Search Strategies Strategy Frontier Selection Complete Halts Space Depth-first Last node added No No Linear Breadth-first First node added Yes No Exp Lowest-cost-first Minimal cost ( p ) Yes No Exp Complete — if there a path to a goal, it can find one, even on infinite graphs. Halts — on finite graph (perhaps with cycles). Space — as a function of the length of current path � D. Poole and A. Mackworth 2010 c Artificial Intelligence, Lecture 3.2, Page 12
Recommend
More recommend