Constrained Satisfaction Problem (CSP)
Constrained Satisfaction Problem (CSP)
we can explicitly describe each of these constraints as a relation between the two
variables where the pairs show the allowed values that the variables can be
simultaneously assigned, i.e.
X1≠X2 = {(1,2),(1,3),(1,4),(2,3),(2,4),(3,2),(3,4),(4,2),(4,3)}
X1≠X3 = {(1,3),(1,7),(2,3),(2,7),(3,7),(4,3),(4,7)}
X2≠X3 ={(2,3),(2,7),(3,7),(4,3),(4,7)}
Constrained Satisfaction Problem (CSP)
Example 2: Suppose we have a CSP as follows:
• Three variables X1 , X2 and X3
• Domains: D1 = {1,2,3,4}, D2 = {2,3,4} , and D3 = {3,7}
X1 can only be assigned one of the values 1,2,3 or 4
• Constrained : X1 + X2= X3, and X1 is even.
Here
X1 + X2= X3 is a ternary constrained
X1 + X2= X3 = { (1,2,3), (3,4,7) , (4,3,7)}
X1 is even
X1 = {2,4}
The only one case where X1 is even and satisfies both condition is (4,3,7). So the solution
to the problem is X1 = 4 , X2 = 3 and X3 = 7
Constrained Satisfaction Problem (CSP)
• Variables can be assigned, or unassigned
• If a CSP has some variables assigned, and those assignments don’t violate any
constraints,
we say the CSP is consistent, or that it is satisfied
• If all the variables of a CSP are assigned a value, we call that a complete
assignment bb
• A solution to a CSP complete assignment that is consistent, i.e. a complete
assignment that does not violate any constraints
• Depending on the constraints, a CSP may have 0, 1, or many solutions
- A CSP with no solutions is sometimes referred to as over-constrained
- A CSP with many solutions is sometimes referred to as under-constrained
• If a domain is empty, then the CSP is no solution
CSP Examples: Map Coloring
The map coloring problem requires that we color regions of the map
such that neighboring regions never have the same color.
Variables : WA, NT, SA, NSW, Q, V, T
Domains : { RED, GREEN , BLUE }
Constraints: adjacent regions must
have different colors
Solutions are assignments satisfying
all constraints, e.g.
{ WA= RED, NT= GREEN, SA=BLUE,
Q=RED, NSW=GREEN, V=RED, T=GREEN }
CSP Examples: Map Coloring
• It can be helpful to visualize a CSP as a constraint graph, as shown in Figure
(b). The nodes of the graph correspond to variables of the problem, and an
edge connects any two variables that participate in a constraint.
• Constraint={ WA ≠ NT, WA ≠ SA, SA ≠ NT, SA ≠ Q, SA ≠ NSW, SA ≠ V, NT
≠ Q, Q ≠ NSW, NSW ≠ V }
CSP Examples: Map Coloring
How many colours in the domains required so that no two neighbours have same
color
Variables: Qk
Domains: {1,2,3,…N}
Constrained: For all i,j non-threatening ( Qi , Qj )
( Qi , Qj ) ϵ { ( 1 , 3 ), (1, 4)….}
CSP Examples: Cryptarithmetic puzzles
Each letter in a cryptarithmetic puzzle represents a different digit. For the case in Figure 6.2(a), this would
be represented as the global constraint Alldiff (F, T, U, W, R, O )
Variable: F T U W R O C1 C2 C3
Domains: { 0, 1 , 2, 3, 4, 5, 6, 7, 8, 9}
Constraints: all variable values should
be different.
O + O = R + 10 * C1
C1 + W + W = U + 10 * C2
C2 + T + T = O + 10 * C3
C3 = F
where C1, C2, and C3 are auxiliary variables representing the digit carried over into the tens,
hundreds, or thousands column.
CSP Examples: Cryptarithmetic puzzles
The constraint hypergraph for the cryptarithmetic problem, showing the Alldiff
constraint (square box at the top) as well as the column addition constraints (four square
boxes in the middle). The variables C1,C2, and C3 represent the carry digits for the three
columns from right to left
O + O = R + 10 * C1
C1 + W + W = U + 10 * C2
C2 + T + T = O + 10 * C3
C3 = F
Setting F = 1, O = 4, R = 8, T = 7, W = 3,
U = 6 gives 734 + 734 = 1468
CSP Examples: Cryptarithmetic puzzles
Constraints:
•A number 0-9 is assigned to a particular alphabet.
•Each different alphabet has a unique number.
•All the same, alphabets have the same numbers.
•The numbers should satisfy all the operations that any normal number does
CSP Examples: Cryptarithmetic puzzles
CSP Examples: Try to solve
Real-world CSPs:
•Assignment problems
e.g., who teaches what class
•Timetabling problems
e.g., which class is offered when and where?
•Hardware configuration
•Transportation scheduling
•Factory scheduling
•Floor planning
Generate and Test
•Generate and Test is the simplest of the algorithms to
identify a solution for a CSP.
•In this algorithm, each of the possible solutions is
attempted (each value enumerated for each variable)
and then tested for the solution.
•Since testing each combination of variable within the
domain of each value can be extremely slow and
inefficient, heuristics can be applied to avoid those
combinations that are outside of the solution space
CSP as a standard search problem
• A CSP can easily be expressed as a standard search problem
• Incremental formulation
Initial State: the empty assignment {}
Successor function: Assign a value to any unassigned variable
provided that it does not violate a constraint
Goal test: the current assignment is complete and consistent
Path cost: constant cost for every step (not generally relevant)
Commutativity
Heuristics
• Most constrained variable
?
• Least constraining value
?
Heuristics for CSPs
Examples: map coloring
Heuristics
• Most constrained variable
Country E is the most constrained
one (cannot use Red, Green)
• Least constraining value
?
Heuristics for CSPs
Examples: map coloring
Heuristics
• Most constrained variable
Country E is the most constrained
one (cannot use Red, Green)
• Least constraining value
-- Assume we have chosen variable C
-- What color is the least
constraining color?
Heuristics for CSPs
Examples: map coloring
Heuristics
• Most constrained variable
Country E is the most constrained
one (cannot use Red, Green)
• Least constraining value
-- Assume we have chosen variable C
-- Red is the least constraining valid color
for the future
Minimum remaining values (MRV)