Arc Consistency
🎯 Learning Objectives
- Define node consistency and arc consistency
- Describe the AC-3 algorithm with its queue-based approach
- Analyse the time complexity O(cd³) of AC-3
- Understand path consistency and k-consistency
- Explain generalized arc consistency for non-binary constraints
- Trace an AC-3 worked example step by step
1. Node Consistency
📚 Node Consistency
A variable Xi is node-consistent if every value in its domain Di satisfies all unary constraints on Xi. A CSP is node-consistent if every variable is node-consistent.
✍ Example
If X1 has domain {R, G, B} and there is a unary constraint X1 ≠ G, we achieve node consistency by removing G from D1, giving D1 = {R, B}.
Node consistency is trivially achieved by pre-processing: scan all unary constraints and remove violating values. After this step, all remaining constraints are binary or higher.
2. Arc Consistency Definition
📚 Arc Consistency
A variable Xi is arc-consistent with respect to variable Xj if for every value v ∈ Di, there exists some value w ∈ Dj such that (v, w) satisfies the constraint between Xi and Xj.
Formally: ∀ v ∈ Di, ∃ w ∈ Dj : (v, w) ∈ Rij
A CSP is arc-consistent if every variable is arc-consistent with respect to every other variable it shares a constraint with.
💡 Direction Matters
Arc consistency is directional. The arc (Xi, Xj) being consistent means every value in Di has a support in Dj. But (Xj, Xi) might not be consistent — some value in Dj might lack a support in Di. Both directions must be checked.
⚠ Arc Consistency ≠ Solution
A CSP can be arc-consistent yet have no solution. For example, three variables X, Y, Z each with domain {R, B} and constraints X ≠ Y, Y ≠ Z, X ≠ Z is arc-consistent (each value has support) but has no valid complete assignment with only 2 colours for 3 mutually constrained variables.
3. AC-3 Algorithm
📚 AC-3 (Arc Consistency Algorithm #3)
AC-3 maintains a queue of arcs to process. It repeatedly dequeues an arc (Xi, Xj), removes unsupported values from Di, and if Di changed, enqueues all arcs (Xk, Xi) for each neighbour Xk ≠ Xj.
Algorithm: AC-3
function AC-3(csp) returns false if inconsistency found, true otherwise
queue ← {(Xi, Xj) : (Xi, Xj) ∈ arcs(csp)} // all arcs, both directions
while queue is not empty do
(Xi, Xj) ← DEQUEUE(queue)
if REVISE(csp, Xi, Xj) then
if |Di| = 0 then return false // domain wipe-out
for each Xk in NEIGHBOURS(Xi) − {Xj} do
ENQUEUE(queue, (Xk, Xi))
return true
function REVISE(csp, Xi, Xj) returns true iff we revise Di
revised ← false
for each v in Di do
if no w in Dj satisfies constraint(Xi, Xj) then
remove v from Di
revised ← true
return revised
📜 Time Complexity of AC-3
Let c = number of binary constraints (arcs in both directions = 2c), d = maximum domain size.
- Each arc (Xi, Xj) can be enqueued at most d times (once for each value deleted from Di or Dj)
- Each call to REVISE checks up to d × d = d² value pairs
- Total: O(c · d³) — where c is the number of constraints and d the max domain size
This is polynomial in the input size, making AC-3 efficient as a preprocessing step.
4. AC-3 Worked Example: Map Coloring
✍ Step-by-Step AC-3 on a Small Map
Consider three regions A, B, C with constraints A ≠ B, B ≠ C, A ≠ C.
Initial domains: DA = {R, G, B}, DB = {R, G}, DC = {R, G, B}
Initial queue: {(A,B), (B,A), (B,C), (C,B), (A,C), (C,A)}
Step 1: Process (A, B) — constraint: A ≠ B
- A=R: support B=G ✓
- A=G: support B=R ✓
- A=B: support B=R ✓
No change to DA. Move on.
Step 2: Process (B, A) — constraint: B ≠ A
- B=R: support A=G ✓
- B=G: support A=R ✓
No change to DB. Move on.
Step 3: Process (B, C) — constraint: B ≠ C
- B=R: support C=G ✓
- B=G: support C=R ✓
No change. Move on.
Step 4: Process (C, B) — constraint: C ≠ B
- C=R: support B=G ✓
- C=G: support B=R ✓
- C=B: need B ≠ B. B=R ✓ (R ≠ B)
No change. Move on.
Steps 5–6: Process (A,C) and (C,A) — similarly no changes.
Queue empty. Final domains: DA={R,G,B}, DB={R,G}, DC={R,G,B}. CSP is arc-consistent.
✍ AC-3 with Pruning
Now suppose DB = {R} initially (B is pre-assigned to Red).
Step 1: Process (A, B) — A ≠ B
- A=R: no w in DB={R} with R≠R → remove R from DA
- A=G: B=R and G≠R ✓
- A=B: B=R and B≠R ✓
DA changed to {G, B}. Enqueue (C, A).
Step 2: Process (C, B) — C ≠ B
- C=R: no support → remove R from DC
- C=G: B=R ✓
- C=B: B=R ✓
DC changed to {G, B}. Enqueue (A, C).
Steps 3+: Remaining arcs produce no further changes. Final: DA={G,B}, DB={R}, DC={G,B}.
5. Path Consistency
📚 Path Consistency
A pair of variables {Xi, Xj} is path-consistent with respect to a third variable Xm if for every assignment (Xi=a, Xj=b) that satisfies the constraint between Xi and Xj, there exists a value c ∈ Dm such that (a, c) satisfies the constraint between Xi and Xm and (b, c) satisfies the constraint between Xj and Xm.
Path consistency is strictly stronger than arc consistency. It considers triples of variables rather than pairs. The PC-2 algorithm enforces path consistency but is rarely used in practice due to high cost.
💡 When Path Consistency Helps
Remember the earlier example: X, Y, Z with domain {R, B} and all-different constraints. This is arc-consistent but has no solution. Path consistency would detect the inconsistency: for (X=R, Y=B), there is no valid Z (Z ≠ R and Z ≠ B is impossible with domain {R, B}).
6. k-Consistency
📚 k-Consistency
A CSP is k-consistent if for any consistent assignment to k−1 variables, there exists a consistent assignment for any k-th variable. Equivalently:
- 1-consistent = node consistent
- 2-consistent = arc consistent
- 3-consistent = path consistent
A CSP is strongly k-consistent if it is j-consistent for all j ≤ k.
📜 Strong n-Consistency ⇒ Backtrack-Free
If a CSP with n variables is strongly n-consistent, then a solution can be found without any backtracking — values can be assigned one variable at a time, and a valid value is always available. However, enforcing strong n-consistency can be as expensive as solving the CSP itself.
7. Generalized Arc Consistency
📚 Generalized Arc Consistency (GAC)
For a constraint C with scope (X1, …, Xk), a value v for variable Xi has generalized support if there exists a tuple (d1, …, dk) ∈ C such that di = v and dj ∈ Dj for all j. GAC removes all values lacking generalized support.
GAC is the natural extension of arc consistency to non-binary constraints. For global constraints like AllDiff, specialized GAC algorithms exist that are much more efficient than the generic approach. For instance, AllDiff can be made GAC using matching theory in O(n · d) time per invocation.
💡 GATE Tip
For GATE, focus on understanding AC-3 thoroughly: the queue-based algorithm, how REVISE works, and the O(cd³) complexity. Be able to trace AC-3 on small examples. Path consistency and k-consistency appear less frequently but understanding the hierarchy (1-consistent = node, 2-consistent = arc, 3-consistent = path) is useful.
Summary
- Node consistency: every value in Di satisfies all unary constraints on Xi.
- Arc consistency: every value in Di has a support in Dj for each constraint (Xi, Xj).
- AC-3 uses a queue of arcs; time complexity is O(cd³).
- Arc consistency does not guarantee a solution exists — it is a necessary but not sufficient condition.
- Path consistency (3-consistency) checks triples; k-consistency generalizes to k variables.
- Strong n-consistency eliminates backtracking but is expensive to enforce.
- GAC extends arc consistency to higher-arity constraints; specialized algorithms exist for global constraints.