Professional Documents
Culture Documents
Constraint Satisfaction Problems: Foundations of Artificial Intelligence
Constraint Satisfaction Problems: Foundations of Artificial Intelligence
Shang-Tse Chen
Department of Computer Science
& Information Engineering
National Taiwan University
N variables
domain D
constraints
x2
x1
o Domains:
Explicit:
o Formulation 2:
o Variables:
o Domains:
o Constraints:
Implicit:
Explicit:
Example: Cryptarithmetic
X1
o Variables:
o Domains:
o Constraints:
Example: Sudoku
§ Variables:
§ Each (open) square
§ Domains:
§ {1,2,…,9}
§ Constraints:
?
§ Approach:
§ Each intersection is a variable
§ Adjacent intersections impose constraints
on each other
§ Solutions are physically realizable 3D
interpretations
Varieties of CSPs
o Discrete Variables
o Finite domains
o Size d means O(dn) complete assignments
o E.g., Boolean CSPs, including Boolean satisfiability (NP-
complete)
o Infinite domains (integers, strings, etc.)
o E.g., job scheduling, variables are start/end times for each job
o Linear constraints solvable, nonlinear undecidable
o Continuous variables
o E.g., start/end times for Hubble Telescope observations
o Linear constraints solvable in polynomial time by LP methods
Varieties of Constraints
o Varieties of Constraints
o Unary constraints involve a single variable (equivalent
to reducing domains), e.g.:
{}
{WA=g} {WA=r} … {NT=g} …
o Ordering:
o Which variable should be assigned next?
o In what order should its values be tried?
Keep track of domains for unassigned variables and cross off bad options
Filtering: Forward Checking
o Filtering: Keep track of domains for unassigned variables and cross off bad
options
o Forward checking: Cross off values that violate a constraint when added to the
existing assignment
NT Q
WA
SA NSW
V
NT Q
WA
SA
NSW
V
NT Q
WA
SA
NSW
V
NT Q
WA SA
NSW
V
o Lots of middle ground between arc consistency and n-consistency! (e.g. k=3,
called path consistency)
Video of Demo Coloring – Backtracking with Arc
Consistency – Complex Graph
K-Consistency
o Increasing degrees of consistency
o 1-Consistency (Node Consistency): Each single node’s domain
has a value which meets that node’s unary constraints
o Lots of middle ground between arc consistency and n-consistency! (e.g. k=3,
called path consistency)
Ordering
Ordering: Minimum Remaining Values
o Variable Ordering: Minimum remaining values (MRV):
o Choose the variable with the fewest legal left values in its domain
o Theorem: if the constraint graph has no loops, the CSP can be solved in O(n d2)
time
o Compare to general CSPs, where worst-case time is O(dn)
o Why doesn’t this algorithm work with cycles in the constraint graph?
o Note: we’ll see this basic idea again with Bayes’ nets
Improving Structure
Nearly Tree-Structured CSPs
Choose a cutset
SA
M1 M2 M3 M4
¹ ¹ ¹ ¹
Agree on
Agree on
Agree on
NS NS
WA NT NT Q Q W W
V
¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹
shared vars
shared vars
shared vars
SA SA SA SA
o To apply to CSPs:
o Take an assignment with unsatisfied constraints
o Operators reassign variable values
o No fringe! Live on the edge.
o Speed-ups:
o Ordering
o Filtering
o Structure – turns out trees are easy!