Artificial Intelligence Lecture 10 Outline • Problem Solving using Search • Search consists of – – – – state space operators start state goal states • A Search Tree is an efficient way to represent a search • There are a variety of specific search techniques, including – Depth-First Search – Breadth-First Search – Others which use heuristic knowledge (in future lectures) What do these problems have in common? • Find the layout of chips on a circuit board which minimize the total length of interconnecting wires • Write a program which can play chess against a human • Build a system which can find human faces in an arbitrary digital image • Decrypt data which has been encrypted but you do not have the key • Answer – they can all be formulated as search problems • Setting Up a State Space Model State-space Model is a Model for The Search Problem – usually a set of discrete states X • e.g., in driving, the states in the model could be towns/cities • Start State - a state from X where the search starts • Goal State(s) – a goal is defined as a target state – For now: all goal states have utility 1, and all non-goals have utility 0 – there may be many states which satisfy the goal • e.g., drive to a town with an airport – or just one state which satisfies the goal • e.g., drive to Las Vagas • Operators – operators are mappings from X to X • e.g. moves from one city to another that are connected with a road (legal) Summary: Defining Search Problems • A statement of a Search problem has 4 components 1. A set of states 2. A set of “operators” which allow one to get from one state to another 3. A start state S 4. A set of possible goal states G, or ways to test for goal states • Search solution consists of – a sequence of operators which transform S into a a unique goal state G (this is the sequence of actions the we would take to maximize the success function) • Representing real problems in a search framework – may be many ways to represent states and operators – key idea: represent only the relevant aspects of the problem • Example 1: Formulation of Map Problem Set of States – individual cities – e.g., San Francisco, Seattle, Las Vegas, Phoenix, Chicago • Operators – freeway routes from one city to another – e.g. San Francisco to Seattle, etc • Start State – current city where we are, San Francisco • Goal States – set of cities we would like to be in – e.g., cities which are cooler than Seattle • Solution – a sequence of operators which get us a specific goal city, • e.g., Irvine to SF via 5, SF to Reno via 80, etc State Space Graph: Map Navigation not to be confused with Search Tree!! A B C G S D E F S = start, G = goal, other nodes = intermediate states, links = legal transitions Abstraction • Definition of Abstraction: Process of removing irrelevant detail to create an abstract representation: ``high-level”, ignores irrelevant details • Navigation Example: how do we define states and operators? – First step is to abstract “the big picture” • i.e., solve a map problem • nodes = cities, links = freeways/roads (a high-level description) • this description is an abstraction of the real problem – Can later worry about details like freeway onramps, refueling, etc • Abstraction is critical for automated problem solving – must create an approximate, simplified, model of the world for the computer to deal with: real-world is too detailed to model exactly – good abstractions retain all important details Qualities of a Good Representation • Given a good representation/abstraction, solving a problem can be easy! • Conversely, a poor representation makes a problem harder • Qualities which make a Representation useful: – – – – – – important objects and relations are emphasized irrelevant details are suppressed natural constraints are made explicit and clear completeness concise efficient Example 2: Puzzle-Solving as Search • • • You have a 3-gallon and a 4-gallon You have a faucet with an unlimited amount of water You need to get exactly 2 gallons in 4-gallon jug • State representation: (x, y) – x: Contents of four gallon – y: Contents of three gallon • • • Start state: (0, 0) Goal state(s) G = {(2, 0), (2, 1), (2, 2)} Operators – – – – – Fill 3-gallon (0,0)->(0,3), fill 4-gallon (0,0)->(4,0) Fill 3-gallon from 4-gallon (4,0)->(1,3), Fill 4-gallon from 3-gallon (0,3)->(3,0) or (1,3)->(4,0) or (2,2)->(4,0)…. Empty 3-gallon into 4-gallon, empty 4-gallon into 3-gallon Dump 3-gallon down drain (0,3)->(0,0), dump 4-gallon down drain (4,0)->(0,0) Example 3: The “8-Puzzle” Problem Start State 1 2 4 6 7 5 8 1 2 3 4 5 6 7 Goal State 3 8 1 2 3 4 5 6 7 8 Search Basics • When the answer is not straight foreword, you must search for a solution. But because of the sheer magnitude of some situations, it is hard to incorporate into AI. • Combination explosions cause the sheer magnitude of these problems. Combination explosions are when the possibilities for a solution explode (increase very rapidly) • The math field of combinatorics study how these combination explosions occur. The commonly accepted theorem states that the number of ways N objects can be combined equals N! (N factorial). Because of the enormous number of possibilities, it is almost never a good idea to try every single possibility Search Basics (Definitions) • • • • • Node: A discrete point and possible goal Terminal Node: A node that ends a path Search Space: The set off all nodes Goal: The node that is the object of the search Heuristic: Information about the likelihood that any specific node is a better choice to try next, rather than another node • Solution Path: A directed graph of the nodes visited that lead to the solution Search Space • Most search spaces are in the form of a tree. A tree looks like an upside down tree that contains nodes. The following is an example of a tree: • Evaluation of Searching Algorithm • Evaluating a search technique can sometimes be very difficult. But the most basic measuring techniques are: – Speed in which the solution is found – The quality of the solution • Both criterions are basically equally important, but in some case one might take priority over the other. DFS • The Depth-First search explores each possible path to find the path's conclusion or the goal. • If the path does not contain the goal the search tries another path by backtracking. • The following image shows the path the search takes when trying to find the goal ‘F': DFS (Conclusion) • As you can see, the search almost had to check every node in order to find the answer, but it did find the right answer. • This search is very reliable but sometimes can take a long time or even turn into an exhaustive search (a search that looks a every point until it reaches the goal). • The Depth-First search can also be modified to go from the right to the left DFS (Pros and Cons) • Advantages: – Always finds the goal • Disadvantages: – Often can be slow – Can result in an exhaustive search – Can get stuck in long paths that don't lead to the goal BFS • The Breadth-First search technique is exactly the same as the Depth-First except that the Breadth-First checks each node on a level until it proceeds to the next level. • The example below demonstrates this technique with the goal of node ‘C': BFS (Pros and Cons) • Advantages: – Always finds the goal – Good for shallow trees • Disadvantages: – Often can be slow in deep trees – Can result in an exhaustive search Hill-Climbing search • The Hill-Climbing search uses heuristics to find the direction which leads towards the goal. • The name "hill-climbing" comes from an analogy: – A hiker is lost halfway up/down (depends on if you are an optimist) a mountain at night. His camp is at the top of the mountain. Even though it is dark, the hiker knows that every step he takes up the mountain is a step towards his goal. • So a hill-climbing search always goes to the node closest to the goal. Traversal of graphs • To traverse means to visit the vertices (nodes) in some systematic order. • Various traversal methods for trees are: – – – – preorder: visit each node before its children. postorder: visit each node after its children. inorder (for binary trees only): visit left subtree, node, right subtree. A small portion of a tree (Maybe in shortest path). Examples of undirected graphs Observe that 1. Every free tree with n vertices contains exactly n - 1 edges 2. If we add any edge to a free tree, we get a cycle Depth First and Breadth First Search Vertex Adj. List a (b, c, d, e) b (a, d, e) c (a, f, g) d (a, b, e) Vertex Adj. List e (a, b, d) f (c, g) g (c, f) Depth First Search (DFS) DFS of an undirected graph involves only two types of arcs. 1. Tree arcs. 2. Back arcs (there is no distinction between back arcs and forward arcs) Cross arcs also don't exist because given any two vertices, if there exists an arc between them, then one of them will be an ancestor and the other a descendant in the DFS. Breadth First Search Breadth First Search is also known as ForwardChaining Graph search algorithms must eliminate loops from solution path Heuristic Search • • • • • A heuristic is a method that might not always find the best solution but is guaranteed to find a good solution in reasonable time. – – • • could not be solved any other way. solutions take an infinite time or very long time to compute. The classic example of heuristic search methods is the travelling salesman problem. Heuristic Search methods Generate and Test Algorithm – – • By sacrificing completeness it increases efficiency. Useful in solving tough problems which – generate a possible solution which can either be a point in the problem space or a path from the initial state. test to see if this possible solution is a real solution by comparing the state reached with the set of goal states. if it is a real solution, return. Otherwise repeat from 1. This method is basically a depth first search as complete solutions must be created before testing. It is often called the British Museum method as it is like looking for an exhibit at random. A heuristic is needed to sharpen up the search. Questions & Answers ???????