Constraint Satisfaction Problem
Constraint Satisfaction Problem
This lecture:
CSP Introduction and Backtracking Search
Chapter 6.1 – 6.4, except 6.3.3
Next lecture:
CSP Constraint Propagation & Local Search
Chapter 6.1 – 6.4, except 6.3.3
• CSP benefits
– Standard representation pattern
– Generic goal and successor functions
– Generic heuristics (no domain specific expertise).
Sudoku as a Constraint Satisfaction Problem
(CSP) 1 2 3 4 5 6
9
7 8
A
B
• Variables: 81 variables C
D
– A1, A2, A3, …, I7, I8, I9 E
F
– Letters index rows, top to bottom
G
– Digits index columns, left to right H
I
• Consistent assignment:
– An assignment that does not violate the constraints.
• Examples of Applications:
– Scheduling the time of observations on the Hubble Space Telescope
– Airline schedules
– Cryptography
– Computer vision, image interpretation
CSP example: Map coloring problem
• A solution is:
– A complete and consistent assignment.
– All variables assigned, all constraints satisfied.
• Constraint graph:
• No objective function
– Any complete and consistent solution is OK
• Solution
– Find a complete and consistent assignment
A Solution:
F=1, T=7, U=6, W=3, R=8, O=4,
X1=0, X2=0, X3=1
734
+734
1468
CSP Example: Cryptharithmetic puzzle
• Uninformed algorithm
– No good general performance
Backtracking search
function BACKTRACKING-SEARCH(csp) return a solution or failure
return RECURSIVE-BACKTRACKING({} , csp)
19
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
20
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
21
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
22
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
23
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
24
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
25
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
26
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
27
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
28
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
29
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
30