Constraint Satisfaction Problems: Soup Chicken Dish Appetizer
Constraint Satisfaction Problems: Soup Chicken Dish Appetizer
Must be
Hot&Sour
Soup
No
Chicken
Appetizer Peanuts
Dish
Total Cost
< $30
Pork Dish No
Vegetable Peanuts
6
Varieties of constraints
• Unary constraints involve a single variable,
– e.g., SA ≠ green
–
• 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
– 8
– X2 + T + T = O + 10 · X3
Example: Latin Squares Puzzle
X1 X2 X3 X4 red RT RS RC RO
X5 X6 X7 X8 green GT GS GC GO
X9 X10 X11 X12 blue BT BS BC BO
X13 X14 X15 X16 yellow YT YS YC YO
Variables Values
Constraints: In each row, each column, each major diagonal, there must
be no two markers of the same color or same shape.
11
Standard Search Formulation
13
Backtracking Tree Search
• Variable assignments are commutative}, i.e.,
[ WA = red then NT = green ] same as [ NT = green then WA = red ]
14
Graph Matching Example
Find a subgraph isomorphism from R to S.
R 1 2
S e
(3,a) (3,b) (3,c) (3,d) (3,e) (3,a) (3,b) (3,c) (3,d) (3,e)
X X X X X X X X X
a c
(4,a) (4,b) (4,c) (4,d) (4,e)
X X X X
b d
How do we formalize this problem? 15
Backtracking Search
16
Backtracking Example
17
Backtracking Example
18
Backtracking Example
19
Backtracking Example
20
Improving Backtracking Efficiency
• General-purpose methods can give huge
gains in speed:
•
– Which variable should be assigned next?
–
– In what order should its values be tried?
–
– Can we detect inevitable failure early?
–
21
Most Constrained Variable
• Most constrained variable:
choose the variable with the fewest legal values
23
Least Constraining Value
• Given a variable, choose the least
constraining value:
•
– the one that rules out the fewest values in the
remaining variables
–
ui,v uj,v’
ui,v)
uj,v’ uj,v’
v1 v2 . . . vm
u1
u2 What does it mean if a
: whole row becomes 0?
un
28
Book’s Forward Checking Example
• Idea:
– Keep track of remaining legal values for unassigned variables
– Terminate search when any variable has no legal values
–
29
Forward Checking
• Idea:
– Keep track of remaining legal values for unassigned variables
– Terminate search when any variable has no legal values
–
30
Forward Checking
• Idea:
– Keep track of remaining legal values for unassigned variables
– Terminate search when any variable has no legal values
–
31
Forward Checking
• Idea:
– Keep track of remaining legal values for unassigned variables
– Terminate search when any variable has no legal values
–
32
Constraint Propagation
• Forward checking propagates information from assigned
to unassigned variables, but doesn't provide early
detection for all failures:
•
34
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 value y of Y
35
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 value y
of Y
40
k-consistency
(from Haralick and Shapiro, 1979,
The Consistent Labeling Problem: Part I)
Variables: U = {u1, u2, … , un}
Values: V = {v1, v2, … , vm}
Constraint Relation: R = {(u1,v1,u2,v2, … uk,vk) |
u1 having value v1, u2 having value v2,…
uk having value vk are mutually compatible}
hyperarc
41
k-consistency
42
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
–
44
• Given random initial state, can solve n-queens in almost
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
–