Constraint Satisfaction Problems (CSPs): Detailed Description, Formalism, and Solving Methods
A Constraint Satisfaction Problem (CSP) is a structured decision problem where we model unknowns as variables with domains and restrict combinations via constraints so that the final assignment satisfies every constraint. Formally, a CSP instance consists of a finite set of variables, each with a finite domain, plus a set of constraints over subsets of variables; a solution is any assignment that makes all constraints true simultaneously.
Many CSPs are computationally hard in the worst case: determining whether a general finite-domain CSP is satisfiable is NP-complete, though important restricted classes become tractable.
Footnotes
-
Introduction and basic definitions — CS-E3220: CSP documentation - Defines CSP as variables with domains and constraints; defines solutions/satisfiable/unsatisfiable. ↩
-
Complexity of constraint satisfaction - Wikipedia - States that satisfiability for finite-domain CSPs is NP-complete in general; discusses tractable restrictions. ↩
Constraint Satisfaction Problems (CSP): Core Ideas (Variables, Domains, Constraints)
1) Formal definition and notation
A common formal definition is: a CSP instance is a triple where:
- is a finite set of variables.
- gives each variable a finite domain of values.
- is a finite set of constraints; each constraint is defined over some subset of variables and specifies which tuples of values are allowed. 2
A solution (sometimes called a satisfying assignment) is an assignment that maps every variable to a value and makes every constraint evaluate to true.
Satisfaction vs. satisfiable vs. unsatisfiable
- Satisfaction: an assignment satisfies a CSP if it satisfies all constraints.
- Satisfiable: there exists at least one satisfying assignment.
- Unsatisfiable: no satisfying assignment exists.
Key learning terms (1): Variables; Domain; Constraint; Assignment; Solution
Footnotes
-
Introduction and basic definitions — CS-E3220: CSP documentation - Defines CSP as variables with domains and constraints; defines solutions/satisfiable/unsatisfiable. ↩ ↩2 ↩3 ↩4 ↩5
-
Constraint satisfaction problem - Wikipedia - Formal definition and description of CSP structure; also frames CSP as search/decision. ↩
2) Modeling: how real problems become CSPs
The practical power of CSPs is their modeling workflow:
- Identify the decisions as variables.
- Identify allowable values as domains.
- Encode relationships/requirements as constraints.
Classic examples include scheduling, map coloring, and Sudoku.
Constraint types (conceptual)
Constraints can be:
- Unary constraints: restrict a variable’s domain.
- Binary constraints: restrict compatible pairs.
- Higher-arity constraints: restrict allowed tuples across multiple variables.
Binary constraints are especially convenient because many propagation techniques (like arc consistency) are defined using constraint graphs with directed edges.
Key learning terms (2): Constraint arity; Constraint graph; Unary/Binary/Higher-arity constraints
Footnotes
-
Constraint Satisfaction Problems (CSP) - YouTube video - Overview examples and components: variables, domains, constraints, and common solving approaches. ↩
-
Making AC-3 an Optimal Algorithm (paper) - Definitions including arc consistency and CSP arc formulation; describes arc consistency enforcement context. ↩
3) CSP search view: partial assignments and dead ends
To solve a CSP, solvers typically perform search over assignments. A central idea is that you don’t wait for full assignments: you maintain a partial assignment and check whether it is consistent with the constraints that are fully determined so far.
A standard baseline procedure is backtracking search:
- Start with an empty assignment.
- Pick an unassigned variable.
- Try values from its domain.
- If the choice violates constraints (given current assignments), backtrack.
- If all variables are assigned consistently, return success.
This “choose-try-check-undo” pattern is explicitly described for CSP backtracking search in course notes, including pseudocode structure and the role of variable/value ordering.
Footnotes
-
Constraint Satisfaction Problems (CMU course notes) - Discusses backtracking search and heuristics MRV/LCV; includes pseudocode and ordering ideas. ↩
Backtracking search for CSPs (process)
- 1Step 1
Start with an empty partial assignment and every variable unassigned.
- 2Step 2
Use a variable-ordering heuristic (e.g., MRV) to choose the next variable to try.
- 3Step 3
Try candidate values for the selected variable (optionally ordered by LCV).
- 4Step 4
If the partial assignment with the chosen value violates any constraint, reject it.
- 5Step 5
If consistent, extend the partial assignment and recurse to assign the next variable.
- 6Step 6
If deeper recursion fails (no completion exists), remove the last assignment and try the next value.
- 7Step 7
If every variable is assigned consistently, return the complete assignment; otherwise return failure.
Pro Tip: Reduce branching early
Backtracking can still be exponential. Use constraint reasoning (e.g., forward checking and arc consistency) to prune domains immediately after each assignment, shrinking the search tree. 2
Footnotes
-
Constraint Satisfaction Problems (CMU course notes) - Discusses backtracking search and heuristics MRV/LCV; includes pseudocode and ordering ideas. ↩
-
Solving Constraint Satisfaction Problems in AI: Backtracking, Arc Consistency, and Heuristics (CamelEdge) - Explains forward checking/heuristics interplay with pruning; discusses arc consistency conceptually. ↩
4) Constraint propagation: arc consistency and AC-3
Pure backtracking only checks constraints when variables become assigned. Constraint propagation improves performance by removing values from domains that cannot participate in any solution extension.
Arc consistency
A central local consistency notion is arc consistency for binary constraints. For a directed arc , the arc is arc-consistent if for every value there exists some value such that the binary constraint between and allows .
A CSP is arc-consistent if every arc in its constraint graph satisfies this property.
AC-3 algorithm
The AC-3 algorithm enforces arc consistency by:
- Starting with a worklist of all directed arcs.
- Repeatedly selecting an arc .
- Performing a “revise” step that removes values from that have no supporting value in .
- When changes, re-adding neighboring arcs (into the worklist) because pruning may create new inconsistencies. 2
AC-3 was proposed by Mackworth in 1977, and the Wikipedia entry describes its queue/worklist behavior and directed-arc interpretation. 2
Footnotes
-
Making AC-3 an Optimal Algorithm (paper) - Definitions including arc consistency and CSP arc formulation; describes arc consistency enforcement context. ↩ ↩2 ↩3 ↩4
-
AC-3 algorithm - Wikipedia - Describes AC-3 worklist processing and pruning of unsupported values to enforce arc consistency. ↩ ↩2
AC-3 (Arc Consistency Algorithm #3) at a high level
- 1Step 1
Put every directed arc implied by binary constraints onto a queue.
- 2Step 2
Remove one arc from the queue.
- 3Step 3
Remove any value for which there is no value satisfying the constraint.
- 4Step 4
If becomes empty, the CSP is inconsistent under current pruning.
- 5Step 5
If any value was removed from , add all arcs for neighbors back to the queue (except ).
- 6Step 6
When the queue is empty, the remaining domains are arc-consistent.
Arc consistency is not the same as a full solution
AC-3 can prune domains and detect inconsistency, but it typically does not directly output a full assignment—only that no further arc-consistency pruning is possible. Backtracking (or another search) may still be needed to construct a complete solution." 2
Footnotes
-
AC-3 algorithm - Wikipedia - Describes AC-3 worklist processing and pruning of unsupported values to enforce arc consistency. ↩
-
Making AC-3 an Optimal Algorithm (paper) - Definitions including arc consistency and CSP arc formulation; describes arc consistency enforcement context. ↩
5) Heuristics: variable ordering and value ordering
Even with propagation, CSP solving often relies on heuristics to decide what to try next. Two widely used heuristics are:
MRV (Minimum Remaining Values)
MRV chooses the next variable to assign from those unassigned, selecting the one with the smallest number of legal values left (a “fail-fast” approach).
LCV (Least Constraining Value)
LCV orders domain values so that the chosen value rules out as little as possible from neighboring variables’ domains. 2
These heuristics are explicitly contrasted in CSP course material: MRV for variable selection and LCV for value ordering.
Footnotes
-
Constraint Satisfaction Problems (CMU course notes) - Discusses backtracking search and heuristics MRV/LCV; includes pseudocode and ordering ideas. ↩ ↩2 ↩3
-
Constraint Satisfaction Problems (CMU course notes) - Mentions least-constraining value heuristic for ordering domain values. ↩
Where MRV and LCV act in CSP solving
Heuristics typically modify which parts of the search tree get explored first.
6) Computational complexity and tractability
In general, satisfiability for CSPs over finite domains is NP-complete. This motivates studying restricted CSP classes:
- limiting the constraint language or allowed constraint structure,
- restricting the domain size,
- restricting constraint arity,
- or identifying special algebraic properties that yield polynomial-time algorithms.
The complexity of CSPs and their relationship to NP-completeness is summarized in standard references on CSP complexity.
Key learning terms (3): NP-complete; Tractability; Constraint language; CSP complexity
Footnotes
-
Complexity of constraint satisfaction - Wikipedia - States that satisfiability for finite-domain CSPs is NP-complete in general; discusses tractable restrictions. ↩ ↩2
Common misconceptions and clarifications
CSP Core Flashcards
Knowledge Check
Which statement best describes a Constraint Satisfaction Problem (CSP)?