CS 371: Introduction to Artificial Intelligence
Constraint Satisfaction

Outline
Definition of a Constraint Satisfaction Problem
Constraint satisfaction as tree search
Looking ahead: constraint propagation
Looking back: intelligent backtracking
Constraint Optimization Problems
Constraint optimization as a stochastic local search

Introductory Problems
Map Coloring
(see New England + New York map)
Object: to color the map with three colors
N-Queens Problem

Constraint Satisfaction Problem
Variables (X1, X2, …, Xn)
Variable domains (D1, D2, …, Dn)
Variable constraints, pairs of:
Constraint variable subsets, and
Relations over such subsets

Constraint Satisfaction as Tree Search
Initial state:
No variables assigned
Operators:
Assign a single variable a member of its domain
Goal Test:
All variables assigned
Path Cost:
Irrelevant à 0

Issues with Backtracking (DFS) Approaches to CSPs
Large number of variables
Large variable domains
Computational cost of evaluating constraints
Must search entire tree to prove that constraints cannot be satisfied

Reducing Search
Variable/value ordering:
Prefer more constrained variables:
Instantiate (assign) the variable with the fewest possible remaining alternatives
Prefer more constraining variables:
Instantiate the variable which is in the most constraint subsets.
Identify and instantiate a stable set of variables (no direct constraints between pairs) last

Reducing Search (continued)
Looking forward:
Consistency preprocessing:
Constraint propagation: As variables are instantiated, compute some level of impact on future variable assignments
Looking backward: intelligent backtracking
Rather than doing simple DFS backtracking, backtrack to the cause of the constraint violation.

Consistency enforcement
In the simplest case, we try to instantiate a variable with each value in its domain.
What of unary constraints?
e.g. “Vermont must be colored green.”, “Massachusetts must be blue or green.”
Much search can be wasted if such simple constraints are ignored.

Node Consistency
Node consistent – each domain obeys unary constraints
(e.g. Vermont’s domain is reduced to the singleton set “green”.)
Easy to do, avoids wasted work
Usually done at problem formulation level
Suppose New York is colored green.  How to propagate this to the constraints of adjacent states?

Arc Consistency
Arc consistent
Node consistent, and
" variables Xi, Xj
" instantiations of Xi,
$ an instantiation of Xj obeying binary constraints between Xi, Xj
Example: If NY green, domains have only values respecting unary constraints, and lacking green for adjacent states.

K-Consistency
The concept of consistency can be generalized.
K-Consistent
" variables X1, X2, …, XK
" instantiations of X1, X2, …X(K-1),
$ an instantiation of XK obeying constraints between XK and {X1, …, X(K-1)}
Strongly K-Consistent
J-Consistent for all J£K

K-Consistency (cont.)
Node Consistent = (Strongly) 1-Consistent
O(de) – d variable domain size, e binary constraints (arcs in constraint graph)
Arc Consistent = Strongly 2-Consistent
O(de2)
Path Consistent = Strongly 3-Consistent
There exists a K for each binary CSP such that enforcing strong K-consistency eliminates backtracking (no search).
Consistency enforcement expensive for non-small K à tradeoff

Constraint Propagation
Different levels of consistency can be enforced during backtracking search.
Common usage (backtracking with arc consistency):
Variable Xi instantiated
For each Xj such that there’s a binary constraint on (Xi, Xj), update Dj
With each domain update, propagate binary constraints onward until no change

Intelligent Backtracking
Example: Maine must be colored green. We start by coloring New Hampshire green, and finish with Maine as the last variable for instantiation. à thrashing
During search, one can keep track of the way in which variable instantiations constrain other variable instantiations.
Then one can backtrack to the cause of instantiation failure.

Combining Approaches
One can combine:
Variable/value ordering heuristics,
Constraint propagation, and
Intelligent backtracking
to greatly increase efficiency of search.
However, tree search is not the only kind of search that can be applied…

Constraint Satisfaction as Iterative Improvement Search
Constraint satisfaction can also be approached using iterative improvement search… (been there, done that already!)
(Constraint Optimization treated in homework project.  More slides will be developed on COPs in the future.)