Table of Contents
Constraint Satisfaction Problems
Ref [Russell2003Constraints].
The CSP is a tree with binary constraints.
Backtracking search
- function Backtracking-Search(csp) returns a solution or failure
- return Recursive-Backtracking({}, csp)
- function Recursive-Backtracking(assignment, csp) returns a solution or failure
- if assignment is complete then return assignment
- var ← Select-Unassigned-Variables(Variables(csp),assignment,csp)
- for each value in Order-Domain-Values(var,assignment,csp) do
- if value is consistent with assignement according to Constraints(csp) then
- add {var = value} to assignement
- result ← Recursive-Backtracking(assignment, csp)
- if result != failure then return result
- remove {var = value} from assignment
- return failure
Select-Unassigned-Variables
- Minimum Remaining Values (selecting the variable with the most reduced legal values set) ;
- Degree heuristic (selecting the variable involved in the largest number of constraints).
Order-Domain-Values
- Least constraining value (choose the value that rules out the fewest choices in the neighboring variables of the constraint graph).
Constraint propagation
Forward checking
When assigning a value to X, remove the colliding values from the domain of each variable Y connected by a constraint. AC-3_algorithm
Redundant with backjumping.
Arc consistency
A (directed) arc from one variable X to a connected one Y is consistent if, for every value in the domain of X, the domain of Y is not empty. Costlier than forward checking.
- function AC-3(csp) returns the CSP, possibly with reduced domains
- queue ← all the arcs in csp
- while queue is not empty
- (Xi, Xj) ← Remove-First(queue)
- if Remove-Inconsistent-Values(Xi, Xj) then
- for each Xk in Neighbors(Xi) do
- add (Xk, Xi) to queue
- function Remove-Inconsistent-Values(Xi, Xj)) returns true iff a value has been removed
- removed ← false
- for each x in Domain(Xi) do
- if no value y in Domain(Xi) allows (x,y) to satisfy the constraint between Xi and Xj then
- delete x from Domain(Xi)
- removed ← true
- return removed
Local search
Minimum conflicts
- function Min-Conflicts(csp,max_steps) returns a solution or failure
- current ← initial complete assignment for csp
- for i = 1 to max_steps do
- if current is a solution for csp then return current
- var ← random conflicted variable from Variables(csp)
- value ← the value for var that minimizes Conflicts(var,v,current,csp)
- set {var = value} in current
return failure