CS 312: Algorithm Analysis Lecture #32: Intro. to State-Space Search This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.

Slides:



Advertisements
Similar presentations
Complexity Classes: P and NP
Advertisements

MBD and CSP Meir Kalech Partially based on slides of Jia You and Brian Williams.
BackTracking Algorithms
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
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.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
B ACKTRACK SEARCH ALGORITHM. B ACKTRACKING Suppose you have to make a series of decisions, among various choices, where You don’t have enough information.
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Backtracking What is backtracking?
Constraint Satisfaction Problems. Constraint satisfaction problems (CSPs) Standard search problem: – State is a “black box” – any data structure that.
Search: Representation and General Search Procedure CPSC 322 – Search 1 January 12, 2011 Textbook § 3.0 –
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
CPSC 322, Lecture 12Slide 1 CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12 (Textbook Chpt ) January, 29, 2010.
CS420 lecture ten BACKTRACK. Solution vectors In optimization problems, or more general in search problems, a set of choices are to be made to arrive.
Graph Coloring and Hamiltonian cycles Lecture 22 CS 312.
Backtracking.
Decision Procedures An Algorithmic Point of View
Busby, Dodge, Fleming, and Negrusa. Backtracking Algorithm Is used to solve problems for which a sequence of objects is to be selected from a set such.
Programming & Data Structures
Dr. Jouhaina Chaouachi Siala
CS 312: Algorithm Analysis
Artificial Intelligence Lecture 9. Outline Search in State Space State Space Graphs Decision Trees Backtracking in Decision Trees.
CS 312: Algorithm Design & Analysis Lecture #34: Branch and Bound Design Options for Solving the TSP: Tight Bounds This work is licensed under a Creative.
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
Backtracking. N-Queens The object is to place queens on a chess board in such a way as no queen can capture another one in a single move –Recall that.
Lecture 5: Backtracking Depth-First Search N-Queens Problem Hamiltonian Circuits.
CS 312: Algorithm Analysis Lecture #8: Non-Homogeneous Recurrence Relations This work is licensed under a Creative Commons Attribution-Share Alike 3.0.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
BackTracking CS335. N-Queens The object is to place queens on a chess board in such as way as no queen can capture another one in a single move –Recall.
Contents of Chapter 7 Chapter 7 Backtracking 7.1 The General method
Computer Science CPSC 322 Lecture 13 Arc Consistency (4.5, 4.6 ) Slide 1.
CS 312: Algorithm Design & Analysis Lecture #23: Making Optimal Change with Dynamic Programming Slides by: Eric Ringger, with contributions from Mike Jones,
CS 312: Algorithm Design & Analysis Lecture #12: Average Case Analysis of Quicksort This work is licensed under a Creative Commons Attribution-Share Alike.
CS 312: Algorithm Design & Analysis Lecture #24: Optimality, Gene Sequence Alignment This work is licensed under a Creative Commons Attribution-Share Alike.
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
CS 312: Algorithm Design & Analysis Lecture #35: Branch and Bound Design Options: State Spaces Slides by: Eric Ringger, with contributions from Mike Jones,
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
COPING WITH THE LIMITATIONS OF ALGORITHM POWER
CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.
Slides by: Eric Ringger, adapted from slides by Stuart Russell of UC Berkeley. CS 312: Algorithm Design & Analysis Lecture #36: Best-first State- space.
CS 312: Algorithm Analysis Lecture #7: Recurrence Relations a.k.a. Difference Equations Slides by: Eric Ringger, with contributions from Mike Jones, Eric.
CS 312: Algorithm Analysis Lecture #33: Branch and Bound, Job Assignment This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
CS 312: Algorithm Analysis Lecture #31: Linear Programming: the Simplex Algorithm, part 2 This work is licensed under a Creative Commons Attribution-Share.
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.
CS 312: Algorithm Analysis Lecture #35: Branch and Bound Design Options - State Spaces Slides by: Eric Ringger, with contributions from Mike Jones, Eric.
Analysis & Design of Algorithms (CSCE 321)
Chapter 13 Backtracking Introduction The 3-coloring problem
CS 312: Algorithm Analysis Lecture #31: Linear Programming: the Simplex Algorithm, part 2 This work is licensed under a Creative Commons Attribution-Share.
February 11, 2016Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 State-Space Graphs There are various methods for searching.
1 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart CSC384: Lecture 16  Last time Searching a Graphplan for a plan, and relaxed plan heuristics.
CS 312: Algorithm Analysis Lecture #9: Recurrence Relations - Change of Variable Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer,
CS 312: Algorithm Design & Analysis Lecture #26: 0/1 Knapsack This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
CS 312: Algorithm Design & Analysis Lecture #29: Network Flow and Cuts This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
CS 312: Algorithm Analysis Lecture #30: Linear Programming: Intro. to the Simplex Algorithm This work is licensed under a Creative Commons Attribution-Share.
Unit – 5: Backtracking For detail discussion, students are advised to refer the class discussion.
CSG3F3/ Desain dan Analisis Algoritma
BackTracking CS255.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
CS 188: Artificial Intelligence
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Back Tracking.
Analysis and design of algorithm
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.
Backtracking and Branch-and-Bound
Unit –VII Coping with limitations of algorithm power.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Presentation transcript:

CS 312: Algorithm Analysis Lecture #32: Intro. to State-Space Search This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative Commons Attribution-Share Alike 3.0 Unported License Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, and Sean Warnick

Announcements  Project #6  Early: today  who will submit early?  Due: Wednesday  Project #7: TSP – last project!  We will have a bake-off competition!

A little perspective “NP-completeness is not a death certificate – it is only the beginning of a fascinating adventure.” -- Dasgupta et al. (our textbook authors)

Objectives  Formulate algorithmic solutions to (intractable) problems  Use a systematic approach called “state-space search”  Start with brute-force back-tracking state-space search  Improvements: intelligent back-tracking state- space search

 Assign colors to the vertices of a graph  So that no adjacent vertices share the same color  Vertices i and j are adjacent if there is an edge from vertex i to vertex j.  Find all m-colorings of a graph  i.e., find all ways to color a graph with at most m colors. Graph Coloring Problem

States  State is another name for a partial solution. Solution: States: Initial State: Child / Successor State:

State-Space Search Note the resemblance to the enumeration of computation paths pursued by a Non-deterministic TM.

State-Space Search  What to store in each state?  What to store in the initial state?  How to expand a state into successor states?  i.e., How to generate children?  How to search?  Properties of the state space:  Is it a graph with shared sub-structure?  Is it simply a tree?

Example: Graph Coloring State: Copy of graph Colors assigned to a subset of the vertices Mark to indicate which vertex to color next State Expansion: For all possible updates to the marked vertex: Copy parent state Assign a color to the marked vertex Advance the mark to another vertex Initial State: Copy of graph No colors Mark on one vertex to indicate which vertex to color first m = 3 colors

State-Space Search Options 1.Brute-force back-tracking state-space search  No pruning  Pure enumeration  Let’s start with this idea. 2.Intelligent back-tracking state-space search  Pruning  i.e., Test partial states and eliminate those that are not feasible

Example: Graph Coloring m=3 Red Yellow Blue

Example: Graph Coloring m=3 Red Yellow Blue

Example: Graph Coloring m=3 Red Yellow Blue

Example: Graph Coloring m=3 Red Yellow Blue

Example: Graph Coloring m=3 Red Yellow Blue

Example: Graph Coloring m=3 Red Yellow Blue

Example: Graph Coloring m=3 Red Yellow Blue

Algorithm: Brute-force State-space Search procedure brute-force-explore(state s) Input: current state s Output: none; prints solutions for each s’  successors(s) if criterion(s’) then output “Solution:” s’ else // possible solution not yet fully specified explore(s’) Outer-most call: explore( init_state() ) For the m-coloring example, we put a little bit of intelligence in the successors() function.

Aside: Coloring a Map  Assign colors to countries so that no two bordering regions are the same color.  Map coloring is reducible to planar graph coloring. UtahNevada Idaho Colorado New Mexico Wyoming Arizona

Color Theorem  How many colors do you need for a planar map?  First proposed in 1852  Answer: Four  Proved by Haken and Appel in 1976  Used a computer program  Checked 1,476 graphs, i.e., cases in the proof  Required 1,200 hours of run-time

State-space size  Consider how large the set of leaf states in the search space could be  (without pruning)

n-Queens Problem  Given: n-queens and an n  n chess board  Find: A way to place all n queens on the board s.t. no queens are attacking another queen. Can you formulate an algorithmic solution to this problem as state-space search? How would you represent a state?

First State-Space Idea  Consider all possible placements of the queens on a chess board.  Represent a state as a chess board.  How many placements are there?

First State-Space Idea  Consider all possible placements of the queens on a chess board.  Represent a state as a chess board.  How many placements are there? Recall:

Second State-Space Idea  Don’t place 2 queens in the same row.

(1,1,1,1,1,1,1,1) Queen in Row #1 (Q1)

(1,1,1,1,1,1,1,1) Queen in Row #5 (Q5)

(1,1,1,1,1,1,1,2)

(1,1,1,1,1,1,1,3)

Second State-Space Idea  Don’t place 2 queens in the same row.  Represent a state as a list of columns.  Now how many positions must be checked? Represent a positioning as an ordered tuple (x 1, …, x 8 ) Where each element is an integer 1, …, 8.

Third State-Space Idea  Don’t place 2 queens in the same row or in the same column.

(1,2,3,4,5,6,7,8)

(1,2,3,4,5,6,8,7)

(1,2,3,4,5,8,6,7)

(1,2,3,4,5,8,7,6)

Third State-Space Idea  Don’t place 2 queens in the same row or in the same column.  Represent a state as a permutation of (1,2…8)  Now how many positions must be checked?  It is easy to enumerate all permutations  We went from C(n 2, n) to n n to n!  And we’re happy about it!  We applied explicit constraints in the enumeration of successor states to shrink our state space up front.

Lessons  Be smart about how to represent states.  So far, efficiency of state-space search depends on: 1.The number of successor states satisfying the explicit constraints 2.The time to generate the successor states

Intelligent Back-tracking State Space Search  Aside from intelligently describing states,  Do: We check a solution after placing all queens:  criterion function (i.e., a solution test): yes or no  To do: We should check after each placement of a queen.  partial-criterion function (i.e., a feasibility test): yes or no  Let’s see how this will help …

Four Queens Problem 1234 Easier to manage in a lecture. Let’s illustrate in more detail how intelligent back-tracking works.

Four Queens Problem 1234 Each branch of the tree represents a decision to place a queen. The criterion function can only be applied to leaf states. x1 = 1 x2 = 2 x3 = 3 x4 = 4

Four Queens Problem 1234 x1 = 1 Is this leaf state a solution? x2 = 2 x3 = 3 x4 = 4

Four Queens Problem 1234 x1 = 1 Is this leaf state a solution? x2 = 2 x3 = 3 x4 = 4 x3 = 4 x4 = 3

Four Queens Problem Using only a criterion function (at the leaves), we would build out the entire state space.

Four Queens Problem 1234 x1 = 1 A better question: Is any child of this state ever going to be a solution? (before placing queens #3 and #4) x2 = 2 x3 = 3 x4 = 4 x3 = 4 x4 = 3

Four Queens Problem 1234 x1 = 1 A better question: Is any child of this state ever going to be a solution? No. 1 is attacking 2. Adding queens won’t fix the problem. x2 = 2 x3 = 3 x4 = 4 x3 = 4 x4 = 3

Four Queens Problem 1234 x1 = 1 The partial criterion or feasibility function checks whether a state may eventually have a solution. Will this state have a solution? no. So we prune and back- track early x2 = 2

Four Queens Problem 1234 x1 = 1 Will this state have a solution? Maybe. x2 = 2x2 = 3

Four Queens Problem 1234 x1 = 1 Will this state have a solution? No. Etc. x2 = 2 x3 = 2 x2 = 3

Four Queens Problem 1234 x1 = 1 Will this state have a solution? No. Etc. x2 = 2 x3 = 2x3 = 4 x2 = 3

Four Queens Problem 1234 x1 = 1 And so on … x2 = 2 x3 = 2x3 = 4 x2 = 3 x2 = 4

Four Queens Problem 1234 x1 = 1 And so on … x2 = 2 x3 = 2x3 = 4 x2 = 3 x2 = 4 x1 = 2

Four Queens Problem Using the feasibility function, the resulting state space is shown in dark blue. x1 = 1 x1 = 2 x1 = 3 x1 = 4

Alternate Notation  The “feasible extensions set”:  T(x 1, x 2, …, x i ) = {y | (x 1, x 2,... x i, y) might be a solution}  B i+1 is the feasibility function  If B i+1 (x 1, x 2, …, x i+1 ) is false for a path (x 1, x 2, …, x i+1 ) from the root state to a problem state, then the path cannot be extended to reach an answer state.  The candidates for position i + 1 of the solution vector (x 1,…, x i ) are those values which are in T and which satisfy B i+1

Algorithm: Intelligent Back-tracking State-space Search procedure intelligent-explore(state s) Input: current state s Output: Solution or {} (failure) for each s’  successors(s) if criterion(s’) then output “Solution:” s’ else if partial_criterion(s’) then explore(s’) else discard s’ Outer-most call: explore( init_state() )

Efficiency of Back-tracking Algorithms depends on: 1.The number of successor states satisfying the explicit constraints 2.The time to generate the successor states 3.The proportion of successor states satisfying the partial criterion function 4.The time to compute the partial criterion (feasibility)  Can substantially reduce the number of states that are generated.  But: also takes time to evaluate.

Conclusions  Can formulate an algorithm for just about any problem as a state-space search.  Have some intelligent options for implementing state-space search  State spaces are large for the hard problems  But some state spaces are small  e.g., for the combinatoric algorithms encountered so far in the course

Assignment  Homework #23: State-space search  Read Sec