Arc Consistency (AC-3)
Repeatedly prunes values that have no compatible partner in a neighbouring variable.
The idea
An arc X→Y is consistent if every value of X has at least one allowed value in Y. AC-3 keeps a queue of arcs; whenever it deletes a value from X, it re-queues the arcs that point to X, because they may now be inconsistent. It can solve some puzzles outright, and it shrinks the search for the rest.
O(e·d³) time
Watch it run
This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.
- red
- green
- blue
- arc being checked
Colour the map so neighbours differ. The small dots under each region are the colours still allowed.
Faded dots are colours that have been ruled out.
Step by step
- 1Put all arcs in a queue.
- 2Take an arc (X, Y); remove values from X that have no support in Y.
- 3If X lost values, add the arcs (Z, X) for its other neighbours back to the queue.
- 4If any domain becomes empty, there is no solution; otherwise continue until the queue is empty.
Where it is used
Preprocessing for Sudoku and scheduling solvers.
Watch out for
Arc consistency alone does not guarantee a solution; it only removes impossible values.