AC-3 2026-10-25
An arc consistency algorithm maintaining a work list of directed constrained variable pairs. Revising deletes each value of with no compatible value in . If shrinks, incoming arcs are reconsidered; the just-used neighbor need not be included, since deleted values had no support in and hence supported no surviving value there. Initially empty constraint domains are rejected before processing.
Each deletion preserves every complete solution: a solution using the removed value would supply its missing support. Therefore an empty constraint domain certifies impossibility. Successful termination establishes arc consistency but need not establish satisfiability. A triangle of two-valued inequality constraints supplies a counterexample: all values have pairwise support, but no assignment can satisfy all three inequalities.
For variables, constrained pairs and maximum constraint domain size , assume constant-time compatibility tests for combined pair relations. A revision costs , and each shrinking source constraint domain can cause at most rounds of reconsideration of its incoming arcs. Thus there are revisions and time complexity . Fixed , including two-valued constraint domains, gives linear time in .
Arc-consistency closure 2026-10-25
The greatest componentwise subdomains of given finite initial constraint domains satisfying every directed arc consistency condition, allowing empty subdomains. Repeated sound revisions to a fixed point produce this same closure regardless of revision order, provided every affected arc is eventually reconsidered.
For the proof, fix subdomains of the initial satisfying arc consistency. If all current contain , every value in has a support in , so revising preserves . Mathematical induction shows that every revision preserves every such family . At termination the current domains themselves satisfy arc consistency, so they are the greatest such family. Algorithms that stop immediately on the first empty constraint domain need not finish computing the closure, but correctly establish that no complete solution exists.
Backtracking leaf bound 2026-10-24
Suppose backtracking assigns each of finitely many variables once along each branch, branching only on distinct values in its initial nonempty constraint domain . Then the number of leaves is at most , even if inconsistent partial assignments terminate early. Ignore constraints and associate a leaf with every full domain assignment extending its partial assignment. Each leaf has at least one such extension. Different leaves have disjoint extension families: at their first diverging choice they assigned different values to the same selected variable. These nonempty disjoint families lie in a Cartesian product of cardinality , proving the bound. The selected next variable can depend on the preceding assignments, provided each full assignment follows a unique branch.
The bound is exact for an unpruned enumeration tree, but need not be attained when actual constraints cause search pruning. Counting complete satisfying assignments alone also does not count failed partial leaves.
Constraint domain 2026-10-25
The set of values permitted for a variable in a constraint satisfaction problem. All assignments before relational constraints form the Cartesian product , whose cardinality is for finite domains. Unary restrictions can be incorporated directly into the constraint domain by deleting forbidden values.
Constraint graph 2026-10-25
For a binary constraint satisfaction problem, the undirected graph with one vertex per variable and an edge for each variable pair sharing a binary constraint. Unary conditions restrict constraint domains but add no edges. A more general constraint can be represented in a primal constraint graph by joining every pair of variables in its scope; such edges do not make a genuinely many-variable constraint binary.
After restricting constraint domains, a binary constraint can become automatically satisfied for every remaining pair of values. Removing such constraints can reveal a tree and enable tree-structured constraint satisfaction.
Official course-hosted technical exposition: 2.4 Ordering.
Relevant locators: §2.4, Minimum Remaining Values; §2.4.1, Structure, the upward support pass, downward assignment and cutset conditioning. The residual tree computation is linear in the number of variables for fixed maximum constraint domain size.
Cutset conditioning 2026-10-25
Enumerate assignments to a cycle cutset, reject internal violations, filter all crossing binary constraints, and solve the residual forest by tree-structured constraint satisfaction. A full solution restricts to one enumerated cutset assignment; the residual tree passes preserve all its values. Conversely, a consistent cutset assignment combined with supported residual solutions satisfies every constraint. These observations prove completeness and soundness.
With variables, maximum constraint domain size and cutset size , there are at most assignments and residual tree work per assignment. Internal cutset and crossing-constraint tests require additional accounting. The method is attractive when a small cycle cutset is available.[ref]
Cycle cutset 2026-10-25
A set of vertices whose deletion leaves a forest. For a binary constraint satisfaction problem, fixing these variables and filtering the remaining constraint domains leaves independent instances of tree-structured constraint satisfaction. A valid cutset need not be minimum; smaller cutsets reduce the exponential enumeration in cutset conditioning.
Represent each original value choice by a Boolean variable and impose an exactly-one constraint for each original variable. For every forbidden tuple of a constraint with scope , add the Boolean clause . A complete original assignment satisfies every constraint exactly when its one-hot indicators satisfy all these Boolean clauses: each forbidden-tuple Boolean clause excludes precisely that joint choice. A satisfying assignment decodes by reading the unique true indicator for each original variable.
For constraint domain sizes , pairwise uniqueness requires Boolean clauses. If a constraint has forbidden tuples and arity , its contribution is Boolean clauses and literal occurrences. Thus bounded arity gives a polynomial-size encoding in explicitly listed domains, whereas enumerating a succinct high-arity relation can be exponential in its description length. Unit propagation on this encoding can be weaker than arc consistency on the original binary constraints.
Full-sweep arc consistency 2026-10-25
Compute an arc-consistency closure by revising every directed constrained pair in complete sweeps until one sweep deletes nothing. The first sweep is unconditional. With variables, maximum constraint domain size , and constrained pairs, at most deletions permit at most sweeps. At per revision plus per emptiness scan, a direct time complexity bound is . AC-3 uses a work list to avoid scanning unrelated arcs after each local change.
Hill climbing 2026-10-25
A local search method that retains one current candidate and repeatedly chooses an improving neighbor of its objective. For a conflict-minimization constraint satisfaction problem, a candidate can assign all variables within their constraint domains while violating some inter-variable constraints; the objective counts those violations. Zero conflicts certifies a solution, while a positive-conflict local minimum need not certify impossibility. Plateaus and local minima motivate sideways moves, randomized choices and restarting. Prescribed variables must remain fixed in every initialization and move.
Nonattacking knights problem 2026-10-25
Choose distinct squares of an chessboard so that no chosen pair has absolute coordinate differences or . One constraint satisfaction problem representation has square-valued variables, requiring distinctness and pairwise nonattack. Another has one Boolean variable per square, a cardinality constraint fixing their sum to , and one mutual-exclusion constraint for every edge of the knight attack graph. The first has fewer variables when is small but represents each unlabelled placement up to times; the second uses only binary constraint domains and sparse local attack restrictions.
No-waste allocation 2026-10-24
For nonnegative additive valuations, the requirement that each allocated item be assigned to an agent who values it strictly positively. This condition alone does not require allocating every item.
Let and restrict agent 's constraint domain to subsets of , or to nonempty subsets when required. If , the two bundles are automatically disjoint and each agent values the other's bundle at zero. Both directional envy-free allocation binary constraints are then automatic. Thus positive-support overlaps determine which pairs can still matter in the residual constraint graph.
One variable per knight. Use , with each constraint domain equal to . For every pair , requireEvery satisfying assignment places distinct nonattacking knights, and any such placement gives an assignment after labelling its knights. This has only variables and binary constraints, but domains of size . Relabelling the knights gives assignments for the same unlabelled board, so the representation contains considerable redundancy.
One Boolean variable per square. Use for every . Impose the cardinality constraintand for every knight-attack pair impose . There are variables, each with a two-element constraint domain, and only local attack restrictions, because each square attacks at most eight others. The single counting constraint is a global constraint, not a binary constraint.
The square encoding avoids knight-label redundancy and has sparse local attack relations; the knight encoding uses fewer variables when is small and makes single-knight moves natural. Both are exact representations of the nonattacking knights problem. Neither may impose one knight per row: several knights can legally share a row.
Backtracking assigns one variable at a time and abandons a partial assignment as soon as it cannot extend to a solution. With forward checking, placing a knight deletes its occupied and attacked squares from every remaining knight's constraint domain. An empty constraint domain rejects the branch immediately; stronger constraint propagation, such as arc consistency, can detect additional incompatibilities among future choices.
This combines early rejection with depth-first storage. It retains the current assignment and domain changes rather than the entire breadth-first layer of partial placements. A direct knight-variable implementation uses space for explicit domains, plus its assignment and restoration trail, instead of an exponentially large breadth-first search search frontier. Propagation has a computational cost and does not guarantee improvement on every input, but often prevents exploration of vast inconsistent subtrees.
The minimum remaining values heuristic selects an unassigned variable with the fewest currently legal values, exposing the likeliest failure first. The degree heuristic selects a variable constrained to the largest number of other unassigned variables, often breaking minimum remaining values heuristic ties. Degree is measured in the remaining constraint graph, not by counting assigned neighbors. In the symmetric knight-variable encoding the remaining degrees can all tie, so the heuristic need not discriminate there.[ref]
CS 188 constraint ordering and structure notes. §2.4, Minimum Remaining Values: choose an unassigned variable with the fewest valid remaining values
For a finite constraint satisfaction problem, remove values violating unary restrictions before starting. The following backtracking algorithm makes independent copies of constraint domains at each branch, so failed forward checking cannot contaminate a sibling branch.
SOLVE(P):
D := domains of P after unary filtering
if some D[X] is empty: return failure
return SEARCH({}, D)
SEARCH(assignment, D):
if every variable is assigned: return assignment
X := SELECT-UNASSIGNED-VARIABLE(assignment, D, P)
for v in ORDER-DOMAIN-VALUES(X, assignment, D, P):
if X=v is compatible with the current assignment:
next_assignment := assignment extended by X=v
next_domains := a deep copy of D
next_domains[X] := {v}
if INFERENCES(X, v, next_assignment, next_domains, P) succeeds:
result := SEARCH(next_assignment, next_domains)
if result is not failure: return result
return failureSELECT-UNASSIGNED-VARIABLE implements minimum remaining values: choose an unassigned variable with the smallest current constraint domain. Break ties by the degree heuristic, choosing the variable constrained to the greatest number of other unassigned variables; a fixed final tie rule makes execution reproducible. ORDER-DOMAIN-VALUES may use any complete ordering; ascending values suffice here.
INFERENCES implements forward checking: for each unassigned neighbor of , remove every value incompatible with , and fail if any constraint domain becomes empty. For higher-arity constraints, reject any completely instantiated violation and use a sound chosen filtering rule; the stated neighbor test is the usual binary case. Forward checking never removes a value used by a possible extension of the current assignment. Exhausting every surviving value therefore makes this finite backtracking procedure both sound and complete.[ref]
CS 188 constraint filtering notes. §2.3, opening paragraphs: filtering neighbors after assignment
[ref]Forward checking makes minimum remaining values respond to current restrictions rather than the original constraint domain sizes. After , its neighbors may have fewer choices, become forced or lose all choices. Minimum remaining values then selects the newly constrained variable early, while an empty constraint domain triggers immediate failure. The two mechanisms expose failure sooner and reduce wasted backtracking.
Forward checking only tests an unassigned neighbor against the newly assigned value. It need not check whether two still-unassigned variables have mutually supporting values. Arc consistency requires every value at either end of each binary constraint to have support in the other constraint domain, and AC-3 propagates deletions until this condition stabilizes or a constraint domain becomes empty.[ref]
For example, let initially have constraint domains with constraints and . Assigning makes forward checking reduce to , but leaves . Arc consistency also deletes from , leaving . Neither procedure alone decides every general constraint satisfaction problem: a triangle of two-valued inequalities satisfies arc consistency but is unsatisfiable.
One solution is . Use ascending value order; after minimum remaining values and the degree heuristic, break any remaining variable tie alphabetically. Apply the unary restrictions first:
Minimum remaining values selects , even though has greater initial vertex degree. Set . Forward checking removes from the three neighbors :Now is the unique minimum remaining values choice. Set . Forward checking removes from , givingSelect and set . Its remaining neighbors are , so forward checking givesThe two remaining variables tie on constraint domain size and each has one unassigned neighbor, so the degree heuristic also ties. Alphabetical order selects ; take . Since is already absent from , forward checking makes no further deletion. Finally choose . No empty constraint domain or violation occurs, so this branch needs no backtracking.
All eight binary constraints are checked explicitly by the unequal value pairsThe unary restrictions also hold. Equalities and are permitted because those pairs have no edges in the constraint graph.
Cutset conditioning selects a cycle cutset : deleting its vertices makes the binary constraint graph a forest. Enumerate assignments to , reject those violating internal constraints, and filter each remaining constraint domain against the chosen cutset values. Solve the residual components by tree-structured constraint satisfaction. Stop at a successful assignment, or report failure after all cutset assignments fail. Completeness follows by considering the restriction of any full solution to ; soundness follows by checking internal, crossing and residual constraints. With maximum constraint domain size and cutset variables, a typical bound is for the residual forest work, with cutset and crossing checks added explicitly.[ref]
Here take . The residual constraint graph has vertices and only edges , a tree rooted at . Choose the consistent cutset values . Filtering against these assignments givesThe upward support pass from deletes , because can only equal . The pass from retains , which has support or . Assign at the root and then supported child values . Together with , this gives the solution in (c).
No singleton cycle cutset exists: deleting or leaves, respectively, a triangle on or ; deleting leaves the cycle in a graph . Thus the two-element choice is also minimum, although the algorithm only requires a valid cutset.
Use an exactly-one constraint for each finite-domain variable and a Boolean clause forbidding each disallowed constraint tuple. Let the variables be , with explicitly listed finite constraint domains , and let constraint have distinct-variable scope and allowed relation . Introduce a Boolean variable for every , interpreted as . The direct SAT encoding of finite-domain constraints isIn the middle logical conjunction, each unordered distinct pair is included once. The first Boolean clause requires at least one value, the pairwise Boolean clauses permit at most one, and a final Boolean clause is false exactly when all coordinates of one forbidden tuple are selected. The formula is in conjunctive normal form. An empty constraint domain produces an empty Boolean clause, correctly making the instance unsatisfiable.
For soundness of the reduction, a solution of the constraint satisfaction problem gives the Boolean valuation exactly when . Every exactly-one constraint holds; a forbidden tuple differs from on at least one scoped coordinate, making its negative Boolean clause true. Thus supplies a satisfying assignment for .
Conversely, a satisfying assignment selects a unique value for every . If a constraint failed, the selected scoped tuple would belong to , and its entire negative Boolean clause would be false. That contradicts satisfiability. Hence is a solution. Decoding takes by scanning the value indicators. This proves has a solution if and only if is satisfiable.
For explicit size accounting, put , and . There are Boolean variables,Boolean clauses, andliteral occurrences. These formulas count nonempty scopes; a false zero-arity constraint contributes an empty Boolean clause, while a true one contributes none. Formula storage is literal-sized records; a bit-level encoding also stores indicator indices. With maximum constraint domain size , constraints and maximum arity , this is bounded by for nontrivial domains and scopes. In the common binary case it is .
The input representation matters: listing all forbidden tuples costs up to tests per constraint. This is polynomial for bounded arity and explicitly represented domains, but can be exponential in the description length of a succinct high-arity constraint. The translation is valid in that case without constituting a polynomial-size reduction. If a compact constraint is supplied as a polynomial-size Boolean circuit, one may instead encode that circuit using auxiliary Boolean variables and local conjunctive normal form equivalences, with size proportional to the circuit. No compact representation is silently assumed.
For the instance in (c), after unary filtering there are indicators. The five at-least-one Boolean clauses, pairwise at-most-one Boolean clauses and forbidden-equality Boolean clauses give Boolean clauses. Setting only true encodes the displayed solution.