Unformatted text preview:

Lecture 12 Search Algorithms Ef cient algorithms for searching underlie many of computer science s biggest successes Check Yourself Search Correct answer How many different board con gurations states exist Search Algorithms Develop an algorithm to systematically conduct search Analyze how well the algorithm performs Optimize the algorithm Find the best solution by considering as few cases as possible We can represent all possible paths with a tree Python representation of the grid Represent the grid as a n instance of class Grid Represent locations as tuples r c where r is row and c is column class Grid def init self width height start goal self width width self height height self start start self goal goal grid Grid 3 3 0 0 2 2 Represent each node in the tree as an instance of Search Node class SearchNode def init self state parent cost 0 0 self state state self parent parent def path self p node self while node p append node state node node parent return p 1 Search Trees Construct a tree and nd a path to the goal Algorithm Initialize agenda meaning the list of nodes to consider to contain starting node Repeat the following steps until goal is found or agenda is empty Remove one node from the agenda Add that node s successors to the agenda Return resulting path Varieties of Search Depth First Search DFS Replace last node by its successors implement with stack last in rst out work down on branch of the tree before moving to another branch Breadth First Search BFS Remove rst node from agenda and add its successors to the end of the agenda Implement with queue rst in rst out Consider all path of length n before paths of length n 1 Pruning Prune the tree to reduce the amount of work Pruning Strategy One Don t consider paths that visit the same state twice Check Yourself Pruning Correct answer How many of these terminal nodes can be ignored Dynamic Programming Principle The shortest path from X to Z that goes through Y is made up of the shortest path from X to Y and the shortest path from Y to Z Breadth First The rst path that BFS nd from start to X is the shortest path from start to X Pruning Technique Don t consider any path that visits the state that you have already visited via some other path Algorithm Initialize visited set Initialize agenda to contain starting node Repeat the following steps unit goal is found or agenda is empty Remove one node from the agenda For each of the node s children if the child is not in the visited set add the child to the visited set Return resulting path Search in lib601 lib601 contains a procedure called search which takes arguments successors function that takes a state and returns a list of successor states StartState the state from which to start the search goalTest a function that takes a state and returns True if that state satis es the goal condition and False otherwise dfs boolean if True run a depth rst search if False run a breadth rst search search returns a list of states from the root of the tree to the goal or None if no path exists Casting Examples Scenario 1 Lonely Robot in A Grid One robot in a grid world which we want to move to some goal location Which of the following state representations allow us to solve this problem using graph search 1 A number d representing the robot s distance from the goal 2 A tuple x y representing the robot s position 3 A tuple x y d containing the robot s position and distance from the goal 4 A list of tuples x0 y0 xn yn representing the robot s path from the starting point to its current position Scenario 2 The Scenic Route One robot in a grid world Want to plan a path such that the robot visits every location Which of the following state representations allow us to solve this problem using graph search 1 A tuple x y representing the robot s position 2 A list of tuples x0 y0 xn yn representing the robot s path from the starting point to its current position 3 A 2 D array of booleans representing whether the robot has visited each location 4 A 2 D array of booleans representing whether the robot has visited each location plus a tuple x y representing the robot s current location Scenario 3 Flash Mob N robots in a grid world Each of the N robots has its own goal want to plan paths such that all robots arrive at their goals Which of the following state representations allow us to solve this problem using graph search 1 N tuples one to represent each robot s position 2 N booleans each representing whether a certain robot is at its goal 3 A 2 D array of integers representing how many robots are in each location 4 N numbers each representing a certain robot s distance to its goal Summary Developed depth rst search Developed breadth rst search Discussed the bene ts and drawbacks of each Developed pruning rules Saw examples of casting problems as searches over graphs


View Full Document

MIT 6 01 - Lecture 12

Documents in this Course
Week 1

Week 1

3 pages

Op-Amps

Op-Amps

8 pages

Op-Amps

Op-Amps

6 pages

Syllabus

Syllabus

14 pages

Planning

Planning

14 pages

Load more
Download Lecture 12
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 12 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 12 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?