Backtracking Search with Propagation

Solving a CSP by combining depth-first backtracking with constraint propagation (typically arc consistency) at every node, including variable selection via the fail-first / MRV heuristic and failure detection via domain wipeout.

Step 1 of 157%

Tutorial

Backtracking Search with Propagation

Solving a CSP means assigning a value to every variable so that all constraints are satisfied. Backtracking search does this by assigning variables one at a time and recursing, undoing the assignment when a constraint is violated. Plain backtracking is slow because it discovers conflicts only after committing to an assignment that propagation could have ruled out in advance.

Backtracking search with propagation interleaves the two. After every assignment we enforce arc consistency on the remaining domains. If propagation empties any domain, the current branch is a dead end and we backtrack immediately. The classic variant that re-establishes AC after each branch is called MAC (Maintaining Arc Consistency).

The algorithm is:

  1. Enforce arc consistency on the current domains.
  2. If some domain is empty, return failure.
  3. If every variable's domain is a singleton, return the assignment.
  4. Choose an unfixed variable XX.
  5. For each value vdom(X)v \in \mathrm{dom}(X):
    • Save the current domains.
    • Set dom(X){v}\mathrm{dom}(X) \leftarrow \{v\} and recurse.
    • If the recursion returns a solution, return it.
    • Otherwise restore the saved domains and try the next vv.
  6. If every value has failed, return failure.

Tiny illustration. Variables X,Y{1,2,3}X, Y \in \{1, 2, 3\} with X<YX < Y. Initial AC reduces the domains to X{1,2}X \in \{1,2\} and Y{2,3}Y \in \{2,3\}. Branch X=1X=1; propagation leaves Y{2,3}Y \in \{2,3\}. Branch Y=2Y=2; both domains are singletons. Solution (X,Y)=(1,2)(X,Y)=(1,2).

navigate · Enter open · Esc close · ⌘K/Ctrl K toggle