CSP Formulation and Examples

What is a CSP?

A Constraint Satisfaction Problem (CSP) replaces the atomic state of classical search with a factored representation: a set of variables, each with a domain of possible values, subject to constraints. This structure lets general-purpose inference algorithms exploit the problem’s internal anatomy rather than treating it as a black box.

Formal definition: A CSP is a triple (X, D, C):

Component Notation Meaning
Variables X = {X₁, …, Xₙ} What we are assigning
Domains D = {D₁, …, Dₙ} Legal values for each Xᵢ
Constraints C = {C₁, …, Cₘ} Restrictions on variable combinations

A solution is a complete, consistent assignment: every variable has a value from its domain and every constraint is satisfied.


Key Definitions


Constraint Types

By Arity

Type Involves Example
Unary 1 variable SA ≠ green
Binary 2 variables SA ≠ WA
Global (higher-order) ≥ 3 variables Alldiff(Q, NSW, V, SA)

By Hardness


The Constraint Graph

For binary CSPs, a constraint graph has: - Nodes: variables - Edges: binary constraints between pairs

    WA ── NT ── Q
    |  ╲  |  ╱  |
    SA   SA   SA
    |  ╱  |  ╲  |
    V  ── NSW ── T  (Tasmania is isolated)

The graph structure encodes independence and guides decomposition algorithms (tree-structured CSPs, cutset conditioning, tree decomposition).


Five Standard Examples

1. Map Coloring (Australia)

2. Cryptarithmetic (SEND + MORE = MONEY)

3. N-Queens

4. Sudoku

5. Job-Shop Scheduling


Why CSP Formulation is Powerful

Classical search treats a state as atomic. CSP formulation: 1. Enables inference — arc consistency, MAC prune domains before and during search 2. Enables smart ordering — MRV, degree heuristic exploit structure 3. Enables decomposition — tree-structured subproblems solvable in polynomial time 4. Generalizes — planning, scheduling, design configuration all map naturally to CSPs


Relation to Other AI Topics

CSP Idea Analogous Concept
Constraint propagation Unit propagation in SAT
Tree-structured CSP Variable elimination in Bayes nets
Min-conflicts GSAT / WalkSAT for SAT
Treewidth Treewidth in probabilistic inference