Basic Constraint Satisfaction Problem (CSP) with Three Variables and Backtracking
A constraint satisfaction problem (CSP) is defined by: (i) a set of variables, (ii) a domain, and (iii) a set of constraints that restrict combinations of values. In a CSP, the goal is to find an assignment of values to all variables such that all constraints are satisfied.
To make this concrete, we will define a simple CSP with three variables , each having a small finite domain, plus binary constraints that relate pairs of variables. We will then solve it using backtracking search, where we assign variables one by one, check constraint satisfaction so far, and backtrack when we hit a dead end.
CSP components (what you “plug in”)
- Domain: limits the values each variable can take.
- Unary constraint: restricts one variable’s values.
- Binary constraint: restricts allowed value pairs.
- Consistency check: used during backtracking.
Constraint Satisfaction Problem (CSP) and Backtracking Search (Intro)
A Concrete 3-Variable CSP Example
We define a CSP with three variables:
And constraints:
- (all different between and )
- (all different between and )
- (ties and together)
This CSP is small but illustrates everything you asked for: the role of the domain (what values are even allowed), and the role of the constraints (which combinations/relations are permitted).
Formal CSP definition
- Variables:
- Domains:
- Constraints:
What constraints do (intuitively)
- The domain says “you may try these values.”
- The constraints say “you may not keep these combinations if they violate the rules.”
So in backtracking, we don’t just search blindly—we prune when the partial assignment already violates any constraint.
Pro Tip: Think “pruning”
In backtracking CSP solving, constraints are used to prune invalid partial assignments early, reducing the search space.
Role of the Domain and Constraints (in backtracking)
1) Domain controls branching factor
Backtracking assigns values from each variable’s domain. If has size , then at the point when you pick , there are up to choices. Smaller domains generally make search faster.
2) Constraints control pruning
A constraint can rule out:
- complete assignments (when all involved variables are assigned), and
- partial assignments (when some involved variables are assigned).
For our example:
- If you already assigned and you try , the constraint can reject a candidate immediately.
- If you assigned and you try , the constraint can reject immediately.
- If you attempt to maintain , then once is assigned, becomes forced to that value (or rejected if you try something else).
Backtracking Backtracking-Solve the 3-Variable CSP
- 1Step 1
Use the order (any fixed order works).
- 2Step 2
Start with (no variables assigned yet).
- 3Step 3
Try ; since there are no constraints violated yet (no other variables assigned), keep the partial assignment.
- 4Step 4
Given , enforce . Allowed values are . Try first.
- 5Step 5
Given and , constraints require: (i) so , and (ii) so . Check: satisfies .
- 6Step 6
Now is a complete assignment and satisfies all constraints.
- 7Step 7
If you had tried while , it would violate immediately; you would reject and try the next value.
Backtracking Search Tree (visual)
Below is a simplified search tree showing how constraints prune choices.
Search Impact of Constraints (Qualitative)
This illustrates that constraints reduce the number of candidate branches kept during search.
Common CSP/Backtracking Details
Backtracking CSP Solving Lifecycle
Model
1Specify variables, domains, and constraints."
Order & Start
2Pick a variable order and begin with an empty assignment."
Select Value
3Try a value from the current variable’s domain."
Check Constraints
4If any constraint is violated, reject immediately."
Recurse or Backtrack
5If consistent, move deeper; otherwise undo and try next value."
Finish
6When all variables assigned consistently, output the solution."
CSP + Backtracking Quick Recall
Knowledge Check
In a CSP, the domain of a variable specifies: