Hande ÇAKIN20133206003
IES 503
TERM PROJECT
CONSTRAINT SATISFACTION PROBLEMS
1
OUTLINE
• Constraint Satisfaction Problems (CSP)• Benefits of CSPs• Varieties of CSPs
• Backtracking Search for CSPs• Improving backtracking efficiency• Minimum remaining values (MRV) heuristic• Forward Checking• Constraint propagation
• Local Search for CSPs• Min-conflicts Heuristic
• The Structure of Problems• Independent Subproblems• Cycle Cutset• Tree Decomposition
• Summary
1
Constraint Satisfaction Problems (CSP)
Constraint satisfaction problems (CSPs) are mathematical problems defined as a set of objects whose state must satisfy a number of constraints or limitationsSimple ExamplesEight queens puzzleMap coloring problemSudokuReal World ExamplesAssignment ProblemsTimetabling ProblemsTransportation ProblemsFactory Scheduling
1
Constraint Satisfaction Problems (CSP)
STANDARD SEARCH PROBLEM
State is defined as a ‘black box’ and represented with the successor function, heuristic function and goal test.
CONSTRAINT SATISFACTION PROBLEMS
State is defined by variables Xi with values from domain Di and goal test is a set of constraints specifying allowable combinations of values for subsets of variables
2
Constraint Satisfaction Problems (CSP)
Benefits of CSPsThe CSPs yield a natural representation for a wide variety of problem
It is possible to develop effective, generic heuristic w/o additional domain-spesific expertise
CSP solver is faster than state space search by eliminating large swatches of the search space
The structure of the constraint graph can be used to simplify the solution process
3
Constraint Satisfaction Problems (CSP)
Example : Map Coloring • Initial state: the empty
assignment {), in which all variables are unassigned.
• Successor function: a value can be assigned to any unassigned variable, provided that it does not conflict with previously assigned variables.
• Goal test: the current assignment is complete.
• Path cost: a constant cost (e.g., 1) for every step.
Same color is not allowable for neighbours!
R
GB
4
Constraint Satisfaction Problems (CSP)
Example : Map Coloring Variables: WA, NT, Q, NSW, V, SA, TDomains: Di= {Red, Green, Blue }Constraints: Neighbour regions should have different colorse.g., WA ≠ NT or (WA,NT) in {(red,green), (red,blue), (green,red), (green,blue), (blue,red), (blue, green)}Solutions: Complete and consistent assignmentse.g. WA=red, NT= green, Q=red, NSW= green, V=red, SA= blue, T=green
Same color is not allowable for neighbours!
R
GB
5
Constraint Satisfaction Problems (CSP)
Example : Map Coloring
R
GB
Constraint Graph
Nodes are variables Arcs are constraints
‘Each constraint relates two variables’
6
Constraint Satisfaction Problems (CSP)
Varieties of CSPs
Types of Variables
Discrete Variables
Finite Domains
e.g. Boolean CSPs
Infinite Domains
e.g. Job Scheduling
Continuous Variables
e.g. Hubble Space Telescope
observations
7
Constraint Satisfaction Problems (CSP)
Varieties of CSPs
Types of Constraints
Unary Constraints
e.g. SA≠ green
Binary Constraints
e.g. SA ≠ WA
Higher Order Constraints
e.g. Cryptarithmetic
column constraints
8
Backtracking Search for CPSs
• Depth-first search for CSPs with single-variable assignments is called backtracking search
• Backtracking search is the basic uninformed algorithm for CSPs
• Can solve n-queens for n ≈ 25
8
Backtracking Search for CPSs
8
Backtracking Search for CPSs
8
Backtracking Search for CPSs
Improving backtracking efficiency
1. Which variable should be assigned next, and in what order should its values be tried?
2. What are the implications of the current variable assignments for the other unassignedvariables?
3. When a path fails-that is, a state is reached in which a variable has no legal values- canthe search avoid repeating this failure in subsequent paths?
8
Backtracking Search for CPSs
Variable and Value Ordering
Minimum remaining values (MRV) heuristic: choosing the variable with the fewest "legal" values.
It also has been called the "most constrained variable" or"fail-first" heuristic
8
Backtracking Search for CPSs
Variable and Value Ordering
Minimum remaining values (MRV)Most constraining variable
Choose the variable with the most constraints on remaining variables
8
Backtracking Search for CPSs
Variable and Value Ordering
Minimum remaining values (MRV)Least constraining value
Given a variable, choose the least constraining value: the one that rules out the fewest values in the remaining variables
DEGREE
HEURITIC
8
Backtracking Search for CPSs
Propagating Information through Constraints
Forward Checking
Keep track of remaining legal values for unassigned variablesTerminate search when any variable has no legal values
8
Backtracking Search for CPSs
Propagating Information through Constraints
Constraint propagation
It is the general term for propagating the implications of a constraint on one variable onto other variables.
In other words, using the constraints to reduce number of legal values for a variable.
• Arc consistency• Node consistency• Path consistency
Backtracking Search for CPSs
Constraint propagation
Arc consistency
Provides a fast method of constraint propagation that is substantially stronger than forward checking
X Y is consistent if for every value x of X there is some allowed y
Backtracking Search for CPSs
Constraint propagation
Arc consistency
8
- If X loses a value, neighbors of X need to be rechecked- Arc consistency detects failure earlier than forward checking-Can be run as a preprocessor or after each assignment
Backtracking Search for CPSs
Constraint propagation
Arc consistency
8
Time complexity =
O(n2d3)
Backtracking Search for CPSs
Constraint propagationA CSP is k-consistent if, for any set of k - 1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any kth variable.
• Node consistency• Each individual variable by itself is
consistent1- consistency
• Arc consistency2- consistency
• Path consistency• Any pair of adjacent variables can always
be extended to a third neighboring variable
3- consistency
Backtracking Search for CPSs
Intelligent Backtracking- looking backward
The BACKTRACKING-SEARCH algorithm; back up to the preceding variable and try a different value when it comes up with a failure
R
BG
R
?
Every value violates the constraint, so back up to the Tasmania!
BACKJUMPING METHOD
Local Search for CSPs
Local search algorithms move from solution to solution in the space of candidate solutions (the search space) by applying local changes, until a solution deemed optimal is found or a time bound is elapsed
e.g. Hill-climbing, simulated annealing..
Complete state formulation
1. Assign a value for every variable2. Randomly select any conflicted variable3. The successor function works by changing the value of that
variable at a time.
Local Search for CSPs
Min-conflicts Heuristic
Select the value that results in the minimum number of conflicts with other variablesStates: 4 queens in 4 columns (44 = 256 states)Actions: move queen in columnGoal test: no attacksEvaluation: h(n) = number of attacks
The Structure of Problems
Tasmania is not connected to the mainland. Intuitively, it is obvious that coloring Tasmania and coloring the mainland are independent subproblems
Independent Subproblems
The Structure of Problems
Cycle Cutset
1. Choose a subset S from VARIABLES such that the constraint graph becomes a treeafter removal of S. S is called a cycle cutset.2. For each possible assignment to the variables in S that satisfies all constraints on S,(a) remove from the domains of the remaining variables any values that are inconsistentwith the assignment for S, and(b) If the remaining CSP has a solution, return it together with the assignment for S.
Cycle cutset has size c,total runtime =O(dC . (n - c)d".
The Structure of Problems
Tree Decomposition
• Solve each subproblem independently; • If any one has no solution, the entire problem has no
solution. • If it is possible to solve all the subproblems, then
attempt to construct a global solution
Tree width has size wTotal run time
=O(n)
Summary• CSPs are a special kind of problem:• states defined by values of a fixed set of variables• goal test defined by constraints on variable values
• Backtracking = depth-first search with one variable assigned per node
• Variable ordering and value selection heuristics help significantly
• Forward checking prevents assignments that guarantee later failure
• Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies
• Iterative min-conflicts is usually effective in practice
Top Related