Constraint Satisfaction Problems
Constraint Satisfaction Problems
Problems
Constraint satisfaction problems
• What is a CSP?
• Finite set of variables X1, X2, …, Xn
• Nonempty domain of possible values for each variable
D1, D2, … Dd
• Finite set of constraints C1, C2, …, Cm
• Each constraint Ci limits the values that variables can take, e.g., X1 ≠ X2
• A state is defined as an assignment of values to some or all variables.
• Consistent assignment: assignment does not violate the constraints.
Constraint satisfaction problems
• Depth-first search for CSPs with single-variable assignments is called backtracking search
1 2 3 4 X1 X2
1 {1,2,3,4} {1,2,3,4}
2
3
4
X3 X4
{1,2,3,4} {1,2,3,4}
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 {1,2,3,4} {1,2,3,4}
2
3
4
X3 X4
{1,2,3,4} {1,2,3,4}
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 {1,2,3,4} { , ,3,4}
2
3
4
X3 X4
{ ,2, ,4} { ,2,3, }
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 {1,2,3,4} { , ,3,4}
2
3
4
X3 X4
{ ,2, ,4} { ,2,3, }
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 {1,2,3,4} { , ,3,4}
2
3
4
Backtrack!!!
X3 X4
{ , , , } { ,2, , }
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 { ,2,3,4} {1,2,3,4}
2
3
4
X3 X4
{1,2,3,4} {1,2,3,4}
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4
X3 X4
{1, ,3, } {1, ,3,4}
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4
X3 X4
{1, ,3, } {1, ,3,4}
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4
X3 X4
{1, , , } {1, ,3, }
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4
X3 X4
{1, , , } {1, ,3, }
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4
X3 X4
{1, , , } { , ,3, }
Example: 4-Queens Problem
1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4
X3 X4
{1, , , } { , ,3, }
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