Lecture 07.1: Constraint Satisfaction Problems and Consistency
An in-depth introduction to Constraint Processing, CSP formalisms, varieties of constraints, constraint graphs, bounds consistency, and arc consistency algorithms like AC-3.
In artificial intelligence, problem-solving strategies generally fall into two broad paradigms based on what the search procedure is seeking:
| Aspect | Search for Planning (Sequence of Actions) | Search for Assignment (Identification / CSP) |
|---|---|---|
| Primary Goal | Finding an optimal or valid path (sequence of actions) to reach a target state. | Finding a complete and consistent state (assignment of values to variables). |
| Path Importance | Essential — path cost, action order, and search depth dictate the solution quality. | Irrelevant — how the assignment is constructed does not matter; only the final state matters. |
| Typical Examples | 8-Puzzle, Route Finding, Search, Game Playing. | Map Coloring, Sudoku, N-Queens, Course Scheduling, VLSI Layout. |
The Constraint Processing Framework
Constraint Processing (pioneered by Rina Dechter) is a general computational framework for modeling and solving problems defined by a set of variables, allowable domain values, and constraints. Constraint processing separates problem modeling into two paradigms:
- Constraint Satisfaction Problems (CSPs): The objective is simply to find one (or all) assignments of values to variables that satisfy every hard constraint.
- Constraint Optimization Problems (COPs): The objective goes beyond satisfying hard constraints to optimize a given objective function (e.g., minimizing cost, execution time, or maximizing resource efficiency) while adhering to constraints.
Formal Definition of a CSP
A Constraint Satisfaction Problem consists of three core components :
- Variables (): A finite set of variables .
- Domains (): A set of domains , where each domain defines the set of allowable values for variable .
- Constraints (): A set of constraints specifying allowable combinations of values for subsets of variables.
State & Assignment Terminology
- Partial Assignment: An assignment that attributes values to only a subset of variables in .
- Complete Assignment: An assignment in which every variable has been assigned a value from its domain .
- Consistent (Legal) Assignment: An assignment (partial or complete) that does not violate any constraint in .
- Solution: A complete and consistent assignment.
[!NOTE] Why Formalize Problems as CSPs? Standard state-space search requires problem-specific heuristics (e.g., Manhattan distance for 8-puzzle). CSP solvers use a standardized representation pattern, enabling generic goal/successor functions and general-purpose heuristics (such as MRV or Arc Consistency) that operate without domain-specific engineering. Moreover, CSP solvers can rapidly prune massive subtrees of search space.
Varieties of CSP Formalisms
CSPs are categorized based on the nature of their variable domains:
1. Discrete Domains
- Finite Domains: Variables take values from finite sets. For variables with maximum domain size , the total number of complete assignments is .
- Example: In the 8-Queens Problem, variables represent queen row positions in columns , with domains .
- Infinite Domains: Variables range over infinite discrete sets (e.g., integers or strings).
- Example: Job shop scheduling without fixed upper deadlines allows start times to grow arbitrarily.
- Constraint Languages: Since allowable value pairs cannot be explicitly enumerated for infinite domains, a constraint language (e.g., ) must be used directly.
2. Continuous Domains
Common in operations research and real-world engineering:
- Example: Precise scheduling of the Hubble Space Telescope, where continuous variables represent observation start times and pointing angles subject to astronomical, precedence, and power constraints.
- Linear Programming (LP): Continuous CSPs defined by linear equalities and inequalities, solvable in polynomial time relative to variable count.
- Nonlinear Programming: Extensions include Quadratic Programming (QP) and Second-Order Conic Programming (SOCP).
Varieties of Constraints
Constraints can be classified by their scope (number of variables involved) and strictness:
- Unary Constraints: Restrict the domain of a single variable.
- Example: .
- Binary Constraints: Relate pairs of variables.
- Implicit representation: .
- Explicit tuple representation: .
- Higher-Order Constraints: Involve 3 or more variables (e.g., column addition constraints in Crypt-arithmetic puzzles).
- Global Constraints: Involve an arbitrary number of variables.
- Note on terminology: The term "global" is traditional but can be misleading; it does not require involving all variables in a problem, but rather an arbitrary list (e.g.,
Alldiff(X_1, X_2, \dots, X_k)in Sudoku rows/columns).
- Note on terminology: The term "global" is traditional but can be misleading; it does not require involving all variables in a problem, but rather an arbitrary list (e.g.,
- Preference (Soft) Constraints: Specify desirable assignments rated by costs or penalties rather than strict hard limits.
- Example (Class Assignment): Professor Jan prefers morning slots while Alex prefers afternoon slots. Assigning an afternoon slot to Jan incurs a penalty cost of 2 points, whereas a morning slot costs 1 point.
- Example (Timetabling): Classroom capacity vs. enrollment is a hard constraint; avoiding simultaneous scheduling of related classes is a soft constraint.
Constraint Graphs
A binary CSP can be represented visually as a Constraint Graph, where nodes represent variables and edges (arcs) represent binary constraints between them.

[!TIP] Subproblem Decomposition: Notice that
T(Tasmania) is completely disconnected from the rest of the Australian mainland graph. Tasmania is an independent subproblem, which can be solved separately without impacting mainland variable assignments!
Constraint Propagation & Search Space Pruning
Constraint Propagation uses constraints to recursively enforce consistency across variables, shrinking variable domains either as a preprocessing step before search or interleaved during search.
Preprocessing Outcomes
When run as a preprocessing step, constraint propagation produces one of three outcomes:
- Solves the CSP completely: Reduces every variable domain to size 1 (no search required!).
- Detects Unsatisfiability: Reduces at least one domain to size 0 (Domain Wipeout / DWO), proving no solution exists.
- Reduces Search Space: Shrinks domains to smaller sets, simplifying subsequent search.
Quantifying Search Space Reduction
Consider the Australia Map Coloring problem with 7 variables and 3 colors . Suppose we assign .
- Without Constraint Propagation: For the 5 unassigned neighboring variables (), a naive search procedure must consider:
- With Constraint Propagation: Because , the color is immediately removed from the domains of all 5 neighbors. Each neighbor now has only 2 valid options left ():
- Search Space Reduction: in search states evaluated!
Bounds Consistency
For continuous domains or large integer bounds where enumerating individual domain values is prohibitive, solvers enforce Bounds Consistency.
Instead of tracking discrete sets, domains are represented by continuous or integer intervals . Bounds consistency ensures that for each boundary value of a variable's domain, there exist matching boundary values in adjacent variables that satisfy the constraints.
Example: Airline Transportation Scheduling
Consider scheduling passengers across two airline flights and :
- Flight capacities: Flight holds up to 165 passengers; Flight holds up to 385 passengers.
- Constraint: Combined, both flights must carry exactly 420 passengers ().
Enforcing Bounds Consistency:
- To satisfy :
- Minimum possible
- Maximum possible
- To satisfy :
- Minimum possible
- Maximum possible
The pruned interval domains become:
Hierarchy of Local Consistency
Local consistency algorithms enforce constraint rules on localized subgraphs, propagating removals throughout the network.
1. Node Consistency
A variable is node-consistent if every value in its domain satisfies all unary constraints on .
- Formal condition: .
- Example: Variable has domain with unary constraint . Pruning values leaves .
2. Arc Consistency
A variable is arc-consistent with respect to another variable (written as directed arc ) if for every value , there exists at least one value such that the binary constraint is satisfied.
- Formal condition: .
- If any lacks such supporting , is removed from .
[!IMPORTANT] Arc Consistency is Directed: Arc consistency does not imply consistency. Both directions must be checked and enforced independently.
Concrete Example
- Variables: ,
- Constraint:
Check directed arc :
- : Supported by and (). (Kept)
- : Supported by (). (Kept)
- : No satisfies . (Pruned!)
Revised Domain: .
3. Path Consistency & K-Consistency
- Path Consistency: Evaluates triples of variables . A pair of values consistent with binary constraint is path-consistent with if there exists a value satisfying and .
- K-Consistency: Generalizes local consistency. A CSP is -consistent if for any consistent assignment to variables, any -th variable can be assigned a consistent value.
- 1-consistency = Node consistency.
- 2-consistency = Arc consistency.
- 3-consistency = Path consistency.
- A CSP is strongly -consistent if it is -consistent, -consistent, ..., down to 1-consistent. If a graph with variables is strongly -consistent, a solution can be found in time with zero backtracking!
The AC-3 Algorithm
The AC-3 algorithm (Mackworth, 1977) maintains a queue of directed arcs requiring verification. When a domain is pruned, all incoming arcs from neighboring variables must be re-queued, because values in that relied on the pruned value for support may now be invalid.
Pseudocode
function AC-3(csp) returns false if inconsistency is found, true otherwise
inputs: csp, a binary CSP with variables X, domains D, constraints C
local variables: queue, a queue of arcs, initially containing all arcs in csp
while queue is not empty do
(Xi, Xj) = REMOVE-FIRST(queue)
if REVISE(csp, Xi, Xj) then
if size of Di == 0 then
return false // Domain Wipe Out (DWO) - no solution exists
for each Xk in Xi.NEIGHBORS - {Xj} do
add (Xk, Xi) to queue
return true
function REVISE(csp, Xi, Xj) returns true iff we revise the domain of Xi
revised = false
for each x in Di do
if no value y in Dj satisfies the constraint between Xi and Xj then
delete x from Di
revised = true
return revisedTrace Walkthrough: Divisibility Constraint Network
Trace AC-3 on three variables with divisibility constraints:
- Constraints: divides and divides (i.e., and ).
- Initial Domains: , , .
Initial Queue:
- Pop : Check if each divides some .
- : divides and . (Kept)
- : does not divide or . (Pruned!)
- Domain update: . Re-queue neighbors pointing to : is already in queue.
- Pop : Check if each has a divisor .
- : divisible by . (Kept)
- : not divisible by . (Pruned!)
- Domain update: .
- Pop : Check divides . Valid. (No change).
- Pop : Check is divisible by . Valid. (No change).
Final Arc-Consistent Domains:
Comparison of Arc Consistency Algorithms (AC-1 to AC-4)
| Algorithm | Queueing Strategy | Time Complexity | Space Complexity | Performance & Trade-offs |
|---|---|---|---|---|
| AC-1 | Brute Force Pass: If any domain changes, re-tests all arcs in the graph. | Highly redundant; re-evaluates unchanged constraints repeatedly. | ||
| AC-2 | Variable-Based Queueing: Queues variable pairs based on modified variables. | Intermediate algorithm; superseded by the simpler arc-based AC-3. | ||
| AC-3 | Arc-Based Queueing: Re-queues only directed arcs affected by domain pruning. | Industry Standard: Optimal memory footprint () and fast average-case performance. | ||
| AC-4 | Support Counter Tables: Pre-computes support counters for every value pair . | Optimal worst-case time complexity, but high memory overhead and implementation complexity. |
(Where is variable count, is maximum domain size, and is binary constraint arc count.)
Lecture 06.3: Monte Carlo Tree Search (MCTS)
Scaling adversarial search to massive state spaces using randomness and the UCB1 algorithm in Monte Carlo Tree Search.
Lecture 07.2: Backtracking and Local Search for CSPs
Exploring backtracking algorithms, intelligent heuristics (MRV, Degree, LCV), Forward Checking, and the Min-Conflicts Local Search.