CSE-41XX
CS-4101 AI

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:

AspectSearch for Planning (Sequence of Actions)Search for Assignment (Identification / CSP)
Primary GoalFinding 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 ImportanceEssential — 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 Examples8-Puzzle, Route Finding, AA^* 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:

  1. Constraint Satisfaction Problems (CSPs): The objective is simply to find one (or all) assignments of values to variables that satisfy every hard constraint.
  2. Constraint Optimization Problems (COPs): The objective goes beyond satisfying hard constraints to optimize a given objective function f(x)f(x) (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 X,D,C\langle X, D, C \rangle:

  1. Variables (XX): A finite set of variables X={X1,X2,,Xn}X = \{X_1, X_2, \dots, X_n\}.
  2. Domains (DD): A set of domains D={D1,D2,,Dn}D = \{D_1, D_2, \dots, D_n\}, where each domain Di={v1,v2,,vk}D_i = \{v_1, v_2, \dots, v_k\} defines the set of allowable values for variable XiX_i.
  3. Constraints (CC): A set of constraints {C1,C2,,Cm}\{C_1, C_2, \dots, C_m\} 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 XX.
  • Complete Assignment: An assignment in which every variable XiXX_i \in X has been assigned a value from its domain DiD_i.
  • Consistent (Legal) Assignment: An assignment (partial or complete) that does not violate any constraint in CC.
  • 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 nn variables with maximum domain size dd, the total number of complete assignments is O(dn)O(d^n).
    • Example: In the 8-Queens Problem, variables Q1,,Q8Q_1, \dots, Q_8 represent queen row positions in columns 181 \dots 8, with domains Di={1,2,3,4,5,6,7,8}D_i = \{1, 2, 3, 4, 5, 6, 7, 8\}.
  • Infinite Domains: Variables range over infinite discrete sets (e.g., integers Z\mathbb{Z} 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., T1+d1T2T_1 + d_1 \le T_2) 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:

  1. Unary Constraints: Restrict the domain of a single variable.
    • Example: SAgreenSA \neq \text{green}.
  2. Binary Constraints: Relate pairs of variables.
    • Implicit representation: SAWASA \neq WA.
    • Explicit tuple representation: (WA,NT){(red,green),(red,blue),(green,red),(green,blue),(blue,red),(blue,green)}(WA, NT) \in \{(\text{red}, \text{green}), (\text{red}, \text{blue}), (\text{green}, \text{red}), (\text{green}, \text{blue}), (\text{blue}, \text{red}), (\text{blue}, \text{green})\}.
  3. Higher-Order Constraints: Involve 3 or more variables (e.g., column addition constraints in Crypt-arithmetic puzzles).
  4. 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).
  5. 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.

Map of Australia

[!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:

  1. Solves the CSP completely: Reduces every variable domain to size 1 (no search required!).
  2. Detects Unsatisfiability: Reduces at least one domain to size 0 (Domain Wipeout / DWO), proving no solution exists.
  3. 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 {red,green,blue}\{ \text{red}, \text{green}, \text{blue} \}. Suppose we assign SA=blueSA = \text{blue}.

  • Without Constraint Propagation: For the 5 unassigned neighboring variables (WA,NT,Q,NSW,VWA, NT, Q, NSW, V), a naive search procedure must consider: 35=243 combinations3^5 = 243 \text{ combinations}
  • With Constraint Propagation: Because SA=blueSA = \text{blue}, the color blue\text{blue} is immediately removed from the domains of all 5 neighbors. Each neighbor now has only 2 valid options left ({red,green}\{ \text{red}, \text{green} \}): 25=32 combinations2^5 = 32 \text{ combinations}
  • Search Space Reduction: 2433224387% reduction\frac{243 - 32}{243} \approx \mathbf{87\% \text{ 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 [Dimin,Dimax][D_i^{\text{min}}, D_i^{\text{max}}]. 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 F1F_1 and F2F_2:

  • Flight capacities: Flight F1F_1 holds up to 165 passengers; Flight F2F_2 holds up to 385 passengers. D1=[0,165],D2=[0,385]D_1 = [0, 165], \quad D_2 = [0, 385]
  • Constraint: Combined, both flights must carry exactly 420 passengers (F1+F2=420F_1 + F_2 = 420).

Enforcing Bounds Consistency:

  1. To satisfy F1=420F2F_1 = 420 - F_2:
    • Minimum possible F1=420max(F2)=420385=35F_1 = 420 - \max(F_2) = 420 - 385 = \mathbf{35}
    • Maximum possible F1=420min(F2)=4200=420    capped at capacity 165F_1 = 420 - \min(F_2) = 420 - 0 = 420 \implies \text{capped at capacity } \mathbf{165}
  2. To satisfy F2=420F1F_2 = 420 - F_1:
    • Minimum possible F2=420max(F1)=420165=255F_2 = 420 - \max(F_1) = 420 - 165 = \mathbf{255}
    • Maximum possible F2=420min(F1)=4200=420    capped at capacity 385F_2 = 420 - \min(F_1) = 420 - 0 = 420 \implies \text{capped at capacity } \mathbf{385}

The pruned interval domains become: D1=[35,165],D2=[255,385]D_1 = [35, 165], \quad D_2 = [255, 385]


Hierarchy of Local Consistency

Local consistency algorithms enforce constraint rules on localized subgraphs, propagating removals throughout the network.

1. Node Consistency

A variable XX is node-consistent if every value in its domain DXD_X satisfies all unary constraints C(X)C(X) on XX.

  • Formal condition: vDX, satisfies C(v)\forall v \in D_X, \text{ satisfies } C(v).
  • Example: Variable AA has domain DA={1,2,3,4}D_A = \{1, 2, 3, 4\} with unary constraint A>2A > 2. Pruning values {1,2}\{1, 2\} leaves DA={3,4}D_A = \{3, 4\}.

2. Arc Consistency

A variable XX is arc-consistent with respect to another variable YY (written as directed arc XYX \rightarrow Y) if for every value xDXx \in D_X, there exists at least one value yDYy \in D_Y such that the binary constraint C(X,Y)C(X, Y) is satisfied.

  • Formal condition: xDX,yDY s.t. (x,y)CXY\forall x \in D_X, \exists y \in D_Y \text{ s.t. } (x, y) \in C_{XY}.
  • If any xDXx \in D_X lacks such supporting yy, xx is removed from DXD_X.

[!IMPORTANT] Arc Consistency is Directed: Arc XYX \rightarrow Y consistency does not imply YXY \rightarrow X consistency. Both directions must be checked and enforced independently.

Concrete Example

  • Variables: X{1,2,3}X \in \{1, 2, 3\}, Y{2,3}Y \in \{2, 3\}
  • Constraint: X<YX < Y

Check directed arc XYX \rightarrow Y:

  1. X=1X = 1: Supported by y=2y = 2 and y=3y = 3 (1<2,1<31 < 2, 1 < 3). (Kept)
  2. X=2X = 2: Supported by y=3y = 3 (2<32 < 3). (Kept)
  3. X=3X = 3: No yDYy \in D_Y satisfies 3<y3 < y. (Pruned!)

Revised Domain: DX={1,2}D_X = \{1, 2\}.

3. Path Consistency & K-Consistency

  • Path Consistency: Evaluates triples of variables {Xi,Xj,Xk}\{X_i, X_j, X_k\}. A pair of values {xi,xj}\{x_i, x_j\} consistent with binary constraint C(Xi,Xj)C(X_i, X_j) is path-consistent with XkX_k if there exists a value xkDkx_k \in D_k satisfying C(Xi,Xk)C(X_i, X_k) and C(Xj,Xk)C(X_j, X_k).
  • K-Consistency: Generalizes local consistency. A CSP is kk-consistent if for any consistent assignment to (k1)(k-1) variables, any kk-th variable can be assigned a consistent value.
    • 1-consistency = Node consistency.
    • 2-consistency = Arc consistency.
    • 3-consistency = Path consistency.
    • A CSP is strongly kk-consistent if it is kk-consistent, (k1)(k-1)-consistent, ..., down to 1-consistent. If a graph with nn variables is strongly nn-consistent, a solution can be found in O(nd)O(n \cdot d) 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 DiD_i is pruned, all incoming arcs (XkXi)(X_k \rightarrow X_i) from neighboring variables must be re-queued, because values in DkD_k 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 revised

Trace Walkthrough: Divisibility Constraint Network

Trace AC-3 on three variables {x,y,z}\{x, y, z\} with divisibility constraints:

  • Constraints: zz divides xx and zz divides yy (i.e., x/zZx/z \in \mathbb{Z} and y/zZy/z \in \mathbb{Z}).
  • Initial Domains: Dx={2,5}D_x = \{2, 5\}, Dy={2,4}D_y = \{2, 4\}, Dz={2,5}D_z = \{2, 5\}.

Initial Queue: Queue={(x,z),(z,x),(y,z),(z,y)}\text{Queue} = \{(x, z), (z, x), (y, z), (z, y)\}

  1. Pop (z,y)(z, y): Check if each zDzz \in D_z divides some yDy={2,4}y \in D_y = \{2, 4\}.
    • z=2z = 2: divides y=2y=2 and y=4y=4. (Kept)
    • z=5z = 5: does not divide 22 or 44. (Pruned!)
    • Domain update: Dz={2}D_z = \{2\}. Re-queue neighbors pointing to zz: (x,z)(x, z) is already in queue.
  2. Pop (x,z)(x, z): Check if each xDx={2,5}x \in D_x = \{2, 5\} has a divisor zDz={2}z \in D_z = \{2\}.
    • x=2x = 2: divisible by z=2z=2. (Kept)
    • x=5x = 5: not divisible by z=2z=2. (Pruned!)
    • Domain update: Dx={2}D_x = \{2\}.
  3. Pop (z,x)(z, x): Check z{2}z \in \{2\} divides x{2}x \in \{2\}. Valid. (No change).
  4. Pop (y,z)(y, z): Check y{2,4}y \in \{2, 4\} is divisible by z{2}z \in \{2\}. Valid. (No change).

Final Arc-Consistent Domains: Dx={2},Dy={2,4},Dz={2}D_x = \{2\}, \quad D_y = \{2, 4\}, \quad D_z = \{2\}


Comparison of Arc Consistency Algorithms (AC-1 to AC-4)

AlgorithmQueueing StrategyTime ComplexitySpace ComplexityPerformance & Trade-offs
AC-1Brute Force Pass: If any domain changes, re-tests all arcs in the graph.O(d3ne)O(d^3 \cdot n \cdot e)O(e)O(e)Highly redundant; re-evaluates unchanged constraints repeatedly.
AC-2Variable-Based Queueing: Queues variable pairs based on modified variables.O(ed3)O(e \cdot d^3)O(e)O(e)Intermediate algorithm; superseded by the simpler arc-based AC-3.
AC-3Arc-Based Queueing: Re-queues only directed arcs (XkXi)(X_k \rightarrow X_i) affected by domain pruning.O(ed3)O(e \cdot d^3)O(e)O(e)Industry Standard: Optimal memory footprint (O(e)O(e)) and fast average-case performance.
AC-4Support Counter Tables: Pre-computes support counters for every value pair (Xi,vi)(X_i, v_i).O(ed2)O(e \cdot d^2)O(ed2)O(e \cdot d^2)Optimal worst-case time complexity, but high memory overhead and implementation complexity.

(Where n=Xn = |X| is variable count, d=maxDid = \max |D_i| is maximum domain size, and e=Ce = |C| is binary constraint arc count.)

On this page