Skip to content
StackDecode
AI & ML Atlas
Artificial IntelligencealgorithmInteractive simulation

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.

WANTQNSWVSAT
  • red
  • green
  • blue
  • arc being checked

Colour the map so neighbours differ. The small dots under each region are the colours still allowed.

1/11

Faded dots are colours that have been ruled out.

Step by step

  1. 1Put all arcs in a queue.
  2. 2Take an arc (X, Y); remove values from X that have no support in Y.
  3. 3If X lost values, add the arcs (Z, X) for its other neighbours back to the queue.
  4. 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.

Related