Problem Solving and Blind Search

Similar documents
Measuring the Performance of an Agent

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

Sequential Data Structures

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

Chapter 11 Number Theory

Binary Search Trees CMPSC 122

The Graphical Method: An Example

Information, Entropy, and Coding

Mathematical Induction

Algorithms and Data S tructures Structures Stack, Queues, and Applications Applications Ulf Leser

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

The Taxman Game. Robert K. Moniot September 5, 2003

Lecture Notes on Linear Search

Y. Xiang, Constraint Satisfaction Problems

Problem solving and search

Common Data Structures

Math 4310 Handout - Quotient Vector Spaces

Notes on Complexity Theory Last updated: August, Lecture 1

Symbol Tables. Introduction

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

The Basics of Graphical Models

A Non-Linear Schema Theorem for Genetic Algorithms

Mathematical Induction

Dynamic Programming. Lecture Overview Introduction

5544 = = = Now we have to find a divisor of 693. We can try 3, and 693 = 3 231,and we keep dividing by 3 to get: 1

Data Structure [Question Bank]

In mathematics, it is often important to get a handle on the error term of an approximation. For instance, people will write

(Refer Slide Time: 2:03)

Lecture Notes on Binary Search Trees

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

6.852: Distributed Algorithms Fall, Class 2

Patterns in Pascal s Triangle

What is Linear Programming?

Linear Programming. March 14, 2014

Algorithms. Margaret M. Fleck. 18 October 2010

Binary Trees and Huffman Encoding Binary Search Trees

Testing LTL Formula Translation into Büchi Automata

Sudoku puzzles and how to solve them

Cosmological Arguments for the Existence of God S. Clarke

The fundamental question in economics is 2. Consumer Preferences

Kenken For Teachers. Tom Davis June 27, Abstract

Search methods motivation 1

Triangulation by Ear Clipping

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

CMPSCI611: Approximating MAX-CUT Lecture 20

Approximation Algorithms

Special Situations in the Simplex Algorithm

Introduction to Data Structures and Algorithms

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Smart Graphics: Methoden 3 Suche, Constraints

Dynamic Programming Problem Set Partial Solution CMPSC 465

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

6.1. The Exponential Function. Introduction. Prerequisites. Learning Outcomes. Learning Style

International Journal of Advanced Research in Computer Science and Software Engineering

Decision Making under Uncertainty

[Refer Slide Time: 05:10]

Lecture Notes on Binary Search Trees

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

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

New Admissible Heuristics for Domain-Independent Planning

5.1 Bipartite Matching

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Heaps & Priority Queues in the C++ STL 2-3 Trees

Data Structures and Algorithms Written Examination

1 Solving LPs: The Simplex Algorithm of George Dantzig

Graph Theory Problems and Solutions

3 Abstract Data Types and Search

A Model-driven Approach to Predictive Non Functional Analysis of Component-based Systems

From Last Time: Remove (Delete) Operation

Coverability for Parallel Programs

14.1 Rent-or-buy problem

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

3. Mathematical Induction

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Basic Electronics Prof. Dr. Chitralekha Mahanta Department of Electronics and Communication Engineering Indian Institute of Technology, Guwahati

An Introduction to The A* Algorithm

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Session 6 Number Theory

Regular Expressions and Automata using Haskell

Analysis of Micromouse Maze Solving Algorithms

23. RATIONAL EXPONENTS

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Enumerating possible Sudoku grids

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

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

Load Balancing. Load Balancing 1 / 24

Analysis of Algorithms I: Optimal Binary Search Trees

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

1 if 1 x 0 1 if 0 x 1

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

Chapter 13: Binary and Mixed-Integer Programming

Regular Languages and Finite Automata

Class notes Program Analysis course given by Prof. Mooly Sagiv Computer Science Department, Tel Aviv University second lecture 8/3/2007

Dynamic Programming 11.1 AN ELEMENTARY EXAMPLE

Data Structures and Algorithms

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

Regions in a circle. 7 points 57 regions

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

TUM INSTITUT FÜR INFORMATIK. Matching and Evaluation of Disjunctive Predicates for Data Stream Sharing TECHNISCHE UNIVERSITÄT MÜNCHEN

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

Transcription:

Plan: Problem Solving Blind Search Breadth-First Priority-First Depth-First Depth-Limited Iterative Deepening Constraint Satisfaction Problem Solving and Blind Search We talked last time about various kinds of agents. Clearly, simple reflex agents, with and without state, are the sorts of things that you probably already know (or can figure out) how to implement. We will therefore begin our study of AI techniques by focusing on how to construct goal-based agents that perform problem solving. Problem-Solving Agents Consider a general paradigm, called problem solving, for implementing goal-based agent programs. Figuring out what to do to achieve a goal would be easy if all effects were the result of executing a single action. But often a sequence of actions is required to achieve a goal. As another example, getting from A(rad) to B(ucharest) via a sequence of local city-to-city transitions (or Ann Arbor to Bowling Green?). Impossible to get there in one transition, but can find a sequence of transitions that works. Show the 15-puzzle as another example. We ll mostly use the smaller (3x3) version called the 8-puzzle, for illustration. Or consider the ToH problem. Can t do it in just one step (or, at least, not just one legal step). How many steps will it take to solve this? How do we know? How would an agent know? In the route-planning example, it is obvious that the effect of an action is to move the agent from one place to another. It turns out that this is analogous to actions in general, which can be modeled as

moving the agent from one situation or state to another. The state may include the physical location of the agent, but may also specify any other feature of the world that is relevant to the agent. How would we specify a state in the 8-puzzle? What do we need to represent? What data structure(s) might we use to represent it? In ToH example, what is relevant in a state? What is not? What data structure might we use? Even ignoring everything but the most relevant stuff - that is, by abstracting the problem, we still might have quite a few states. How many states are there in the ToH problem? Do we have to worry about the order in which disks are on pegs? Why not? What are the available actions to an agent in this problem? How many states are there in the 8-puzzle? We can also define what it means more precisely to solve a problem. A problem consists of: an initial state, a set of available actions, or operators, defined in terms of a successor function, S:state operator state, specifying the state resulting from executing the action in any particular state, the goal test, defining the subset of states that satisfy the goal, and a path cost function g specifying the cost of executing a sequence of operators, or a path. A solution to a problem is a sequence of operators, 8 o 1,l,o n, such that the state 88 S(S(m(S(x init,o 1 ),o 2 )m), o n ) satisfies the goal test. The solution is optimal if it has minimum path cost among all solutions. Given the data structure that we decided on for representing a state in the 8-puzzle, for example, we can now be more precise about the problem description. The initial state is something that would be given to us, and that we would encode in the array. <Give an example.>

The goal test, in this case, is very specific about what state needs to be reached to satisfy the goal. So the goal test would involve comparing a potential goal state array with an array that contains the goal state, and if the arrays are identical then the goal has been reached. The operators involve sliding tiles into the open space; or equivalently, moving the space to one of its adjacent locations. Thus, we could have an operator for moving the space-right, in pseudocode: Operator: space-right(state-array) Xspace,Yspace :- Find-space(state-array) If (Xspace > 1) then return(state-array) Else {new-state-array :- copy(state-array); new-state-array(xspace,yspace) :- new-state-array(xspace+1,yspace); new-state-array(xspace+1, Yspace) :- S; return(new-state-array)} The other operators would be defined similarly. Let s look at another problem - the milk jug problem. Let s try doing some formulation. <Show them the problem.> How do we formulate the goal? How will we specify a state? Is the space continuous or discrete? How large will the state space be? (20) How many of these states will satisfy the goal? (4) What is a solution? How long a sequence would be too long to expect as a solution? ToH. What are the goal state(s)? What would you expect as the path to the goal, in terms of length. <For the 8-disk case, there are 3**8 states. The path length is (2**d)-1, so (2**8)-1. Thus, the proportion of states visited is less than 4% (255/6561). It would be good to avoid exhaustive search, don t you think?

Search in State Spaces In general, how can we solve a problem? Some problems may be amenable to particular procedures that result in solutions. But a general approach that can be applied to any problem described in this manner is called search. By search we mean any systematic way of traversing the graph of states in order to find a sequence of operators leading to a goal state. Starting from an initial state, the set of all paths beginning at that state form a tree, which we will call the search tree. A search strategy is a method of generating that tree dictating in which order the paths are elaborated. We elaborate paths by expanding a node, generating all of its possible successors. (Note: I cannot emphasize strongly enough this view of generating a tree during the search. Lots of people have in mind the notion of searching a tree, as if the tree is all known ahead of time. Would you want to generate the whole tree for the ToH, and then search it? I think not!) To implement a search strategy, we will need to keep track at each node of the search tree: the corresponding state in the state space, the node s predecessor in the path, or parent, and the operator applied to the parent to generate this node. It will also often be convenient to keep track of the depth of the node, and the path cost from the root to the node. Comparing Search Strategies We can evaluate particular search strategies on the following criteria: completeness: whether guaranteed to find a solution if one exists time efficiency (complexity) space efficiency optimality, or more generally, solution quality

Breadth-first Search In BFS, our search strategy will be to expand nodes in the order they are generated. To implement this, as we generate new successor nodes, we simply enqueue the nodes at the end of the list of nodes marking the frontier of the search tree, so they will be removed from the queue in a first-in first-out (FIFO) manner. This corresponds to a level-order traversal of the search tree all nodes at depth d are expanded before proceeding to depth d +1. Illustrate with the 8-puzzle. Let us examine BFS wrt our evaluation criteria. First, it is complete. If there is a solution, BFS will eventually find it. Moreover, it will find the shallowest solution there is. So if path cost corresponds to solution depth, BFS also produces optimal solutions. Now let us consider efficiency, first time complexity. To simplify the analysis we will assume a uniform search space, one where each node has the same number of successors. This is satisfied in some problems, but is not quite true for some of our examples, such as ToH or the jug problem. The number of successors for each node is called the branching factor, and denoted by b. Suppose the shallowest solution is found at depth d. Since BFS will have generated the complete search trees at depths < d, the number of nodes in the search tree is: d 1 b i 66 + x = 1 + b + b 2 + h + b d 1 + x, where 1 x b d i=0. The actual value of x depends on where at depth d the solution is found (draw triangle picture). Regardless, both the worst-case and average-case complexity is O(b d ). (Explain this, as well as the expression above.) This is exponential, and so obviously can get out of hand quickly with d. This may be depressing, but get used to it exponential complexity is the usual situation for search algorithms. <Think about this with the ToH problem. Let s say conservatively that b is 2. We already know that d is 255 for the 8-disk version.

Care to do the mathematics? (5.7 e 76)> or 1.7e38 + x. You betcha we don t want to repeat states! Perhaps a more serious concern is the space complexity. This is the same as the time complexity, because we have to store the entire fringe, which consists of all the nodes at the deepest level. This is also O(b d ). In typical computer configurations, we will run out of space long before we run out of time. A slight variant or generalization of BFS is uniform-cost search. In uniform-cost search, we expand the node with the minimum path cost, rather than that with the minimum depth. This requires a priority queue as opposed to a FIFO queue (remember priority-first search?). Uniform-cost has the same completeness and complexity properties (modulo the queuing operations) as BFS, but is optimal in somewhat more general circumstances. Namely, it produces the optimal solution as long as path cost never decreases as we go down a path. The PFS shortest-path algorithm (aka Dijkstra s algorithm) is an instance of uniform-cost search. Different search strategies are defined as versions of PFS with different sorting functions. Depth-First Search The second canonical search method is depth-first search (DFS). In contrast with BFS, DFS expands the most recently expanded node first. Equivalently, it expands the deepest node on the fringe. To implement DFS, we simply replace the FIFO queuing discipline with LIFO. That is, the queue is a stack. (Sometimes this is implemented recursively using the function calling stack, rather than an explicit data structure for fringe nodes.) Is DFS complete? No charging down a path in depth-first manner might lead to infinite expansions in that direction, when a solution was possibly close-at-hand along another direction. One way of reducing the chances of infinite movement along one path is to recognize states that you ve already expanded and not expanding them again. Talk about avoiding redundancy:

Avoid two-step cycles (don't reverse previous step) Avoid n-step cycles (don't have same state twice in path) Avoid redoing anything: closed list. Its cost? Even with redundancy checking, still can wander down infinite path if the state space itself is infinite. Example: initial state is 0. Operators are increment-by-1 and decrement-by-1. Goal-test is "< -3." What happens if first operator applied is always increment-by-1. In cases where we can bound the maximum depth that we need to search, say at m, however, DFS is complete. That is, if we can be sure that at least one solution lies at depth m or less. Its worst-case time complexity is O(b m ), as is the average case (but a little less obviously). This is basically the same as BFS. Moreover, DFS is not optimal. Consider route-finding example where we make an unlucky early choice. So why would we ever consider DFS? The answer lies in its space complexity. In DFS, the fringe requires at most b nodes per level, since all we need is the current node we have expanded and the other nodes to try if this fails (draw picture). Therefore the overall space complexity is O(bm), which is practically never a problem (unless the paths we are exploring are too long anyway space required is proportional to solution size). Variant: depth-limited search. Simply impose a limit l on the depth of nodes to be expanded. Time complexity O(b l ), space complexity O(bl), complete iff l m (where, again, m is a depth at which a solution exists). Iterative Deepening What we would really like to do is find a method that combines the advantages of BFS and DFS: getting the completeness and optimality of the former and the space efficiency of the latter. There is a technique that does this, called iterative deepening.

The idea of iterative deepening is very simple. We start by running DFS with a depth limit of 1. If that finds a solution (fat chance), we are done. Otherwise, we run DFS again with a depth limit of 2. And if that fails we start again with a depth limit of 3, and so on. Here s the pseudo-code: function ITERATIVE-DEEPENING-SEARCH(Problem) loop for depth from 0 to infinity if DEPTH-LIMITED-SEARCH(Problem,depth) succeeds then return its result end loop return failure This is complete, because if there is a solution at depth d, the algorithm will eventually find it when it runs DEPTH-LIMITED- SEARCH with argument d (and all of the previous iterations are guaranteed to terminate). It is optimal in the same sense as BFS, because it never looks at a path of length d +1 before it looks at all paths of length d. In fact, it generates solutions in the same order as BFS. Now what about complexity? At first glance, iterative deepening looks extremely inefficient, because there is a great deal of redundant processing. When running DEPTH-LIMITED-SEARCH with argument l, it repeats all the work it did at iteration l 1, which in turn repeats all the work it did on l 2, and so on. But on further examination, we see that this redundancy is not really significant. To see this, we can express the complexity of the algorithm as the sum of the complexity of its iterations, d 88 O(b l ) = O(b) + O(b 2 )+m+o(b d 1 ) + O(b d ) = O(b d ). l=1 So the asymptotic complexity is still O(b d ). In fact, the ratio of time required by DFID compared to DFS is given by (after some algebra) (b + 1) ( b 1), which is maximized at 3 for b = 2. For higher branching factors (e.g., b = 10), the redundancy overhead is virtually negligible.

So the time requirements are the same as our basic methods, but the space requirements are just those of DFS. This is the best we can hope to do in the worst case we may have to look at the entire search space O(b d ), and the size of the solution itself is O(d). Iterative deepening is invariably the way to go when there is a large search space and we don t know the depth of the solution. An unusually definitive recommendation! Bidirectional Search How do you solve a maze? Hope is to work from ends toward the middle. Why is this good? If only go half way from each end, then instead of O(b**d) we have two searches of O(b**(d/2)) which is a lot less! What would the space complexity be? O(b**(d/2)) also! But to work we need to: Know the inverse operators to work backwards. Need to start backward from a goal state rather than goal test. Need to discover whether new node matches node found in other search tree - matching can be costly! Need to do a decent search in each half. Constraint Satisfaction We have so far talked about methods applicable to all problems. There is a particular subclass of problems that is still very broad, but yet has some additional structural properties that are useful to exploit in search. Members of this class are called constraintsatisfaction problems, or CSPs. CSPs represent a practically important special class, and indeed are the subject of much active research in AI and OR. Recall that a problem is defined by sets of states, operators, a goal test, and a path cost function. In a CSP, these are: states: operators: assignments to a set of variables assigning a value to a variable

goal test: path cost: solutions) constraints on joint variable assignments (usually ignored, but may specify preferred Example: cryptarithmetic (a toy problem). SEND+MORE=MONEY Variables are letters, which can take on values in the set {0,,9} (the domain). Constraints are that the columns have to add up right, including carries (and perhaps that all characters stand for a different digit). Initial state is the empty assignment. Goal states are those that assign a value to every variable and where all constraints are satisfied. We can of course apply our general search procedure to this problem, and to all CSPs. A very naive approach would be to start from the initial state (no assignments), and consider all assignments that we could make. For cryptarithmetic, this would correspond to a branching factor of 10x, where x is the number of characters in the problem. This is obviously wasteful, since it will generate separate paths that differ only in which order variables are assigned. While operator order matters for problems in general, they do not for CSPs. So almost all CSP algorithms generate successors for only a single variable assignment at a given search-tree node. This leads to a search space of size b d, where d is the number of variables, and b is the maximum domain size. For cryptarithmetic, this is 10x. Still pretty bad, of course, but better than (10x)x. We cannot hope to do significantly better in the worst case, because many NP-complete problems are CSPs. There is another major fact we can take advantage of in CSPs. Namely, in solving a CSP we can often tell that a state can never lead to the goal, even before all variables are assigned. This is because the constraints may already be violated. It would be wasteful to expand such a state, so instead we prune the node, and avoid even looking at its entire subtree. This can dramatically reduce the search space (but of course it is still exponential in the worst case). This approach is called backtracking after generating each node we check it for constraint consistency, and if it fails we backtrack to some other

node. Often we can do even better than to check each node for immediate constraint violations. For example, we might be able to tell that a state can never lead to a goal state, even though none of the current assignments directly violate the specified constraints. For example, consider the state that assigns D=2, E=3, and N=5. This does not directly violate any of the column or uniqueness constraints. But we can see that this will ultimately lead to an inconsistency, because any state with D=2 and E=3 must have Y=5, and so that value cannot be assigned to N. But if we fail to recognize this, we can waste a lot of effort in expanding this state to assign combinations of values for M,R,S,, only to notice the inconsistency when we get to Y. We can avoid this problem by assigning Y=5 as soon as we assign D=2 and E=3. Such an approach is called constraint propagation. (Illustrate more extensively, if there's time).