Constraint Satisfaction Problems (CSPs) are a class of problems in which the goal is to assign values to a set of variables in a way that satisfies a given set of constraints. Each variable has a domain (a set of possible values), and the constraints restrict the values that the variables can simultaneously take. CSPs are used in various fields such as AI, scheduling, planning, resource allocation, and more.
Variables: A and B, with domains {1, 2}, and constraint A=B.
AA
BB
A≠B
Steps:
Try A=1,B=1 (violates the constraint A=B), so backtrack.
A=1,B=1A = 1, B = 1
A≠B
Try A=1,B=2 (satisfies the constraint), solution found.
A=1,B=2A = 1, B = 2
Variables X,Y,Z, with X having only one possible value left, while Y and Z have two values. Assign X first to improve the chances of finding a solution quickly.
X,Y,ZX, Y, Z
XX
YY
ZZ
XX
Forward Checking:
After assigning a value to a variable, eliminate values from the domains of neighboring variables that would violate constraints.
Example: For variables X and Y with the constraint X<Y, assigning X=2 removes values ≤2 from Y’s domain.
XX
YY
X<YX < Y
X=2X = 2
≤2\leq 2
YY
Arc Consistency:
Variables A, B, and C with constraints A=B and B=C.
AA
BB
CC
A≠BA \neq B
B≠CB \neq C
If assigning C=3 leads to a conflict due to B=3, intelligent backtracking skips A and directly backtracks to B.
C=3C = 3
B=3B = 3
AA
BB
CSP with variables X,Y,Z from domain {1, 2, 3} and the constraint that no two variables can have the same value. Local search might start with X=1,Y=1,Z=3, then iteratively change Y’s value to 2 or 3 to satisfy the constraints.
X,Y,ZX, Y, Z
X=1,Y=1,Z=3X = 1, Y = 1, Z = 3
YY
The Map Coloring Problem is a classic example of a CSP where the objective is to assign colors to regions on a map such that no two adjacent regions have the same color.