Professional Documents
Culture Documents
Constraint Satisfaction: CSE 473 University of Washington
Constraint Satisfaction: CSE 473 University of Washington
Constraint Satisfaction: CSE 473 University of Washington
CSE 473
University of Washington
Logistics
• PS
PS 1 due in a week
• Reading
Today + Monday: Ch 5 (esp 5.1 and 5.2)
4/14 (Wed) Ch 6 (esp 6.1 - 6.4)
4/16 (Fri) Ch 7
© Daniel S. Weld 2
473 Topics
Blind
Informed (Heuristics)
Constraint Satisfaction (Factored)
Adversarial
Search Knowledge
Representation
Problem Spaces
Agency
© Daniel S. Weld 3
Today:
Constraint Satisfaction Problems
• Definition
Factoring state spaces
• Backtracking policies
• Variable-ordering heuristics
• Preprocessing algorithms
© Daniel S. Weld 4
Constraint Satisfaction
• Kind of search in which
States are factored into sets of variables
Search = assigning values to these variables
Structure of space is encoded with constraints
• Backtracking-style algorithms work
E.g. DFS for SAT (i.e. DPLL)
• But other techniques add speed
Propagation
Variable ordering
Preprocessing
© Daniel S. Weld 5
Chinese Food as Search?
• States?
• Operators?
• Start state?
• Null meal
• Goal states?
© Daniel S. Weld 6
Factoring States
• Rather than state = meal
• Model state’s (independent) parts, e.g.
Suppose every meal for n people
Has n dishes plus soup
Soup =
Meal 1 =
Meal 2 =
…
Meal n =
© Daniel S. Weld 7
Chinese Constraint Network
Must be
Hot&Sour
Soup
Chicken No
Appetizer Peanuts
Dish
Total Cost
< $30
Pork Dish No
Vegetable Peanuts
© Daniel S. Weld 8
CSPs in the Real World
© Daniel S. Weld 9
Binary Constraint Network
• Set of n variables: x1 … xn
• Value domains for each variable: D1 … Dn
• Set of binary constraints (also “relations”)
Rij Di Dj
Specifies which values pair (xi xj) are consistent
© Daniel S. Weld 10
Binary Constraint Network
Partial assignment of values = tuple of pairs
{...(x, a)…} means variable x gets value a...
Tuple=consistent if all constraints satisfied
Tuple=full solution if consistent + has all vars
© Daniel S. Weld 11
Cryptarithmetic
• State Space SEND
Set of states
+ MORE
Operators [and costs]
Start state ------
Goal states MONEY
• Variables?
• Domains (variable values)?
• Constraints?
© Daniel S. Weld 12
Classroom Scheduling
• Variables?
• Constraints?
© Daniel S. Weld 13
N Queens
• As a CSP?
© Daniel S. Weld 14
N Queens
• Variables = board columns
• Domain values = rows
• Rij = {(ai, aj) : (ai aj) (|i-j| |ai-aj|)
e.g. R12 = {(1,3), (1,4), (2,4), (3,1), (4,1), (4,2)}
Q
Q
© Daniel S. Weld 16
Chronological Backtracking (BT)
(e.g., depth first search)
1
Q
Q
2 6
Q
Q
Q Q
Q
Q
Q
Q
BJ Discovers Q
(2, 5, 3, 6) inconsistent with x6
No sense trying other values of x5
© Daniel S. Weld 18
Conflict-Directed Backjumping (CBJ)
• More sophisticated backjumping behavior
• Each variable has conflict set CS
Set of vars that failed c-checks w/ current val
Update this set on every failed c-check
• When no more values to try for xi
Backtrack to deepest var, xd, in CS(xi)
And update CS(xd):=CS(xd)CS(xi)-{xd}
1 Q 3 2
CBJ Discovers CS(x5) CS(x6) 2 Q 1 1
(2, 5, 3) 1,2,3 1,2,3,5 3 Q 3 3
Q 5
inconsistent 4
5 Q 2
with {x5, x6 } 6 3
x1 x2 x3 x4 x5 x6
© Daniel S. Weld 19
BT vs. BJ vs. CBJ
© Daniel S. Weld 20
Forward Checking (FC)
• Perform Consistency Check Forward
• Whenever a var is assigned a value
Prune inconsistent values from
As-yet unvisited variables
Backtrack if domain of any var ever collapses
© Daniel S. Weld 21