Download presentation
Presentation is loading. Please wait.
Published byLawrence Cain Modified over 9 years ago
1
1 State Space of a Problem Lecture 03 ITS033 – Programming & Algorithms http://www.vcharkarn.com/vlesson/showlesson.php?lessonid=7&pageid=4 Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information, Computer and Communication Technology (ICT) Sirindhorn International Institute of Technology (SIIT) Thammasat University http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th 02 5013505 X 2005
2
2 ITS033 Topic 01-Problems & Algorithmic Problem Solving Topic 01 - Problems & Algorithmic Problem Solving Topic 02 – Algorithm Representation & Efficiency Analysis Topic 03 - State Space of a problem Topic 04 - Brute Force Topic 05 - Divide and Conquer Topic 06-Decrease and Conquer Topic 06 - Decrease and Conquer Topic 07 - Dynamics Programming Topic 08-Transform and Conquer Topic 08 - Transform and Conquer Topic 09 - Graph Algorithms Topic 10 - Minimum Spanning Tree Topic 11 - Shortest Path Problem Topic 12 - Coping with the Limitations of Algorithms Power http://www.siit.tu.ac.th/bunyarit/its033.php and http://www.vcharkarn.com/vlesson/showlesson.php?lessonid=7
3
3 This Week Overview State of a Problem State Space Rules State Space Traversal State space and problem solving
4
4 State Space: A problem representation Lecture 02.1 ITS033 – Programming & Algorithms Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information, Computer and Communication Technology (ICT) Sirindhorn International Institute of Technology (SIIT) Thammasat University http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th 02 5013505 X 2005 http://www.vcharkarn.com/vlesson/showlesson.php?lessonid=7&pageid=4
5
5 To solve a problem computationally, we have to translate the problem into something that computer can understand. To solve a problem computationally, we have to translate the problem into something that computer can understand. In other words, we have to define state of the problem. In other words, we have to define state of the problem. The states of a problem should be defined mathematically or with a specific data structure. The states of a problem should be defined mathematically or with a specific data structure. State of a problem
6
6 A possible state of a problem is one of the specific choices made for a solution’s components. A possible state of a problem is one of the specific choices made for a solution’s components. Or a specific combination from all possibilities. Or a specific combination from all possibilities. Or a possible step in the problem. Or a possible step in the problem. State of a problem
7
7 We have two empty containers (with no scale), one can hold 4 gallons of water, the other 3 and plenty of water. We have two empty containers (with no scale), one can hold 4 gallons of water, the other 3 and plenty of water. How can we have exactly 2 gallons of water in container A ? How can we have exactly 2 gallons of water in container A ? Write a program to solve this problem with user’s input of different size of containers ? Write a program to solve this problem with user’s input of different size of containers ? Example 1 : Water Jug Problem 3 Gal B 4 Gal A
8
8 Water Jug State A state in this problem could be define as (X, Y) Where X is a number of gallons in A, and Y is a number of gallons in B
9
9 Water Jug Problem: Possible States (0,0) (1,1)(2,1)(3,1) (0,2)(1,2)(3,2) (1,3)(2,3)(3,3) (4,0) (4,3)
10
10 Two important states in a problem Initial State is a first state given by the problem Initial State is a first state given by the problem Goal State is a solution state where the problem wants to reach. Goal State is a solution state where the problem wants to reach. State of a problem
11
11 Water Jug Problem The initial state is when both jugs are empty: (0,0) The goal state is any state that has 2 gallons in container A: (2,n) for any n
12
12 Water Jug States (0,0)(2,0) (2,1) (2,2) (2,3) Goal States Initial State
13
13 Example 2: Knight Traversal Problem On a 8 x 8 chess board, move a knight from any initial position to all position on the board. (see demo 1) + It would be best if the knight make minimum number of move to complete the journey. (see demo 2) + define State of the problem.
14
14 Knight Traversal What’s wrong with this state representation ? A state in this problem could be define as (X, Y) Where X is {1, 2, 3, 4, 5, 6, 7, 8} and Y is {1, 2, 3, 4, 5, 6, 7, 8}
15
15 The 8-puzzle - also known as the sliding- block/tile-puzzle - is one of the most popular instrument in the artificial intelligence (AI) studies. The 8-puzzle - also known as the sliding- block/tile-puzzle - is one of the most popular instrument in the artificial intelligence (AI) studies. Arrange the tiles so that all the tiles are in the correct positions. You do this by moving tiles. You can move a tile up, down, left, or right, so long as the following conditions are met: Arrange the tiles so that all the tiles are in the correct positions. You do this by moving tiles. You can move a tile up, down, left, or right, so long as the following conditions are met: A) there's no other tile blocking you in the direction of the movement; and A) there's no other tile blocking you in the direction of the movement; and B) you're not trying to move outside of the boundaries/edges. If you wish to try another picture, try this. B) you're not trying to move outside of the boundaries/edges. If you wish to try another picture, try this. Example 3 - 8 Puzzle 146 82 375 12378465
16
16
17
17 A man finds himself on a riverbank with a wolf, a goat, and a head of cabbage. He needs to transport all three to the other side of the river in his boat. However, the boat has room for only the man himself and one other item. In his absence, the wolf would eat the goat, and the goat would eat the cabbage. The man is vegetarian who doesn’t like to eat cabbage. Define state for this problem. River-Crossing Puzzle Example 4 - River-Crossing Puzzle
18
18 State Space Lecture 02.2 ITS033 – Programming & Algorithms Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information, Computer and Communication Technology (ICT) Sirindhorn International Institute of Technology (SIIT) Thammasat University http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th 02 5013505 X 2005 http://www.vcharkarn.com/vlesson/showlesson.php?lessonid=7&pageid=4
19
19 State Space of a problem is a space containing all possible states of the problem. State Space of a problem is a space containing all possible states of the problem. State Space
20
20 Water Jug State Space The state can be represented by 2 integers x and y: x = gallons in the 4 gallon jug y = gallons in the 3 gallon jug State Space = (x,y) such that x {0,1,2,3,4}, y {0,1,2,3}
21
21 Water Jug Problem: Possible States (0,0)(1,0)(2,0)(3,0) (0,1)(1,1)(2,1)(3,1) (0,2)(1,2)(2,2)(3,2) (0,3)(1,3)(2,3)(3,3) (4,0) (4,1) (4,2) (4,3)
22
22 It is usually not possible to list all possible states: It is usually not possible to list all possible states: use abstractions to describe legal states. It may be easier to describe the illegal states. Sometimes it is useful to provide a general description of the state space and a set of constraints. State Space of a problem
23
23 Two types of states in a problem Legal States are possible states in the problem which can be reached and follow the rules of that problem. Legal States are possible states in the problem which can be reached and follow the rules of that problem. Illegal States are possible states in the problem that violate the rules of that problem. Illegal States are possible states in the problem that violate the rules of that problem. State of a problem
24
24 Example Problem - 3 Puzzle Sliding Tile game with 3 tiles: 12 32 1 3 start stategoal state
25
25 State Space: Rules Lecture 02.3 ITS033 – Programming & Algorithms Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information, Computer and Communication Technology (ICT) Sirindhorn International Institute of Technology (SIIT) Thammasat University http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th 02 5013505 X 2005 http://www.vcharkarn.com/vlesson/showlesson.php?lessonid=7&pageid=4
26
26 Solving a problem means searching for a path in the state space from a starting state to a goal state. Solving a problem means searching for a path in the state space from a starting state to a goal state. That’s why we need to devise a set of operations (rules) that changes from one state to another. That’s why we need to devise a set of operations (rules) that changes from one state to another. Rules
27
27 The problem solving system moves from one state to another according to well defined operations. The problem solving system moves from one state to another according to well defined operations. Typically these operations are described as rules. Typically these operations are described as rules. A control system decides which rules are applicable at any state, and resolves conflicts and/or ambiguities. A control system decides which rules are applicable at any state, and resolves conflicts and/or ambiguities. Rules or Operations
28
28 Water Jug Operations Rule 1 : Fill B from pump move from any state (x,y) to a state (x,3) Rule 2 : Fill A from pump move from any state (x,y) to a state (4,y) Rule 3 : Empty Bmove from any state (x,y) to a state (x,0) Rule 4 : Empty Amove from any state (x,y) to a state (0,y) Fill A from B Rule 5 : Fill A from Bmove from any state (x,y) to a state (x+y, 0) ………. if x+y <= 4 (x+y, 0) ………. if x+y <= 4 (4, x+y mod 4).. if x+y > 4 (4, x+y mod 4).. if x+y > 4 Fill B from A Rule 6 : Fill B from Amove from any state (x,y) to a state (0, x+y) ………. if x+y <= 3 (0, x+y) ………. if x+y <= 3 (x+y mod 3, 3).. if x+y > 3 (x+y mod 3, 3).. if x+y > 3
29
29 Relationship between states (0,0)(4,0) (4,3)(1,3)(0,0) (0,3)(4,3)(3,0)(0,0)
30
30 The search for a solution can be described by a tree - each node represents one state. The path from a parent node to a child node represents an operation Each node is a search tree has child nodes that represent each of the states reachable by the parent state. Each node is a search tree has child nodes that represent each of the states reachable by the parent state. Another way of looking at it: child nodes represent all available options once the search procedure reaches the parent node. Another way of looking at it: child nodes represent all available options once the search procedure reaches the parent node. There are a number of strategies for traversing a search tree. There are a number of strategies for traversing a search tree. Search Concepts Search Tree
31
31 River Crossing Problem: Relationship between states
32
32 Relationship between states
33
33 Rules: Knight Traversal Problem Defines rules for Knight Traversal Problem
34
34 State Space: Problem Solving with State Space Lecture 02.4 ITS033 – Programming & Algorithms Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information, Computer and Communication Technology (ICT) Sirindhorn International Institute of Technology (SIIT) Thammasat University http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th http://www.siit.tu.ac.th/bunyarit bunyarit@siit.tu.ac.th 02 5013505 X 2005 http://www.vcharkarn.com/vlesson/showlesson.php?lessonid=7&pageid=4
35
35 State Space Problem Problem Solving Currently we have, Set of possible states. Set of possible states. Set of possible rules that change the state. Set of possible rules that change the state. Specification of a starting state(s). Specification of a starting state(s). Specification of a goal state(s). Specification of a goal state(s).
36
36 Simple Agent Algorithm Problem-Solving-Agent 1. Find an initial-state 2. Define a goal state 3. Define Rules 4. Find a path from Initial State to a Goal state 5. Done
37
37 Simple Algorithm (not very clever). Initial State Random a rule Change to a new state Check if it is a goal state done yes no
38
38 More complexed Algorithm. Initial State Pick a rule Change to a new state Check if it is a goal state done yes no Do something clever
39
39 Blind (or uninformed) strategies do not exploit any of the information contained in a state Blind (or uninformed) strategies do not exploit any of the information contained in a state Heuristic (or informed) strategies exploits such information to assess that one node is “more promising” than another Heuristic (or informed) strategies exploits such information to assess that one node is “more promising” than another Blind Search Heuristic Search Blind Search vs Heuristic Search
40
40 The blind search - a search for a solution at random. The blind search - a search for a solution at random. Blind search, also called uninformed search, works with no information about the search space, other than to distinguish the goal state from all the others. Blind search, also called uninformed search, works with no information about the search space, other than to distinguish the goal state from all the others. Pure blind search is usually simple to run, and therefore fast to realize. Pure blind search is usually simple to run, and therefore fast to realize. It often finds answers that are good enough for practical purposes, or at least can serve as the preliminary estimates. It often finds answers that are good enough for practical purposes, or at least can serve as the preliminary estimates. Blind State Space Search
41
41 Water Jug States (0,0)(1,0)(2,0)(3,0) (0,1)(1,1)(2,1)(3,1) (0,2)(1,2)(2,2)(3,2) (0,3)(1,3)(2,3)(3,3) (4,0) (4,1) (4,2) (4,3) Goal States Start State
42
42 Heuristic State Space Search The heuristic search - a search for the best answer by assigning a value to each state in the State Space The heuristic search - a search for the best answer by assigning a value to each state in the State Space
43
43 Heuristic State Space Search Score for a state is a value calculated by comparing the state with the goal state Score for a state is a value calculated by comparing the state with the goal state Such as a number of correct items, or a distance from a goal state. Such as a number of correct items, or a distance from a goal state. So the new rules will be chosen based on this values. So the new rules will be chosen based on this values.
44
44 1 2 34 56 7 8 123 456 78 Goal state 123 45 678 N1 N2 STATE Score for a heuristic search Score = correct position = 1 points Score = correct position = 7 points
45
45 1 2 34 56 7 8 123 456 78 Goal state 123 45 678 N1 N2 STATE For a blind strategy, N1 and N2 are just two nodes (at some depth in the search tree) For a heuristic strategy counting the number of misplaced tiles, N2 is more promising than N1 Search Concepts Blind Search Heuristic Search Search Concepts Blind Search vs Heuristic Search
46
46 Heuristic State Space Search In doing so, it is more likely to get to a goal state faster than blind search. In doing so, it is more likely to get to a goal state faster than blind search.
47
47 Conclusions To solve any problems using computer 1. We define State of a Problem 2. Limit the State Space 3. Create Rules that move states 4. State Space Traversal or move among states until Goal is found. Problem is solved!
48
48 ITS033 Topic 01-Problems & Algorithmic Problem Solving Topic 01 - Problems & Algorithmic Problem Solving Topic 02 – Algorithm Representation & Efficiency Analysis Topic 03 - State Space of a problem Topic 04 - Brute Force Topic 05 - Divide and Conquer Topic 06-Decrease and Conquer Topic 06 - Decrease and Conquer Topic 07 - Dynamics Programming Topic 08-Transform and Conquer Topic 08 - Transform and Conquer Topic 09 - Graph Algorithms Topic 10 - Minimum Spanning Tree Topic 11 - Shortest Path Problem Topic 12 - Coping with the Limitations of Algorithms Power http://www.siit.tu.ac.th/bunyarit/its033.php and http://www.vcharkarn.com/vlesson/showlesson.php?lessonid=7
49
49 End of Chapter 3 Thank You! http://www.vcharkarn.com/vlesson/showlesson.php?lessonid=7&pageid=4
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.