A General Backtracking Algorithm

Slides:



Advertisements
Similar presentations
Review: Search problem formulation
Advertisements

An Introduction to Artificial Intelligence
Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
BackTracking Algorithms
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2007.
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.
Problem Solving and Search Andrea Danyluk September 9, 2013.
Solving Problems by Searching Currently at Chapter 3 in the book Will finish today/Monday, Chapter 4 next.
G5BAIM Artificial Intelligence Methods Graham Kendall Blind Searches.
Lets remember about Goal formulation, Problem formulation and Types of Problem. OBJECTIVE OF TODAY’S LECTURE Today we will discus how to find a solution.
Artificial Intelligence (CS 461D)
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move.
Artificial Intelligence Lecture No. 7 Dr. Asad Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Lecture 3 Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi. Text Book - Aritificial Intelligence Illuminated.
Review: Search problem formulation
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2004.
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
Artificial Intelligence Chapter 3: Solving Problems by Searching
Uninformed Search Reading: Chapter 3 by today, Chapter by Wednesday, 9/12 Homework #2 will be given out on Wednesday DID YOU TURN IN YOUR SURVEY?
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
Using Search in Problem Solving
CS 188: Artificial Intelligence Spring 2006 Lecture 2: Queue-Based Search 8/31/2006 Dan Klein – UC Berkeley Many slides over the course adapted from either.
Uninformed Search (cont.)
Review: Search problem formulation Initial state Actions Transition model Goal state (or goal test) Path cost What is the optimal solution? What is the.
Vilalta&Eick:Uninformed Search Problem Solving By Searching Introduction Solutions and Performance Uninformed Search Strategies Avoiding Repeated States/Looping.
Goal-based Problem Solving Goal formation Based upon the current situation and performance measures. Result is moving into a desirable state (goal state).
Introduction to Artificial Intelligence (G51IAI) Dr Rong Qu Blind Searches - Introduction.
Implementation: General Tree Search
Chapter 13 Backtracking Introduction The 3-coloring problem
Fahiem Bacchus © 2005 University of Toronto 1 CSC384: Intro to Artificial Intelligence Search II ● Announcements.
February 11, 2016Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 State-Space Graphs There are various methods for searching.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
February 18, 2016Introduction to Artificial Intelligence Lecture 8: Search in State Spaces III 1 A General Backtracking Algorithm Sanity check function.
Search Part I Introduction Solutions and Performance Uninformed Search Strategies Avoiding Repeated States Partial Information Summary.
Biointelligence Lab School of Computer Sci. & Eng. Seoul National University Artificial Intelligence Chapter 8 Uninformed Search.
Artificial Intelligence Solving problems by searching.
Lecture 3 Problem Solving through search Uninformed Search
Lecture 3: Uninformed Search
Review: Tree search Initialize the frontier using the starting state
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
BackTracking CS255.
Introduction to Artificial Intelligence
Problem Solving by Searching
Problem Solving as Search
Artificial Intelligence (CS 370D)
Artificial Intelligence Problem solving by searching CSC 361
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
CS 188: Artificial Intelligence Fall 2008
Problem Solving and Searching
Search Related Algorithms
CSE 4705 Artificial Intelligence
EA C461 – Artificial Intelligence
Artificial Intelligence
Searching for Solutions
Problem Solving and Searching
Search Exercise Search Tree? Solution (Breadth First Search)?
Artificial Intelligence
Haskell Tips You can turn any function that takes two inputs into an infix operator: mod 7 3 is the same as 7 `mod` 3 takeWhile returns all initial.
Artificial Intelligence
Artificial Intelligence Chapter 8 Uninformed Search
A General Backtracking Algorithm
UNINFORMED SEARCH -BFS -DFS -DFIS - Bidirectional
State-Space Searches.
State-Space Searches.
ECE457 Applied Artificial Intelligence Fall 2007 Lecture #2
CMSC 471 Fall 2011 Class #4 Tue 9/13/11 Uninformed Search
State-Space Searches.
Lecture 4: Tree Search Strategies
Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -
Presentation transcript:

A General Backtracking Algorithm Let us say that we can formulate a problem as a sequence of n successive decisions, in each of which we pick one choice out of a predefined set of options. For example, in the 4-queens problem we have to make four decisions, each of which consists in placing a queen in one of the four rows. We could formalize each decision as choosing one element from the set of rows [1, 2, 3, 4]. This set is the same for all four decisions. Therefore, we can describe the overall choices we have for this problem as: [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]] (placing the first, second, third, and fourth queen) September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

A General Backtracking Algorithm We can build our plan for solving the problem by starting at the root with an empty list [] and adding (prepending) our decisions as we move down the tree. For example, if we decide to place the first three queens in rows 3, 1, and 4, our current plan is [4, 1, 3]. Obviously, any solution of the problem is represented by a list of length four. We also need a “sanity check” function that tells us if a decision, given the current plan, makes sense, i.e., could potentially lead to a solution. Let us call it fQueens for the 4-queens problem: fQueens 4 [4, 1, 3] = False fQueens 2 [4, 1] = True September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Voluntary Homework Write the function fQueens :: Int -> [Int] -> Bool in Haskell. It is actually easiest if you allow it to check the status of any n-queens problem instead of only the 4-queens one. (2) Write a function backtrack :: (a->[a]->Bool) -> [a] -> [[a]] -> [a] that takes a “sanity” function such as fQueens, a start plan – usually [] – and a list of the choices at each level, in our case [[1,2,3,4], [1,2,3,4], [1,2,3,4], [1,2,3,4]] and outputs a solution, i.e., a successful plan (here: a list of four numbers). I know that this is a tricky task, but it is very useful for not only practicing Haskell but also really understanding backtracking. If you have extra time and energy, you could also write a function that turns the list output into a console visualization of queens on a chessboard (e.g. an array of “Q”s vs. “.”s). September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Breadth-First September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Breadth-First 1 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Breadth-First 1 2 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Breadth-First 1 2 3 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Breadth-First 1 2 3 4 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Breadth-First 1 2 3 4 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Depth-First September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Depth-First 1 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Depth-First 1 2 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Depth-First 1 2 3 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Depth-First 1 2 3 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Depth-First 1 2 3 4 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Depth-First 1 2 3 4 5 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Uninformed Search: Depth-First 1 2 3 4 5 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Breadth-First vs. Depth-First Uninformed breadth-first search: Requires the construction and storage of almost the complete search tree. Space complexity for search depth n is O(en). Is guaranteed to find the shortest path to a solution. Uninformed depth-first search: Requires the storage of only the current path and the branches from this path that were already visited. Space complexity for search depth n is O(n). May search unnecessarily deep for a shallow goal. September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening Iterative deepening is an interesting combination of breadth-first and depth-first strategies: Space complexity for search depth n is O(n). Is guaranteed to find the shortest path to a solution without searching unnecessarily deep. How does it work? The idea is to successively apply depth-first searches with increasing depth bounds (maximum search depth). September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

maximum search depth = 0 (only root is tested) Iterative Deepening maximum search depth = 0 (only root is tested) September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening maximum search depth = 1 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening maximum search depth = 2 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening maximum search depth = 3 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening maximum search depth = 4 September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening But it seems that the time complexity of iterative deepening is much higher than that of breadth-first search! Well, if we have a branching factor b and the shallowest goal at depth d, then the worst-case number of nodes to be expanded by breadth-first is: September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening In order to determine the number of nodes expanded by iterative deepening, we have to look at depth-first search. What is the worst-case number of nodes expanded by depth-first search for a branching factor b and a maximum search level j ? September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening Therefore, the worst-case number of nodes expanded by iterative deepening from depth 0 to depth d is: September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II

Iterative Deepening Let us now compare the numbers for breadth-first search and iterative deepening: For large d, you see that Nid/Nbf approaches b/(b – 1), which in turn approaches 1 for large b. So for big trees (large b and d), iterative deepening does not expand many more nodes than does breadth-first search (about 11% for b = 10 and large d). September 20, 2018 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II