1 / 39

Introduction to State Space Search

Introduction to State Space Search. Robin Boswell. Contents. How to represent a problem in the form of a state-space search Some formal definitions Initial states, goal states, operators The painted squares example Choice of operators affects the search space

kare
Download Presentation

Introduction to State Space Search

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to State Space Search Robin Boswell The Robert Gordon University

  2. Contents • How to represent a problem in the form of a state-space search • Some formal definitions • Initial states, goal states, operators • The painted squares example • Choice of operators affects the search space • Estimating the size of the search space • Other problems that can be represented in a similar way • Machine learning as search The Robert Gordon University

  3. State Space Representation • To represent a problem as a state-space search • Define the states • Define the initial and goal states • Define the possible operators in any given state. • Example: Chess • State = position; what occupies each square of the board • Initial state – traditional starting position • Final state – checkmate or draw • Operators correspond to legal chess moves

  4. Problem Solving using State Space Search • Define the problem • What are the initial and goal states? • If we’re talking about a game, then • Starting position • Legal moves • Winning positions • Analyse the problem to suggest appropriate solution methods • In chess, try thinking a few moves ahead • Choose the best technique and apply it • In chess, make a move which gives us advantage whilst blocking our opponent The Robert Gordon University

  5. State Space Representation • State space representation consists of a graph where • Nodes correspond to states, and • Arcs are steps in the problem-solving • The initial state is the start of the problem • Goal condition is usually a property of a state, e.g. • A winning position (chess, Os & Xs) • The farmer and his possessions are on the far side of the river • The goal can also be a property of the whole path, e.g. • Travelling salesman problem The Robert Gordon University

  6. Fox, Chicken, Corn, Man Man, Chicken Fox, Corn Fox, Corn Chicken, Man State state representation: Example Initial state Man takes chicken into boat Man takes corn into boat X Goal state

  7. More formal definition of a state space • A state space consists of • S: a set of states • O: a set of operators • I: a subset of S which are initial states • G: a subset of S which are goal states • These states are recognised by either • Properties of the state, or • Properties of the path by which they were reached • A state space can be represented as a graph, where • Nodes are states in S • Arcs are specified by ordered pairs of states in S: (s1, s2), where • o: s1 s2 for some o in O The Robert Gordon University

  8. I s4 s24 s33 s54 G s67 A solved search problem (s24, s33) o2 o2:s24  s33 The Robert Gordon University

  9. The Painted Squares Problem Task: Arrange the squares in a 2x2 grid so that adjacent sides have the same colour The Robert Gordon University

  10. One state-space representation for painted squares Place all four tiles, and test whether the result is a solution to the problem # ways of assigning tiles to slots (ignoring tile orientation): 4 x 3 x 2 x 1 = 4! Each tile can be in one of 4 orientations, giving 44 possibilities for all the tiles.  Total number of arrangements is 4! X 44 = 6144 The Robert Gordon University

  11. An alternative representation 4x4x4 = 64 nodes in first row • Operator: • Select an unused tile • Orient the tile • Place in any legal vacant square The Robert Gordon University

  12. A smaller state space 1 23 4 4x4 = 16 nodes in first row (instead of 64) • Operator: • Select an unused tile • Orient the tile • Place in the next vacant square The Robert Gordon University

  13. Estimating the size of this space ? 4 x 4 = 16 nodes in first row Each node has at most 4x3 children ? so 42 x 4 x 3 nodes in the second row Each node has at most 4x2 children so 43 x 4 x 3 x 2 nodes in the third row The Robert Gordon University

  14. Estimating the size of the space (cont) • An upper bound on the size of the search space is • 1 + 4x4 + 42x4x3 + 43x4x3x2 + 44x4x3x2 = 7889 • However, in practice the size will be much smaller than this, because • Paths are pruned when a state with mis-matched sides is found • Typically you will find a solution without searching the whole tree • You can use knowledge of symmetry to reduce the search further

  15. Using knowledge of symmetries to reduce the search space For every solution, there are three equivalent solutions, obtained by rotation If you constrain your search so that the “double-red” tile always appears top left, you will only find the second of these. However, you haven’t lost any significantly different solutions, and you’ve reduced the search space to roughly ¼ of its original size

  16. Summary of state representation • Representation should • Contain all the necessary information • Be easy to apply the operators to • Be easy to understand • For efficiency • Each solution should only appear once in the tree • Should be only one route to the solution • Identify failures early The Robert Gordon University

  17. 1 2 3 4 A possible board representation We’re going to add tiles to the board in the order shown. If we use a linked list to represent the board, then it’s more efficient to add elements to the left-hand end, so we store the cells in reverse order: [ S4 S3 S2 S1 ] [ ] [ S1 ] [ S2 S1 ] [ S3 S2 S1 ] [ S4 S3 S2 S1 ] The Robert Gordon University

  18. Ob1 Ob2 Ob3 Linked List • Operations: • Add object to top of list • Remove object from top of list • Iterate along list • Advantages • Dynamic structure • Language independent • Can implement in C • Exists in Java as class LinkedList in java.util • A basic data structure in Lisp and Prolog The Robert Gordon University

  19. A possible tile representation • For each tile we need an identifier, a list of colours, and an orientation • Suppose we code the colours as integers: 1 = Blue, 2 = Red, 3 = Green, 4 = Yellow • Code orientations as follows: 1 = 0 quarter turns clockwise 2 = 1 quarter turns clockwise 3 = 2 quarter turns clockwise 4 = 3 quarter turns clockwise Identifier = p1Colours = [ 1 2 3 3 ] /* listed anti-clockwise from base */ Tile p1 with orientation 3 The Robert Gordon University

  20. Putting the tiles on the board Add tile p1 with orientation 3 Add tile p4 with orientation 1 • The board is represented as a list • The tiles are represented as • Lists (LISP) • Objects (Java) – see next slide [ ] [ [p1, 3 ] ] [ [p4, 1 ], [p1, 3 ] ] The Robert Gordon University

  21. A possible tile representation in Java public class Tile { private int mytileno; private int myorientation; /* Colours of each tile, listed anti-clockwise from base */ private int colours[][] = { { 3, 1, 2, 1}, /* tile p1 */ {4, 3, 1, 4}, /* tile p2 */ {3, 1, 4, 2}, /* tile p3 */ {2, 2, 1, 4} }; /* tile p4 */ Tile( int tileno, int orientation) { mytileno = tileno; myorientation = orientation; } /* Return list of colours, listed anti-clockwise from base, taking account of orientation */ public int [] getColours() { … }}

  22. Other problems which can be represented as a state-space search… The Robert Gordon University

  23. The water jugs problem • You have two jugs, holding respectively 3 and 4 gallons, and a water supply. • How do you get exactly 2 gallons into the 4 gallon jug? The Robert Gordon University

  24. Farmer, Wolf, Goat and Cabbage • Farmer, wolf, goat and cabbage wish to cross a river by boat. • If left alone • Wolf will eat goat • Goat will eat cabbage • How can all four cross the river? • Similar problem • 3 missionaries and 3 cannibals wish to cross a river using a boat that will hold only 2 people. • If there are ever more cannibals than missionaries on either bank, the missionaries will eat the cannibals The Robert Gordon University

  25. The 8-puzzle The Robert Gordon University

  26. London Cardiff Dublin Edinburgh … London 0 223 470 538 Cardiff 223 0 290 495Dublin 470 290 0 350Edinburgh 538 495 350 0… Travelling salesman problem The Robert Gordon University

  27. Tower of Hanoi • By moving the discs one at a time, transfer the discs from the first to the third pole. • No disc can ever rest on a smaller disc The Robert Gordon University

  28. Monkey and Bananas The monkey can move around, carry things around, and wave the stick around.What sequence of actions allows the monkey to eat the bananas? The Robert Gordon University

  29. Cryptarithmetic S E N D M O R E M O N E Y + Each letter represents one digit. No two letters can be assigned to the same digit. Work our which digit each letter must represent if the sum works out correctly The Robert Gordon University

  30. Equation solving loge(x+1) + loge(x-1) = 3 loge((x+1)(x-1)) = 3 elog(x+1) + log(x-1) = e3 loge(x+1) = 3 - loge(x-1) loge(x2-1) = 3 x = … The Robert Gordon University

  31. Machine Learning describes a variety of techniques and applications, most of which require some form of search… The Robert Gordon University

  32. Machine Learning / Data Mining • Aim is to identify patterns in data which can be used to make predictions • Applications: • Diagnosis • Liver Disease • Disease of soybeans • Classification • Species of iris The Robert Gordon University

  33. Machine Learning / Data Mining Sample data on playing outdoor games outlook temp humidity windy play sunny hot high false no sunny hot high true no overcast hot high false yes rainy mild high false yes sunny mild high false no … Rule: If outlook is sunny and humidity = high then play = no Test example: sunny hot high true ? The Robert Gordon University

  34. Machine Learning / Data Mining Sample data on contact lense recommendation Age Eyesight Astigmatism Tear production lenses young myope no reduced none young myope no normal soft Prepresbyopic myope no reduced none presbyopic myope yes normal hard … If tear production rate is normal and age = young astigmatic = noThen recommendation = soft Test example: Young myope yes normal ? The Robert Gordon University

  35. Machine Learning / Data Mining • Given a set of examples • Derive a classifier (set of rules) which classify the examples • Use the classifier to classify new examples The Robert Gordon University

  36. Machine Learning as search A very inefficient approach: Generate and test If outlook is sunnyand temp is hotand humidity is highand windy is falseThen play is no If outlook is overcastand temp is hotand humidity is highand windy is falseThen play is no If outlook is rainyand temp is hotand humidity is highand windy is falseThen play is no If outlook is sunnyand temp is mildand humidity is highand windy is falseThen play is no Evaluate each rule against the test examples The Robert Gordon University

  37. Machine Learning as search Generate and test If outlook is sunnyThen play is no If temp is hotThen play is no If outlook is overcastThen play is yes If temp is mildThen play is yes If outlook is sunnyAnd temp is mildThen play is no If outlook is sunnyAnd humidity is highThen play is no May choose to reject rules of low accuracy, or which describe few examples If outlook is sunnyAnd temp is mildAnd humidity is highThen play is no The Robert Gordon University

  38. Conclusions • Many problems can be represented in the form of a state space search • Nodes correspond to states • Arcs correspond to steps in problem solving = applications of operators • A good choice of operators • Will reduce the search space • Will not rule out any possible solutions • You can also use knowledge of symmetries to reduce the search space • Given a set of operators, you can calculate an upper bound to the size of a (finite) search space The Robert Gordon University

  39. Where next… • This week’s lab: Lisp implementation of the painted squares problem • This week’s tutorial: exercises in representing problems as state space search, and estimating the size of the spaces • Next week: Algorithms for searching the state space Java Lab The Robert Gordon University

More Related