Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

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

3 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)

4 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

5  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

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

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

8 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?

9 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

10 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

11 Example: Graph Coloring m=3 Red Yellow Blue

12 Example: Graph Coloring m=3 Red Yellow Blue

13 Example: Graph Coloring m=3 Red Yellow Blue

14 Example: Graph Coloring m=3 Red Yellow Blue

15 Example: Graph Coloring m=3 Red Yellow Blue

16 Example: Graph Coloring m=3 Red Yellow Blue

17 Example: Graph Coloring m=3 Red Yellow Blue

18 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.

19 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

20 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

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

22 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?

23 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?

24 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:

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

26 1 2 3 4 5 6 7 8 12345678 (1,1,1,1,1,1,1,1) Queen in Row #1 (Q1)

27 1 2 3 4 5 6 7 8 12345678 (1,1,1,1,1,1,1,1) Queen in Row #5 (Q5)

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

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

30 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.

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

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

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

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

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

36 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.

37 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

38 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 …

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

40 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

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

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

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

44 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

45 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

46 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

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

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

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

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

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

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

53 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

54 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() )

55 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.

56 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

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

58


Download ppt "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."

Similar presentations


Ads by Google