2.8 Constraint Satisfaction Problems (CSP) (BT104CO)
1. What is a CSP?
In the framework of Russell and Norvig, a Constraint Satisfaction Problem (CSP) solves problems by looking at the internal structure of a state (Factored representation), rather than treating it as an Atomic "black box."
Variables
The set of items that need to be assigned values (e.g., $\{X_1, X_2...\}$).
Domains
The set of all possible values for each variable (e.g., $\{Red, Blue...\}$).
Constraints
Mathematical rules specifying which value combinations are allowed.
2. Types of Constraints
3. Cryptarithmetic Problems: The Rookie Guide
Solving Cryptarithmetic problems is like being a detective uncovering hidden digits. We use CSP principles: deduction, exhaustion, and "carry" variables.
Case Study Walkthrough: SEND + MORE = MONEY
M must be the carry. M = 1.4. 5 Classic Solved Problems
TWO
+ TWO
-----
FOUR
Logic: $R$ is even ($2O$). $F=1$ (carry). If $T=7, O=4 \to R=8$. If $W=3 \to U=6$.
BASE
+ BALL
------
GAMES
Logic: $G=1$ (carry). $A=0$ (since $2A=A$). If $B=7$ (with carry) $\to G=1, A=0$.
FORTY
TEN
+ TEN
-------
SIXTY
Logic: $2N=10 \to N=5$ or $0$. Testing confirms $N=0, E=5, T=8$.
EAT
+ THAT
-------
APPLE
Logic: $A=1$ (carry). $T=9$ (needed for carry). $P=0$ ($9+1=10$). $E=8$ ($9+9=18$).
4. Solving CSPs: Backtracking Search
The standard algorithm is Backtracking Search—a Depth-First Search that chooses values for one variable at a time, "backtracking" immediately if a constraint is violated.
Minimum Remaining Values: Pick the variable with the fewest "legal" values left. Also called the Most Constrained Variable.
Choice based on the largest number of constraints on other unassigned variables. Acts as a tie-breaker for MRV.
Least Constraining Value: Choose the value that rules out the fewest choices for its neighbors.
6. Quick Practice & Troubleshooting
Hint: $A=1$. Look at $C+I=A$.
Hint: $C=1, A=9$.
Hint: $O=1, T=2$.
Rookie Troubleshooting Guide
- Stuck? Find the letter that appears most often—that's your "anchor."
- Contradiction? If you find $E=5$ but $A$ is already $5$, your first guess (usually $S$ or $O$) was wrong. Backtrack!
- Carry Mark: Always write a small "$1$" above your math columns. It changes everything!
Unit 2 Assignment: CSP Master
Using the **Backtracking Search** logic and **MRV Heuristic**, solve the following 3 problems. Submit your step-by-step deductions.
USA + USSR = PEACE.