Constraint Satisfaction Problems: AIMA: Chapter 6
Constraint Satisfaction Problems: AIMA: Chapter 6
AIMA: Chapter 6
Variables: F T U W R O, X1 X2 X3
Domain: {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
CIS 391 - Intro to AI 3
Constraint satisfaction problems
An assignment is complete when every
variable is assigned a value.
A solution to a CSP is a complete
assignment that satisfies all constraints.
Applications:
• Map coloring
• Line Drawing Interpretation
• Scheduling problems
—Job shop scheduling
—Scheduling the Hubble Space Telescope
• Floor planning for VLSI
Beyond our scope: CSPs that require a solution
that maximizes an objective function.
CIS 391 - Intro to AI 4
Example: Map-coloring
Continuous variables
• e.g., start/end times for Hubble Space Telescope observations
• linear constraints solvable in polynomial time by linear
programming
And so on….
And so on….
X1 X2
X1 X2 X3 X4 {1,2,3,4} {1,2,3,4}
1
2
3
4
X3 X4
{1,2,3,4} {1,2,3,4}
X1 X2
1 2 3 4 {1,2,3,4} {1,2,3,4}
1
2
3
4
X3 X4
{1,2,3,4} {1,2,3,4}
X1 X2
1 2 3 4 {1,2,3,4} { , ,3,4}
1
2
3
4
X3 X4
{ ,2, ,4} { ,2,3, }
X1 X2
1 2 3 4 {1,2,3,4} { , ,3,4}
1
2
3
4
X3 X4
{ ,2, ,4} { ,2,3, }
X1 X2
1 2 3 4 {1,2,3,4} { , ,3,4}
1
2
3
4
X3 X4
Backtrack!!!
{ , , , } { ,2,3, }
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, ,3, } {1, ,3,4}
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, ,3, } {1, ,3,4}
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, , , } {1, ,3, }
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, , , } {1, ,3, }
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, , , } { , ,3, }
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, , , } { , ,3, }
occluding
convex concave
arrow Y L T
junction junction junction junction
A2
A3
A1
L1
L3
L5 L6
Arrow 3 4x4x4= 64
L 6 4x4=16
T 4 4x4x4=64
Y 3 4x4x4=64
...
...
+
+ L3 ...
L3 ... +
-
L4
L5
Check
L1,L2,L3, Given
L1,L3, A1,A2, L1,L3, A1,A2,
L4,L5, A1,A2, L5,L6 L5,L6
L6 A3 A3 A3
A1,A3 A1,A3
…
L1, A1,A2, L1, A1, A3
L5,L6 A3 L5,L6
CIS 391 - Intro to AI 51
Inefficiencies: Towards AC-3
1. At each iteration, we only need to examine those
Xi where at least one neighbor of Xi has lost a value
in the previous iteration.
2. If Xi loses a value only because of edge
inconsistencies with Xj, we don’t need to check Xj
on the next iteration.
3. Removing a value on Xi can only make Xj edge-
inconsistent is with respect to Xi itself. Thus, we
only need to check that the labels on the pair (j,i) are
still consistent.
These insights lead a much better algorithm...
(i,j)
Xi Xj
To apply to CSPs:
• allow states with unsatisfied constraints
• operators reassign variable values