CMPS715CSP
CMPS715CSP
Problems
Chapter 5
Section 1 – 3
1
Outline
Constraint Satisfaction Problems (CSP)
Backtracking search for CSPs
Local search for CSPs
2
Constraint satisfaction problems (CSPs)
3
Example: Map-Coloring
4
Example: Map-Coloring
5
Constraint graph
Binary CSP: each constraint relates two variables
Constraint graph: nodes are variables, arcs are constraints
6
Varieties of CSPs
Discrete variables
finite domains:
7
Varieties of constraints
Unary constraints involve a single variable,
e.g., SA ≠ green
Binary constraints involve pairs of variables,
e.g., SA ≠ WA
Higher-order constraints involve 3 or more
variables,
e.g., cryptarithmetic column constraints
8
Example: Cryptarithmetic
Variables: F T U W
R O X1 X2 X3
Domains: {0,1,2,3,4,5,6,7,8,9}
Constraints: Alldiff (F,T,U,W,R,O)
O + O = R + 10 · X1
X1 + W + W = U + 10 · X2
X2 + T + T = O + 10 · X3
X3 = F, T ≠ 0, F ≠ 0
9
Example: Sudoku
Variables:
Each (open) square
Domains:
{1,2,…,9}
Constraints:
9-way all diff for each column
9-way all diff for each row
9-way alldiff for each region
(or can have a bunch of
pairwise inequality
constraints)
Real-world CSPs
Assignment problems
e.g., who teaches what class
Timetabling problems
e.g., which class is offered when and where?
Transportation scheduling
Factory scheduling
Notice that many real-world problems involve real-
valued variables
11
Standard search formulation (incremental)
13
Backtracking search
14
Backtracking example
15
Backtracking example
16
Backtracking example
17
Backtracking example
18
Improving backtracking efficiency
19
Most constrained variable
Most constrained variable:
choose the variable with the fewest legal values
20
Most constraining variable
Tie-breaker among most constrained
variables
Most constraining variable:
choose the variable with the most constraints on
remaining variables
21
Least constraining value
Given a variable, choose the least
constraining value:
the one that rules out the fewest values in the
remaining variables
22
Forward checking
Idea:
Keep track of remaining legal values for unassigned
variables
Terminate search when any variable has no legal values
23
Forward checking
Idea:
Keep track of remaining legal values for unassigned
variables
Terminate search when any variable has no legal values
24
Forward checking
Idea:
Keep track of remaining legal values for unassigned
variables
Terminate search when any variable has no legal values
25
Forward checking
Idea:
Keep track of remaining legal values for unassigned
variables
Terminate search when any variable has no legal values
26
Constraint propagation
Forward checking propagates information from assigned to
unassigned variables, but doesn't provide early detection for
all failures:
28
Arc consistency
Simplest form of propagation makes each arc consistent
X Y is consistent iff
for every value x of X there is some allowed y
29
Arc consistency
Simplest form of propagation makes each arc consistent
X Y is consistent iff
for every value x of X there is some allowed y
30
Arc consistency
Simplest form of propagation makes each arc consistent
X Y is consistent iff
for every value x of X there is some allowed y
32
Local search for CSPs
Hill-climbing, simulated annealing typically work with
"complete" states, i.e., all variables assigned
To apply to CSPs:
allow states with unsatisfied constraints
operators reassign variable values
33
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
34