Presentation is loading. Please wait.

Presentation is loading. Please wait.

Constraint Satisfaction Problems vs. Finite State Problems

Similar presentations


Presentation on theme: "Constraint Satisfaction Problems vs. Finite State Problems"— Presentation transcript:

1 Constraint Satisfaction Problems vs. Finite State Problems

2 Finite State Problems (FSP)
FSP can be solved by searching in a space of simple states. Finite states are evaluated by domain-specific heuristics (rules) and tested to see whether they were goal states. Finite States have no discernible internal structure. Objective: Examine rules that govern behavior and perform a goal test. The Virtual Pet problem is a Finite State Problem.

3 Constraint Satisfaction Problems (CSP)
complex situations that cannot utilize this finite state application very efficiently. Problem requires a complex internal structure. Constraint Satisfaction Problems contain states and goals that conform to a complex data structured representation. The Maze problem is a Constraint Satisfaction Problem, which refers to a specific area of AI.

4 Virtual Pet Problem: Simple Data Structure
Virtual Pet is a Finite State Problem. Finite states can be represented by primitive values. isEATING = 1 , isHUNGRY = 2, and, isPLAYING = 3. Simplified states could be easily identified them during the game loop using a switch statement.

5 Maze App: Complex Data Structure - Carving out the pathways -
The Maze Game is a Constraint Satisfaction Problem because it contains states and goals that conform to a complex data structured representation. A maze requires a unique search algorithm to carve out a path. Search algorithms for Constraint Satisfaction Problems require the application of conflict heuristics. NOTE: The topic of Constraint Satisfaction appears regularly in Artificial Intelligence research papers and in the specialist journal, Constraints.

6 Definition of Constraint Satisfaction Problem
Formally speaking, a constraint satisfaction problem (or CSP) is a search problem defined by: a set of variables. a set of constraints that restrict the values assigned to the variables. Each variable has a nonempty domain of possible values. Each constraint involves some subset of the variables and specifies the allowable combinations of values for that subset.

7 Example Constraint Satisfaction Problem
We are tired of living in California and we’re thinking of moving to Australia. Explore a map of Australia showing each territory. RULES: Identify locations by coloring each region a different color. Use either red, green, or blue. Color in such a way that no neighboring regions have the same color.

8 No neighboring regions have the same color
No neighboring regions have the same color. NOTE: Tasmania is not included.

9 Develop Heuristics (Generic Rules) for CSP
Visualize the problem, such as structuring the constraints in the form of graph. Define the variables : WA, N , Q, NSW, V , and SA. The domain of each variable is the set: {red, green, blue}. The nodes of the graph correspond to variables of the problem and the arcs correspond to constraints. Next step: develop generic rules for the structure of the constraints

10 Why Constraint Rules? – An Overview
Once we have chosen {SA = blue}, we can conclude that none of the five neighboring variables can take on the value blue. Without taking advantage of a constraint heuristic, a search would consider 35 = 243 assignments for the five neighboring variables. With a constraint heuristic we never have to consider blue as a value, so we have only 25 assignments to search.

11 The Map Constraints Since there are nine places where regions border, there are nine constraints. SA != WA SA != NT SA != Q SA != NSW SA != V WA != NT NT != Q Q != NSW; NSW != V

12 Searching a CSP - Backtracking
Backtracking is a list processing search mechanism. Backtracking is commonly used for solving CSPs. The term backtracking is used for a depth-first search that chooses values for one variable at a time and backtracks when a variable has no legal values left to assign. Legal values are governed by constraints.

13 Backtracking Algorithms
Stacks Depth-First Searches

14 Review of Stacks A Stack is a list with very strict rules placed on its behavior. Elements may be added or removed only from the back of the list. The back of the list is usually referred to as the top of the stack. When an element is added to a stack, it must be pushed onto the back of the list. When an element is removed, it must be popped off the back of the list. Elements are added and removed strictly from the back of the list (the top). The item that is added last will be removed first. A stack is also called a last in, first out (LIFO) data structure. The second book in a stack can be removed only once the book on top of it has been removed.

15 Stacks and AS3 A stack can be implemented using an AS3 array structure. Stacks begin with zero elements, initialized to an empty state. The top of the stack is the last element in the array. Two array operations are used for accessing elements on a stack: push() Adds an item to the back of the list. pop() Removes an item from the back of the list.

16 AS3 Code Example for Stacks
var stack:Array = new Array(); stack.push(3); stack.push(4); stack.push(5); stack.push(6); stack.push(7); trace(“Top of the stack is “, stack.length – 1);

17 AS3 Code Example for Stacks
var stack:Array = new Array(); stack.push(3); stack.push(4); stack.push(5); stack.push(6); stack.push(7); stack.pop(); stack.pop(); trace(“Top of the stack is “, stack.length – 1);

18 Carving out a Perfect Maze using Backtracking
Carving a maze is a CSP. A “perfect” maze is one in which there is exactly one path between any two given cells. In computer science terms, this is called a minimal spanning tree over a set of cells.

19 Algorithm Objectives: Building a Maze
The maze will contain nine cells arranged in three rows and three columns. The maze contains no circular paths: Every cell is connected to every other cell by exactly one path. Build the maze cell by cell while making sure that no loops exist and that no cell ends up isolated. The backtracker operates as follows Begin with an array of maze cells with all the walls intact. Choose a starting cell. Repeatedly select a random adjacent cell in the maze—one that has been unvisited—and open the wall between the two. Continue to do this until every cell has been “visited” and a wall has been eliminated during the visit.

20 Step 1: Create a two-dimensional array representing the maze cells.
All cell walls are initially intact. Construct an empty stack for backtracking. This will ensure that no loops exist in the path and that no cell ends up isolated.

21 Step 2: The starting cell is selected. For convenience in this example, the starting cell will be cell number 0. This first cell is marked as visited, and pushed onto the stack. The stack now holds the first cell visited.

22 Step 3: Choose a random adjacent cell that has not yet been visited.
In this case, the constraints tell us the possible cells are 1 and 3. Assume that cell 1 has been randomly selected. The east wall of cell 0 is eliminated. Cell 1 is marked as visited. Cell 1 is pushed onto the stack.

23 Step 4: The possible adjacent cells to cell 1 are 2 and 4. Assume that cell 4 has been randomly selected. The south wall of cell 1 is eliminated. The north wall of 4 is eliminated. Cell 4 is marked as visited and pushed onto the stack.

24 Step 5: The possible adjacent cells to cell 1 are 3, 7, and 5. Assume that cell 7 has been randomly selected. The south wall of cell 4 is eliminated. The north wall of 7 is eliminated. Cell 7 is marked as visited and pushed onto the stack.

25 Step 6: The possible adjacent cells to cell 1 are 6 and 8. Assume that cell 6 has been randomly selected. The west wall of cell 7 is eliminated. The east wall of 6 is eliminated. Cell 6 is marked as visited and pushed onto the stack.

26 Step 7: Cell 3 is the only possible adjacent cell to visit from cell 6. The south wall of 3 is eliminated. The north wall of cell 6 is eliminated. Cell 3 is marked as visited and pushed onto the stack.

27 Step 8: There are no valid cells to cell 3 that can be visited
Step 8: There are no valid cells to cell 3 that can be visited. Backtrack to find a new cell that has not been visited.

28 Step 9: After backtracking to cell 7, Cell 8 is the only possible adjacent cell to visit. The east wall of cell 7 is eliminated. The west wall of 8 is eliminated. Cell 8 is marked as visited and pushed onto the stack.

29 Step 10: Cell 5 is the only possible adjacent cell to visit from cell 8. The south wall of 5 is eliminated. The north wall of cell 8 is eliminated. As shown, cell 5 is marked as visited and pushed onto the stack.

30 Step 11: Final Step Cell 2 is the only remaining cell to be visited in the algorithm. It is also the only possible adjacent cell to visit from cell 5. The north wall of cell 5 is eliminated. The south wall of Cell 2 eliminated. Cell 2 is marked as visited. All cells have been visited. There is exactly one path between any two cells.


Download ppt "Constraint Satisfaction Problems vs. Finite State Problems"

Similar presentations


Ads by Google