CSC3402 Lecture5 Constraini Satisfaction Problem
CSC3402 Lecture5 Constraini Satisfaction Problem
AI
Lesson 5: Constraint
Satisfaction Problems
Outline
Constraint Satisfaction Problems (CSP)
Backtracking search for CSPs
Local search for CSPs
CSC3402 - Constraint
11/05/24 Satisfaction 2
Constraint satisfaction problems
(CSPs)
CSC3402 - Constraint
11/05/24 Satisfaction 3
Example: Map-Coloring
CSC3402 - Constraint
11/05/24 Satisfaction 4
Example: Map-Coloring
CSC3402 - Constraint
11/05/24 Satisfaction 6
Varieties of CSPs
Discrete variables
finite domains:
n variables, domain size d O(dn) complete assignments
e.g., Boolean CSPs, incl.~Boolean satisfiability (NP-complete)
infinite domains:
integers, strings, etc.
e.g., job scheduling, variables are start/end days for each job
need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3
Continuous variables
e.g., start/end times for Hubble Space Telescope
observations
linear constraints solvable in polynomial time by linear
programming
CSC3402 - Constraint
11/05/24 Satisfaction 7
Varieties of constraints
Unary constraints involve a single variable,
e.g., SA ≠ green
CSC3402 - Constraint
11/05/24 Satisfaction 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
CSC3402 - Constraint
11/05/24 Satisfaction 9
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
CSC3402 - Constraint
11/05/24 Satisfaction 10
Standard search formulation
(incremental)
CSC3402 - Constraint
11/05/24 Satisfaction 11
Backtracking search
Variable assignments are commutative}, i.e.,
[ WA = red then NT = green ] same as [ NT = green then WA =
red ]
Only need to consider assignments to a single variable at each
node
b = d and there are dn leaves
Depth-first search for CSPs with single-variable assignments is
called backtracking search
CSC3402 - Constraint
11/05/24 Satisfaction 12
Backtracking search
CSC3402 - Constraint
11/05/24 Satisfaction 13
Backtracking example
CSC3402 - Constraint
11/05/24 Satisfaction 14
Backtracking example
CSC3402 - Constraint
11/05/24 Satisfaction 15
Backtracking example
CSC3402 - Constraint
11/05/24 Satisfaction 16
Backtracking example
CSC3402 - Constraint
11/05/24 Satisfaction 17
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?
CSC3402 - Constraint
11/05/24 Satisfaction 18
Most constrained variable
Most constrained variable:
choose the variable with the fewest legal
values
CSC3402 - Constraint
11/05/24 Satisfaction 19
Most constraining variable
Tie-breaker among most constrained
variables
Most constraining variable:
choose the variable with the most
constraints on remaining variables
CSC3402 - Constraint
11/05/24 Satisfaction 20
Least constraining value
Given a variable, choose the least
constraining value:
the one that rules out the fewest values in the
remaining variables
CSC3402 - Constraint
11/05/24 Satisfaction 21
Forward checking
Idea:
Keep track of remaining legal values for unassigned
variables
Terminate search when any variable has no legal values
CSC3402 - Constraint
11/05/24 Satisfaction 22
Forward checking
Idea:
Keep track of remaining legal values for unassigned
variables
Terminate search when any variable has no legal values
CSC3402 - Constraint
11/05/24 Satisfaction 23
Forward checking
Idea:
Keep track of remaining legal values for unassigned
variables
Terminate search when any variable has no legal values
CSC3402 - Constraint
11/05/24 Satisfaction 24
Forward checking
Idea:
Keep track of remaining legal values for unassigned
variables
Terminate search when any variable has no legal values
CSC3402 - Constraint
11/05/24 Satisfaction 25
Constraint propagation
Forward checking propagates information from assigned
to unassigned variables, but doesn't provide early
detection for all failures:
CSC3402 - Constraint
11/05/24 Satisfaction 27
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
CSC3402 - Constraint
11/05/24 Satisfaction 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
To apply to CSPs:
allow states with unsatisfied constraints
operators reassign variable values
CSC3402 - Constraint
11/05/24 Satisfaction 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
Backtracking = depth-first search with one variable assigned
per node
Variable ordering and value selection heuristics help
significantly
Forward checking prevents assignments that guarantee later
failure
Constraint propagation (e.g., arc consistency) does additional
work to constrain values and detect inconsistencies
Iterative min-conflicts is usually effective in practice
CSC3402 - Constraint
11/05/24 Satisfaction 34