February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 1 A General Backtracking Algorithm Sanity check function.

Slides:



Advertisements
Similar presentations
Informed search algorithms
Advertisements

Heuristic Search techniques
Informed search algorithms
An Introduction to Artificial Intelligence
Traveling Salesperson Problem
Artificial Intelligence Chapter 9 Heuristic Search Biointelligence Lab School of Computer Sci. & Eng. Seoul National University.
October 1, 2012Introduction to Artificial Intelligence Lecture 8: Search in State Spaces II 1 A General Backtracking Algorithm Let us say that we can formulate.
1 Heuristic Search Chapter 4. 2 Outline Heuristic function Greedy Best-first search Admissible heuristic and A* Properties of A* Algorithm IDA*
CSC 423 ARTIFICIAL INTELLIGENCE
September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move.
Problem Solving by Searching
CSC344: AI for Games Lecture 5 Advanced heuristic search Patrick Olivier
SE Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:
Review: Search problem formulation
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
MAE 552 – Heuristic Optimization Lecture 27 April 3, 2002
Using Search in Problem Solving
Problem Solving and Search in AI Heuristic Search
CSC344: AI for Games Lecture 4: Informed search
CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:
State-Space Searches. 2 State spaces A state space consists of –A (possibly infinite) set of states The start state represents the initial problem Each.
State-Space Searches.
Informed Search Idea: be smart about what paths to try.
Vilalta&Eick: Informed Search Informed Search and Exploration Search Strategies Heuristic Functions Local Search Algorithms Vilalta&Eick: Informed Search.
Artificial Intelligence Lecture 9. Outline Search in State Space State Space Graphs Decision Trees Backtracking in Decision Trees.
Informed search algorithms
Informed search algorithms Chapter 4. Outline Best-first search Greedy best-first search A * search Heuristics.
1 Shanghai Jiao Tong University Informed Search and Exploration.
State-Space Searches. 2 State spaces A state space consists of A (possibly infinite) set of states The start state represents the initial problem Each.
Informed search algorithms Chapter 4. Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most.
Informed search strategies Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select.
For Friday Finish reading chapter 4 Homework: –Lisp handout 4.
For Monday Read chapter 4, section 1 No homework..
CS344: Introduction to Artificial Intelligence (associated lab: CS386)
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
Artificial Intelligence for Games Informed Search (2) Patrick Olivier
CSC3203: AI for Games Informed search (1) Patrick Olivier
CS621: Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 3 - Search.
Basic Problem Solving Search strategy  Problem can be solved by searching for a solution. An attempt is to transform initial state of a problem into some.
Informed Search Reading: Chapter 4.5 HW #1 out today, due Sept 26th.
Problem Reduction So far we have considered search strategies for OR graph. In OR graph, several arcs indicate a variety of ways in which the original.
4/11/2005EE562 EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 4, 4/11/2005 University of Washington, Department of Electrical Engineering Spring 2005.
A General Introduction to Artificial Intelligence.
Feng Zhiyong Tianjin University Fall  Best-first search  Greedy best-first search  A * search  Heuristics  Local search algorithms  Hill-climbing.
Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most desirable unexpanded node Implementation:
Introduction to Artificial Intelligence (G51IAI) Dr Rong Qu Blind Searches - Introduction.
Search in State Spaces Problem solving as search Search consists of –state space –operators –start state –goal states A Search Tree is an efficient way.
February 11, 2016Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 State-Space Graphs There are various methods for searching.
Chapter 3.5 and 3.6 Heuristic Search Continued. Review:Learning Objectives Heuristic search strategies –Best-first search –A* algorithm Heuristic functions.
CPSC 420 – Artificial Intelligence Texas A & M University Lecture 5 Lecturer: Laurie webster II, M.S.S.E., M.S.E.e., M.S.BME, Ph.D., P.E.
CS621: Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 3: Search, A*
For Monday Read chapter 4 exercise 1 No homework.
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
Chapter 3.5 Heuristic Search. Learning Objectives Heuristic search strategies –Best-first search –A* algorithm Heuristic functions.
Review: Tree search Initialize the frontier using the starting state
Artificial Intelligence Problem solving by searching CSC 361
CS 4100 Artificial Intelligence
Artificial Intelligence
Introduction to Artificial Intelligence Lecture 9: Two-Player Games I
A General Backtracking Algorithm
Artificial Intelligence Chapter 9 Heuristic Search
A General Backtracking Algorithm
Informed Search Idea: be smart about what paths to try.
State-Space Searches.
State-Space Searches.
Artificial Intelligence
Reading: Chapter 4.5 HW#2 out today, due Oct 5th
State-Space Searches.
Informed Search Idea: be smart about what paths to try.
Presentation transcript:

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 1 A General Backtracking Algorithm Sanity check function for the n-queens problem: fQueens :: Int -> [Int] -> Bool fQueens row plan = isOK plan 1 where isOK [] dist = True where isOK [] dist = True isOK (p:ps) dist = isOK (p:ps) dist = if elem p [row, row-dist, row+dist] then False if elem p [row, row-dist, row+dist] then False else isOK ps (dist + 1) else isOK ps (dist + 1)

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 2 A General Backtracking Algorithm We can write our general backtracking function: backtrack :: (a->[a]->Bool) -> [[a]] -> [a] backtrack fCheck levels = bt [] levels where bt plan [] = plan where bt plan [] = plan bt plan ([]:_) = [] bt plan ([]:_) = [] bt plan ((b:bs):ls) = if not (fCheck b plan) || null result bt plan ((b:bs):ls) = if not (fCheck b plan) || null result then bt plan (bs:ls) then bt plan (bs:ls) else result else result where result = bt (b:plan) ls where result = bt (b:plan) ls Use it to solve n-queens problem: nQueens n = backtrack fQueens $ take n (repeat [1..n])

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 3 A General Backtracking Algorithm Here is some code to print nQueens solution boards (rotated by 90  to simplify things): showQueens :: Int -> [Int] -> String showQueens size [] = "" showQueens size (q:qs) = (concat $ replicate (q-1) ". ") ++ "Q " ++ (concat $ replicate (size-q) ". ") ++ "\n" ++ (concat $ replicate (size-q) ". ") ++ "\n" ++ showQueens size qs showQueens size qs nQueensBoard :: Int -> String nQueensBoard n = showQueens n $ nQueens n The Haskell Platform allows you to even solve the 22-queens problem within about 15 seconds: main = putStrLn $ nQueensBoard 22

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 4 Our 22-Queens Solution Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 5 A General Graph-Searching Algorithm We just saw how backtracking can lead to very efficient search when we continuously check whether we are stuck in a dead end. We would not be able to solve the 22-queens problem with brute force, i.e., breadth-first search. That would create a tree with at least … = ( )/  1.6  nodes before we could possibly find a solution. Even if we could create a billion nodes per second and store them somehow, it would still take us over 500 billion years to build the complete tree.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 6 A General Graph-Searching Algorithm In some cases, we may even have an idea which decisions during search are most likely to get us to the goal quickly. Then we should take advantage of this information. Unfortunately, neither depth-first nor breadth-first search are flexible enough to allow this. Instead, we need a general graph-searching algorithm. It can be tuned towards depth-first or breadth-first search but also allows intermediate variants that can be guided by task- specific search heuristics. Let’s see how this magic works…

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 7 A General Graph-Searching Algorithm 1.Create search tree Tr consisting only of the start node (root) n 0. Put n 0 on an ordered list called OPEN. 2.Create empty list called CLOSED. 3.If OPEN is empty, exit with failure. 4.Move the first node on OPEN, called n, to CLOSED. 5.If n is a goal node, exit with success; the solution is the path from n to n 0 along the edges in Tr. 6.Expand node n by generating a set M of successors and connect them to n. Also put the members of M on OPEN. 7.Reorder the list OPEN according to a specific rule. 8.Go to step 3.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 8 Rules for the Graph-Searching Algorithm What happens if we simply append new nodes to the end of OPEN? The algorithm turns into breadth-first search. The algorithm turns into breadth-first search. What happens if we add new nodes at the beginning of OPEN? The algorithm turns into depth-first search. The algorithm turns into depth-first search. What happens if we sort the nodes according to a heuristic evaluation function f’ ? The algorithm turns into best-first search. The algorithm turns into best-first search.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 9 Best-First (Heuristic) Search We can often improve search efficiency by implementing a heuristic evaluation function f’ that estimates which node is the best one to expand in a given situation.We can often improve search efficiency by implementing a heuristic evaluation function f’ that estimates which node is the best one to expand in a given situation. Small values of f’ indicate the best nodes.Small values of f’ indicate the best nodes. In the general graph-searching algorithm, sort the nodes on the OPEN list in ascending order with regard to their f’-values.In the general graph-searching algorithm, sort the nodes on the OPEN list in ascending order with regard to their f’-values. This way, the supposedly “best” nodes are expanded first.This way, the supposedly “best” nodes are expanded first.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 10 Best-First (Heuristic) Search Example: The Eight-puzzle The task is to transform the initial puzzle into the goal state by shifting numbers up, down, left or right.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 11 Best-First (Heuristic) Search How can we find an appropriate evaluation function? Heuristic evaluation functions have to be “custom- made” for individual problems.Heuristic evaluation functions have to be “custom- made” for individual problems. Often, it is easy to see what a reasonable (but usually not optimal) function could look like.Often, it is easy to see what a reasonable (but usually not optimal) function could look like. For the Eight-puzzle, it seems like a good idea to expand those nodes first that lead to configurations similar to the goal state.For the Eight-puzzle, it seems like a good idea to expand those nodes first that lead to configurations similar to the goal state. In our first attempt, we will simply define f’ as the number of digits in the puzzle that are not in the correct (goal) position yet.In our first attempt, we will simply define f’ as the number of digits in the puzzle that are not in the correct (goal) position yet.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 12 Best-First (Heuristic) Search to the goal to further unnecessary expansions

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 13 Best-First (Heuristic) Search You see that with this simple function f’ the algorithm is still likely to perform unnecessarily many steps.You see that with this simple function f’ the algorithm is still likely to perform unnecessarily many steps. We should increase the “cost” of searches in greater depth to make the algorithm avoid them.We should increase the “cost” of searches in greater depth to make the algorithm avoid them. To achieve this, we simply add the current depth of a node to its f’-value.To achieve this, we simply add the current depth of a node to its f’-value. Now f’(n) = depth of n in the tree + number of digits in the puzzle in incorrect position.Now f’(n) = depth of n in the tree + number of digits in the puzzle in incorrect position. Let us try again!Let us try again!

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 14 Best-First (Heuristic) Search goal !

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 15 Best-First (Heuristic) Search Using the improved function f’, the best-first algorithm discovers the solution much more efficiently than it did before.Using the improved function f’, the best-first algorithm discovers the solution much more efficiently than it did before. To formalize things, we now have a function f’(n) = g’(n) + h’(n), where g’(n) is a estimate of the depth (or cost) of n, and h’(n) is an estimate of the minimal distance (or cost) from n to a goal node.To formalize things, we now have a function f’(n) = g’(n) + h’(n), where g’(n) is a estimate of the depth (or cost) of n, and h’(n) is an estimate of the minimal distance (or cost) from n to a goal node. While f’(n), g’(n), and h’(n) are estimates, f(n) = g(n) + h(n) is the actual minimal cost of any path going from n 0 through n to a goal node.While f’(n), g’(n), and h’(n) are estimates, f(n) = g(n) + h(n) is the actual minimal cost of any path going from n 0 through n to a goal node.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 16 Best-First (Heuristic) Search Question: What happens if for our heuristic estimation function f’(n) = g’(n) + h’(n) we simply set h’(n) = 0? Answer: Only the distance of a node from n 0 determines the cost of expanding a node. Only the distance of a node from n 0 determines the cost of expanding a node. Nodes closer to n 0 will be expanded first. Nodes closer to n 0 will be expanded first. The algorithm turns into breadth-first search. The algorithm turns into breadth-first search.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 17 Best-First (Heuristic) Search And what happens if the state-space graph for our problem is not a tree? For example, is the Eight-puzzle state-space graph a tree? No. In this puzzle, actions are reversible. Any successor of a node n has n as a successor. In order to overcome this problem, we have to modify Step 6 in our general graph-searching algorithm.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 18 Improved Graph-Searching Algorithm 1.Create search tree Tr consisting only of the start node (root) n 0. Put n 0 on an ordered list called OPEN. 2.Create empty list called CLOSED. 3.If OPEN is empty, exit with failure. 4.Move the first node on OPEN, called n, to CLOSED. 5.If n is a goal node, exit with success; the solution is the path from n to n 0 along the edges in Tr. 6.Expand node n by generating a set M of successors and connect them to n. Also put the members of M on OPEN. 7.Reorder the list OPEN according to a specific rule. 8.Go to step 3. 6.Expand node n by generating a set M of successors that are not already ancestors of n in Tr. Connect each node in M to node n. Also put the members of M on OPEN.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 19 Algorithm A* The algorithm shown on the previous slide, using a heuristic estimation function f’(n) = g’(n) + h’(n), is also called Algorithm A*. Under the following conditions, A* is guaranteed to find the minimal cost path: Each node in the graph has a finite number of successors (or no successors). Each node in the graph has a finite number of successors (or no successors). All edges in the graph have costs greater than some positive amount . All edges in the graph have costs greater than some positive amount . For all nodes n in the search graph, h’(n)  h(n), that is, h’(n) never overestimates the actual value h(n) – an optimistic estimator. For all nodes n in the search graph, h’(n)  h(n), that is, h’(n) never overestimates the actual value h(n) – an optimistic estimator.

February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 20 Algorithm A* Question: What happens if we use a “stupid” estimation function such as h’(n) = 0 ? Answer: A* is still guaranteed to find a minimal cost path. However, the more closely our function h’(n) is to the actual function h(n), the better will be the efficiency of A* in finding such a path. The effort of finding a good estimator pays off in the efficiency of the algorithm.