You are on page 1of 16

1

Constraint Satisfaction Problems

2
Constraint satisfaction problems (CSPs)
• CSP:
– state is defined by variables Xi with values from domain Di
– goal test is a set of constraints specifying allowable combinations
of values for subsets of variables

• Allows useful general-purpose algorithms with more


power than standard search algorithms

3
Example: Map-Coloring

• Variables WA, NT, Q, NSW, V, SA, T

• Domains Di = {red,green,blue}

• Constraints: adjacent regions must have different colors


• e.g., WA ≠ NT 4
Example: Map-Coloring

• Solutions are complete and consistent assignments, e.g.,


WA = red, NT = green,Q = red,NSW = green,V =
red,SA = blue,T = green
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:
• n variables, domain size d  O(d n) complete assignments
• e.g., 3-SAT - A collection of clauses C where each clause
contains exactly 3 literals, over a set of Boolean variables V.
(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

7
Varieties of CSPs
• Continuous variables
– e.g., start/end times for Hubble Space Telescope observations
– linear constraints solvable in polynomial time by linear
programming

8
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., SA ≠ WA ≠ NT

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

• Notice that many real-world problems involve real-


valued variables
10
Cryptaritmatic Problem
Statement
How to assign decimal digits to
letters, so that the following sum
is valid? Assume that we already
know that
• The possible digits set for the letters is
{0,1,2,…9}; SEND
• M must be 1; + MORE
• Two different letters can't be assigned the same
digit --------
MONEY
using c1,c2 and c3 to represent carries
changing problem to solve 4 equations

S E N D D+E = Y+10*C1
M O R E C1+N+R = E+10*C2
+ C3 C2 C1 C2+E+O = N+10*C3
---------------------- C3+S+M = O+10*M
M O N E Y
Queens puzzle
• Place eight queens on a chessboard so that no two attack
each other
Q

Q
Search formulation of the queens puzzle
• Successors: all valid ways of placing additional queen on the board;
goal: eight queens placed
Q

How big is this tree?


Q

How many leaves?


Q

Q Q Q Q Q

Q Q Q Q Q

Q Q Q Q Q

Q Q

Q Q Q Q Q

Q Q

Q Q Q Q Q
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


15

You might also like