Recap Breadth-First Search Search with Costs Heuristic Search Best-First Search. Heuristic Search. CPSC 322 Lecture 6. January 19, 2007 Textbook 2.

Similar documents
AI: A Modern Approach, Chpts. 3-4 Russell and Norvig

Informed search algorithms. Chapter 4, Sections 1 2 1

An Introduction to The A* Algorithm

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Seminar. Path planning using Voronoi diagrams and B-Splines. Stefano Martina

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Degeneracy in Linear Programming

SIMS 255 Foundations of Software Design. Complexity and NP-completeness

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

2. Length and distance in hyperbolic geometry

Computational Geometry. Lecture 1: Introduction and Convex Hulls

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

Analysis of Micromouse Maze Solving Algorithms

Decision Mathematics 1 TUESDAY 22 JANUARY 2008

Binary Search Trees CMPSC 122

WAN Wide Area Networks. Packet Switch Operation. Packet Switches. COMP476 Networked Computer Systems. WANs are made of store and forward switches.

Data Structure [Question Bank]

Cpt S 223. School of EECS, WSU

(Refer Slide Time: 2:03)

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

CSE 326: Data Structures B-Trees and B+ Trees

Binary Adders: Half Adders and Full Adders

New Admissible Heuristics for Domain-Independent Planning

From Last Time: Remove (Delete) Operation

Linear Programming. Solving LP Models Using MS Excel, 18

The number of marks is given in brackets [ ] at the end of each question or part question. The total number of marks for this paper is 72.

Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four

SUPPLY CHAIN OPTIMIZATION MODELS IN THE AREA OF OPERATION

Electrical Fundamentals Module 3: Parallel Circuits

International Journal of Software and Web Sciences (IJSWS)

Moving Target Search. 204 Automated Reasoning

West Virginia University College of Engineering and Mineral Resources. Computer Engineering 313 Spring 2010

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

A Strategy for Teaching Finite Element Analysis to Undergraduate Students

Hagit Attiya and Eshcar Hillel. Computer Science Department Technion

A Note on Maximum Independent Sets in Rectangle Intersection Graphs

Midterm Practice Problems

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi

Kenken For Teachers. Tom Davis June 27, Abstract

Session 6 Number Theory

Linear Programming Notes V Problem Transformations

Learning Example. Machine learning and our focus. Another Example. An example: data (loan application) The data and the goal

Data Structures and Algorithms Written Examination

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

Class Notes CS Creating and Using a Huffman Code. Ref: Weiss, page 433

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

Dynamic programming formulation

Dynamic Programming. Lecture Overview Introduction

Representing Vector Fields Using Field Line Diagrams

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. #-approximation algorithm.

Strong and Weak Ties

Data Structures Fibonacci Heaps, Amortized Analysis

Reasoning Under Uncertainty: Variable Elimination Example

Minimum cost maximum flow, Minimum cost circulation, Cost/Capacity scaling

Survey On: Nearest Neighbour Search With Keywords In Spatial Databases

CMPSCI611: Approximating MAX-CUT Lecture 20

Scheduling Shop Scheduling. Tim Nieberg

Sample Questions Csci 1112 A. Bellaachia

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Simplex method summary

Problem Set 7 Solutions

Angles and Quadrants. Angle Relationships and Degree Measurement. Chapter 7: Trigonometry

Greedy Routing on Hidden Metric Spaces as a Foundation of Scalable Routing Architectures

Measuring the Performance of an Agent

Y. Xiang, Constraint Satisfaction Problems

Guessing Game: NP-Complete?

Today s topic: So far, we have talked about. Question. Task models

APP INVENTOR. Test Review

Helvetic Coding Contest 2016

Analysis of Algorithms, I

Determine If An Equation Represents a Function

Efficient Data Structures for Decision Diagrams

Data Structures. Chapter 8

Social Media Mining. Graph Essentials

Decision Making under Uncertainty

Tom wants to find two real numbers, a and b, that have a sum of 10 and have a product of 10. He makes this table.

Smart Graphics: Methoden 3 Suche, Constraints

Practical Guide to the Simplex Method of Linear Programming

Lecture 4 Online and streaming algorithms for clustering

Search methods motivation 1

Graph Theory Problems and Solutions

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

Simplified External memory Algorithms for Planar DAGs. July 2004

Lab 7: Operational Amplifiers Part I

6.263 Data Communication Networks

BIRCH: An Efficient Data Clustering Method For Very Large Databases

Exam study sheet for CS2711. List of topics

Relevant Reading for this Lecture... Pages

CS MidTerm Exam 4/1/2004 Name: KEY. Page Max Score Total 139

What is Characteristic Impedance?

Chapter 15: Dynamic Programming

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 313]

Data Mining Practical Machine Learning Tools and Techniques

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Vector storage and access; algorithms in GIS. This is lecture 6

Transcription:

Heuristic Search CPSC 322 Lecture 6 January 19, 2007 Textbook 2.5 Heuristic Search CPSC 322 Lecture 6, Slide 1

Lecture Overview 1 Recap 2 Breadth-First Search 3 Search with Costs 4 Heuristic Search 5 Best-First Search Heuristic Search CPSC 322 Lecture 6, Slide 2

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 After the algorithm returns, it can be asked for more answers and the procedure continues. Which value is selected from the frontier defines the search strategy. The neighbor relationship defines the graph. The goal function defines what is a solution. Heuristic Search CPSC 322 Lecture 6, Slide 3

Depth-first Search Depth-first search treats the frontier as a stack It always selects one of the last elements added to the frontier. Complete when the graph has no cycles and is finite Time complexity is O(b m ) Space complexity is O(bm) Heuristic Search CPSC 322 Lecture 6, Slide 4

Lecture Overview 1 Recap 2 Breadth-First Search 3 Search with Costs 4 Heuristic Search 5 Best-First Search Heuristic Search CPSC 322 Lecture 6, Slide 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. Example: the frontier is [p 1, p 2,..., p r ] neighbours of p 1 are {n 1,..., n k } What happens? p 1 is selected, and tested for being a goal. Neighbours of p 1 follow p r at the end of the frontier. Thus, the frontier is now [p 2,..., p r, (p 1, n 1 ),..., (p 1, n k )]. p 2 is selected next. Heuristic Search CPSC 322 Lecture 6, Slide 6

Illustrative Graph Breadth-first Search 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Heuristic Search CPSC 322 Lecture 6, Slide 7

Analysis of Breadth-First Search Is BFS complete? Heuristic Search CPSC 322 Lecture 6, Slide 8

Analysis of Breadth-First Search Is BFS complete? Yes (but it wouldn t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?) Heuristic Search CPSC 322 Lecture 6, Slide 8

Analysis of Breadth-First Search Is BFS complete? Yes (but it wouldn t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?) What is the time complexity, if the maximum path length is m and the maximum branching factor is b? Heuristic Search CPSC 322 Lecture 6, Slide 8

Analysis of Breadth-First Search Is BFS complete? Yes (but it wouldn t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?) What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is O(b m ): must examine every node in the tree. The order in which we examine nodes (BFS or DFS) makes no difference to the worst case: search is unconstrained by the goal. Heuristic Search CPSC 322 Lecture 6, Slide 8

Analysis of Breadth-First Search Is BFS complete? Yes (but it wouldn t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?) What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is O(b m ): must examine every node in the tree. The order in which we examine nodes (BFS or DFS) makes no difference to the worst case: search is unconstrained by the goal. What is the space complexity? Heuristic Search CPSC 322 Lecture 6, Slide 8

Analysis of Breadth-First Search Is BFS complete? Yes (but it wouldn t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?) What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is O(b m ): must examine every node in the tree. The order in which we examine nodes (BFS or DFS) makes no difference to the worst case: search is unconstrained by the goal. What is the space complexity? Space complexity is O(b m ): we must store the whole frontier in memory Heuristic Search CPSC 322 Lecture 6, Slide 8

Using Breadth-First Search When is BFS appropriate? Heuristic Search CPSC 322 Lecture 6, Slide 9

Using Breadth-First Search When is BFS appropriate? space is not a problem it s necessary to find the solution with the fewest arcs although all solutions may not be shallow, at least some are there may be infinite paths Heuristic Search CPSC 322 Lecture 6, Slide 9

Using Breadth-First Search When is BFS appropriate? space is not a problem it s necessary to find the solution with the fewest arcs although all solutions may not be shallow, at least some are there may be infinite paths When is BFS inappropriate? Heuristic Search CPSC 322 Lecture 6, Slide 9

Using Breadth-First Search When is BFS appropriate? space is not a problem it s necessary to find the solution with the fewest arcs although all solutions may not be shallow, at least some are there may be infinite paths When is BFS inappropriate? space is limited all solutions tend to be located deep in the tree the branching factor is very large Heuristic Search CPSC 322 Lecture 6, Slide 9

Lecture Overview 1 Recap 2 Breadth-First Search 3 Search with Costs 4 Heuristic Search 5 Best-First Search Heuristic Search CPSC 322 Lecture 6, Slide 10

Search with Costs 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 In this setting we often don t just want to find just any solution Instead, we usually want to find the solution that minimizes cost We call a search algorithm which always finds such a solution optimal i=1 Heuristic Search CPSC 322 Lecture 6, Slide 11

Lowest-Cost-First Search 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. We say a path because there may be ties When all arc costs are equal, LCFS is equivalent to BFS. Example: the frontier is [ p 1, 10, p 2, 5, p 3, 7 ] p 2 is the lowest-cost node in the frontier neighbours of p 2 are { p 9, 12, p 10, 15 } What happens? p 2 is selected, and tested for being a goal. Neighbours of p 2 are inserted into the frontier (it doesn t matter where they go) Thus, the frontier is now [ p 1, 10, p 9, 12, p 10, 15, p 3, 7 ]. p 3 is selected next. Of course, we d really implement this as a priority queue. Heuristic Search CPSC 322 Lecture 6, Slide 12

Analysis of Lowest-Cost-First Search Is LCFS complete? Heuristic Search CPSC 322 Lecture 6, Slide 13

Analysis of Lowest-Cost-First Search Is LCFS complete? not in general: a cycle with zero or negative arc costs could be followed forever. Heuristic Search CPSC 322 Lecture 6, Slide 13

Analysis of Lowest-Cost-First Search Is LCFS complete? not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive What is the time complexity, if the maximum path length is m and the maximum branching factor is b? Heuristic Search CPSC 322 Lecture 6, Slide 13

Analysis of Lowest-Cost-First Search Is LCFS complete? not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is O(b m ): must examine every node in the tree. Knowing costs doesn t help here. Heuristic Search CPSC 322 Lecture 6, Slide 13

Analysis of Lowest-Cost-First Search Is LCFS complete? not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is O(b m ): must examine every node in the tree. Knowing costs doesn t help here. What is the space complexity? Heuristic Search CPSC 322 Lecture 6, Slide 13

Analysis of Lowest-Cost-First Search Is LCFS complete? not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is O(b m ): must examine every node in the tree. Knowing costs doesn t help here. What is the space complexity? Space complexity is O(b m ): we must store the whole frontier in memory. Heuristic Search CPSC 322 Lecture 6, Slide 13

Analysis of Lowest-Cost-First Search Is LCFS complete? not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is O(b m ): must examine every node in the tree. Knowing costs doesn t help here. What is the space complexity? Space complexity is O(b m ): we must store the whole frontier in memory. Is LCFS optimal? Not in general. Why not? Heuristic Search CPSC 322 Lecture 6, Slide 13

Analysis of Lowest-Cost-First Search Is LCFS complete? not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is O(b m ): must examine every node in the tree. Knowing costs doesn t help here. What is the space complexity? Space complexity is O(b m ): we must store the whole frontier in memory. Is LCFS optimal? Not in general. Why not? Arc costs could be negative: a path that initially looks high-cost could end up getting a refund. However, LCFS is optimal if arc costs are guaranteed to be non-negative. Heuristic Search CPSC 322 Lecture 6, Slide 13

Lecture Overview 1 Recap 2 Breadth-First Search 3 Search with Costs 4 Heuristic Search 5 Best-First Search Heuristic Search CPSC 322 Lecture 6, Slide 14

Past knowledge and search Some people believe that they are good at solving hard problems without search However, consider e.g., public key encryption codes (or combination locks): the search problem is clear, but people can t solve it When people do perform well on hard problems, it is usually because they have useful knowledge about the structure of the problem domain Computers can also improve their performance when given this sort of knowledge in search, they can estimate the distance from a given node to the goal through a search heuristic in this way, they can take the goal into account when selecting path Heuristic Search CPSC 322 Lecture 6, Slide 15

Heuristic Search h(n) is an estimate of the cost of the shortest path from node n to a goal node. h can be extended to paths: h( n 0,..., n k ) = h(n k ) h(n) uses only readily obtainable information (that is easy to compute) about a node. Admissible heuristic: h(n) is an underestimate if there is no path from n to a goal that has path length less than h(n). another way of saying this: h(n) is a lower bound on the cost of getting from n to the nearest goal. Heuristic Search CPSC 322 Lecture 6, Slide 16

Example Heuristic Functions If the nodes are points on a Euclidean plane and the cost is the distance, we can use the straight-line distance from n to the closest goal as the value of h(n). this makes sense if there are obstacles, or for other reasons not all adjacent nodes share an arc Heuristic Search CPSC 322 Lecture 6, Slide 17

Example Heuristic Functions If the nodes are points on a Euclidean plane and the cost is the distance, we can use the straight-line distance from n to the closest goal as the value of h(n). this makes sense if there are obstacles, or for other reasons not all adjacent nodes share an arc Likewise, if nodes are cells in a grid and the cost is the number of steps, we can use Manhattan distance this is also known as the L 1 distance; Euclidean distance is L 2 distance Heuristic Search CPSC 322 Lecture 6, Slide 17

Example Heuristic Functions If the nodes are points on a Euclidean plane and the cost is the distance, we can use the straight-line distance from n to the closest goal as the value of h(n). this makes sense if there are obstacles, or for other reasons not all adjacent nodes share an arc Likewise, if nodes are cells in a grid and the cost is the number of steps, we can use Manhattan distance this is also known as the L 1 distance; Euclidean distance is L 2 distance In the 8-puzzle, we can use the number of moves between each tile s current position and its position in the solution Heuristic Search CPSC 322 Lecture 6, Slide 17

How to Construct a Heuristic Overall, a cost-minimizing search problem is a constrained optimization problem e.g., find a path from A to B which minimizes distance traveled, subject to the constraint that the robot can t move through walls A relaxed version of the problem is a version of the problem where one or more constraints have been dropped e.g., find a path from A to B which minimizes distance traveled, allowing the agent to move through walls A relaxed version of a minimization problem will always return a value which is weakly smaller than the original value: thus, it s an admissible heuristic Heuristic Search CPSC 322 Lecture 6, Slide 18

How to Construct a Heuristic It s usually possible to identify constraints which, when dropped, make the problem extremely easy to solve this is important because heuristics are not useful if they re as hard to solve as the original problem! Another trick for constructing heuristics: if h 1 (n) is an admissible heuristic, and h 2 (n) is also an admissible heuristic, then max(h 1 (n), h 2 (n)) is also admissible. Heuristic Search CPSC 322 Lecture 6, Slide 19

Lecture Overview 1 Recap 2 Breadth-First Search 3 Search with Costs 4 Heuristic Search 5 Best-First Search Heuristic Search CPSC 322 Lecture 6, Slide 20

Best-First Search Idea: select the path whose end is closest to a goal according to the heuristic function. Best-First search selects a path on the frontier with minimal h-value. It treats the frontier as a priority queue ordered by h. This is a greedy approach: it always takes the path which appears locally best Heuristic Search CPSC 322 Lecture 6, Slide 21

Illustrative Graph Best-First Search s g Heuristic Search CPSC 322 Lecture 6, Slide 22

Complexity of Best-First Search Complete: no: a heuristic of zero for an arc that returns to the same state can be followed forever. Time complexity is O(b m ) Space complexity is O(b m ) Optimal: no (why not?) Heuristic Search CPSC 322 Lecture 6, Slide 23