Constraint Programming

Decision Sciences
Introduced by
Rossi, van Beek & Walsh
Year
2006
Type
Declarative combinatorial optimization
Family
Mathematical programming

What does it do?

Constraint Programming (CP) is a declarative optimization paradigm in which a problem is stated as a set of variables with finite domains and a set of constraints, and a solver searches for assignments that satisfy all of them.

Its core mechanism combines constraint propagation, which removes domain values that cannot appear in any solution, with systematic backtracking search. CP is widely applied to combinatorial problems in scheduling, planning, and configuration; the 2006 Handbook of Constraint Programming, edited by Rossi, van Beek, and Walsh, is a standard reference on the field. CP is classed under mathematical programming in this taxonomy, but its paradigm, constraint propagation combined with search, differs from the linear and mixed-integer methods it is often compared with.

The intuition behind the method

Think of CP as filling in a complex puzzle: each cell is a variable with a set of legal values, and every rule of the puzzle is a constraint. Rather than guessing blindly, CP uses the rules to immediately eliminate impossible values from neighboring cells whenever one cell is filled in. This propagation shrinks the search space dramatically, so the solver explores only plausible combinations — backtracking and revising only when it reaches a dead end.

History

Constraint Programming grew out of artificial intelligence research on constraint satisfaction, which dates back to the 1970s. The field matured through the 1980s and 1990s, with the development of arc consistency algorithms, global constraints, and practical solver implementations. The 2006 Handbook of Constraint Programming, edited by Rossi, van Beek, and Walsh, gives a consolidated treatment of theory, algorithms, and applications.

When to use it

Choose Constraint Programming for combinatorial problems over discrete or enumerable variable domains, especially when the model contains many heterogeneous constraints such as logical rules, precedence relations, and global constraints like alldifferent or cumulative. It suits scheduling, timetabling, configuration, and routing tasks where finding a feasible assignment is as important as optimizing the objective. For timetabling in particular, constraint-based models are generally computationally demanding and are often most successful when combined with other approaches, such as sequential heuristics or metaheuristics. Do not choose CP for continuous optimization or for large linear models, where Linear Programming or Mixed-Integer Programming solvers are usually the more natural fit. If the constraints offer little structure for propagation to exploit, or if a good solution is needed quickly and proof of optimality is not required, a metaheuristic may be more practical.

Limitations and considerations

  • Scalability: worst-case exponential search makes CP slow on very large instances with weak propagation.
  • Requires good modeling: poor variable/value ordering heuristics or missing global constraints lead to unnecessarily large search trees.
  • Continuous domains: CP is natively designed for discrete domains; continuous problems require specialized extensions or hybrid approaches.
  • Solver expertise: effective use demands familiarity with constraint modeling techniques and solver-specific global constraint libraries.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Declarative modeling: complex real-world rules are stated directly as constraints, without writing the search procedure by hand.
  • Early pruning: constraint propagation removes infeasible domain values before search reaches them, which can substantially reduce the search compared with enumerating all assignments.
  • Handles heterogeneous constraints: logical, arithmetic, global, and user-defined constraints can coexist in a single model.
  • Complete search: given enough run time, the solver either finds an optimal solution or shows that no feasible solution exists; stopping early under a time limit gives up this guarantee (see limitations).

Applications

  • Employee and nurse scheduling: assigning staff to shifts while satisfying availability, labor law, and skill constraints.
  • Timetabling: constructing university or school timetables subject to room capacity, instructor availability, and curriculum constraints.
  • Configuration: assembling product configurations (computers, vehicles) from component catalogs under compatibility and resource constraints.
  • Vehicle routing and logistics: planning delivery routes subject to time windows, vehicle capacities, and driver regulations.
  • Combinatorial auctions and resource allocation: assigning resources to bidders or tasks under exclusivity and budget constraints.

How it works

How it works

1

The problem is encoded as a Constraint Satisfaction Problem triple consisting of variables X, their finite domains D, and a set of constraints C. Each variable x_i can be assigned any value from its domain D_i. Constraints define permissible combinations of values across subsets of variables, translating real-world rules — capacity limits, precedence relations, resource conflicts — into a mathematical structure the solver can reason over. The standard formulation assumes finite, enumerable domains; in examination and timetabling models, for instance, variables are typically times and rooms, each taking one of a finite set of values. Solver performance depends on the strength of propagation and on the search ordering, not only on the number of variables and constraints.

Formula
\text{CSP} = \langle X, D, C \rangle \quad X = \{x_1, x_2, \ldots, x_n\},\; D = \{D_1, D_2, \ldots, D_n\}
2

Before and during search, the solver applies arc consistency and other local-consistency algorithms to prune domain values that cannot participate in any valid solution. For every pair of constrained variables, arc consistency removes values from one variable's domain for which no supporting value exists in the other's domain. This propagation is triggered repeatedly after each assignment, drastically reducing the effective search space.

Formula
\text{AC}(x_i, x_j): \forall a \in D_i,\; \exists b \in D_j \text{ s.t. } c_{ij}(a, b) \text{ holds}
3

The solver selects an unassigned variable — typically using heuristics such as minimum remaining values or degree — and tentatively assigns it a value from its pruned domain. Propagation runs again; if a contradiction is detected (an empty domain), the solver backtracks to the most recent choice point and tries an alternative value. Backjumping and nogood recording can further accelerate recovery from failures.

Formula
x_i \leftarrow a_i \in D_i,\quad \text{propagate},\quad \text{if fail: backtrack and reassign}
4

When all variables have been assigned values consistent with every constraint, the complete assignment S* constitutes a solution. For optimization problems, an objective function guides search toward the best feasible solution, and branch-and-bound strategies progressively tighten the bound as better solutions are found, until the global optimum is certified or a time limit is reached. Reading the outcome correctly matters. If the search space is exhausted without a solution, the model is proven infeasible. A run stopped by a time limit that returns a solution gives a feasible solution, which is guaranteed optimal only if the bound search completed. A time-limited run that returns no solution is inconclusive: it proves neither feasibility nor infeasibility.

Formula
S^* = \{(x_1, a_1^*), \ldots, (x_n, a_n^*)\} : \forall c \in C,\; c(a_1^*, \ldots, a_n^*) = \text{true}

Common pitfalls

  • Conflicting constraints make a model infeasible, and the solver then correctly reports no solution; a modeling error that adds a constraint contradicting the intended rules produces this result even though the real problem is feasible. Redundant constraints do not change the set of solutions, but they can change how much propagation prunes, so they should be checked for both correctness and effect.
  • Neglecting global constraints (e.g., alldifferent, cumulative) misses propagation opportunities that specialized algorithms provide for free.
  • Ignoring search heuristics and relying on default variable/value ordering can waste exponential time on pathological orderings.
  • Confusing constraint satisfaction with optimization: forgetting to add an objective function and bound-tightening yields only the first feasible solution, not the best one.

Frequently asked questions

How does Constraint Programming differ from Integer Linear Programming?

While both solve combinatorial problems, ILP requires all constraints and objectives to be linear, enabling efficient LP-relaxation bounds. CP imposes no such linearity requirement and instead relies on constraint propagation and systematic search. CP handles complex logical and global constraints more naturally, whereas ILP often scales better on problems with strong linear structure and large variable counts.

What are global constraints and why do they matter?

Global constraints are high-level constraints over arbitrary numbers of variables — for example, alldifferent (all variables take distinct values) or cumulative (resource usage at any time does not exceed capacity). They matter because solvers implement dedicated, highly efficient propagation algorithms for each, achieving far stronger pruning than decomposing the same condition into many binary constraints, which would leave much of the search space unexplored.

Can Constraint Programming find optimal solutions, or only feasible ones?

CP can find optimal solutions by combining feasibility search with an objective function. The solver uses branch-and-bound: once a feasible solution is found, it adds a constraint requiring any subsequent solution to be strictly better, continuing until no improvement is possible. This certifies optimality. If runtime is limited, the best solution found so far is returned as an approximation.

Related methods

Sources

  1. Rossi, F., van Beek, P., & Walsh, T. (Eds.). (2006). Handbook of Constraint Programming. Elsevier.

    ISBN: 978-0-444-52726-4
  2. 01_a1de2edf7f9cc4615168f0f0264becdaffa06b77, p. 15