Constraint Satisfaction Problems: Dr. Amar Singh Associate Professor, School of Computer Applications
Constraint Satisfaction Problems: Dr. Amar Singh Associate Professor, School of Computer Applications
• Initial state?
• Set of operators?
• Goal state?
• Path cost?
Example: The 8-puzzle
3 M, 3 C Send 2 C 0 M, 2 C
3 M, 2 C 1 C came back 0 M, 1 C
3M, 0 C Send 2 C 0 M, 3 C
3M, 1 C 1 C came back 0 M, 2 C
1M, 1 C Send 2 M 2 M, 2C
2M, 2 C 1 M, 1C came back 1 M, 1 C
0 M, 2C send 2 M 3 M, 1 C
0M,3C 1 C came back 3 M, 0 C
0, 1 M Send 2 C 3 M, 2 C
0 M, 2 C Send 1 C back 3 M, 1 C
0 M, 0 C Send 2 C 3 M, 1 C
Introduction
• A Constraint Satisfaction Problem consists of:
– A set of variables, X
– For each variable xi in X, a domain Di.
• D is finite set of possible values.
– A set of constraints restricting tuples of values.
• If only pair of values, it’s a binary CSP.
– A solution is an assignment of value in Di to each
variable xi such that every constraint satisfied.
Examples
• Many problems in AI are types of CSP.
– Scheduling
– Time Table
– Graph Coloring
– Machine Vision
– Puzzles
Coloring in CSP
• Can we color all 4 regions with 3 colors so that
no two adjacent regions are of same color
V3
V1
V4
V2
Example: 8-Queens
Example: 8-Queens
• Variables: 64 squares, number of queens
V = {S1,1, S1,2, …, S8,8, Number_of_queens}
• Values: Queen or No-Queen
Si,j is an element of DS = {queen, empty}
Number_of_queens is an element of DN = [0, 64]
• Constraints: Attacks, queen count
{Number_of_queens = 8,
Si,j = queen Si,j+n = empty,
Si,j = queen Si+n,j = empty,
Si,j = queen Si+n,j+n = empty}
Sudoku Game
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
Send
More
Money
S 9
E 5
N 6
D 7
M 1
O 0
R 8
Y 3
Example: Map-Coloring
Note: In
general, 4 colors
are necessary
• Variables: WA, NT, Q, NSW, V, SA, T
• Domains: Di = {red,green,blue}
• Constraints: adjacent regions must have different colors
e.g., WA ≠ NT, or (WA,NT) in {(red,green), (red,blue),
(green,red), (green,blue), (blue,red), (blue,green)}
Example: Map-Coloring