Back to CSP Lecture

Arc Consistency Algorithm Demonstration

Learn how AC-3 reduces domains and detects inconsistencies before search

Learning Objectives

πŸ” Domain Reduction: Watch how arc consistency eliminates impossible values
πŸ“‹ Queue Processing: Understand why and when arcs are added to the processing queue
⚑ Search Benefit: See how AC-3 preprocessing reduces backtracking effort

Example 1: Simple Triangle Map - Arc Consistency Success

Watch AC-3 reduce domains in a 3-region map with only 2 colors available

πŸ—ΊοΈ Relation to Map Coloring
Map Coloring CSP Setup:
  • πŸ›οΈ Variables: A, B, C (three regions)
  • 🎨 Domain: {Red, Blue} for each region
  • πŸ”— Constraints: Adjacent regions must have different colors
  • πŸ“ Graph: Path A-B-C - only adjacent regions connected

Graph edges mean: "Adjacent regions must have different colors"
Example: If A and B are neighbors β†’ A β‰  B

πŸ”„ Why Arc Consistency (AC-3)?

Arc Consistency ensures that:

πŸ‘‰ For every value in one variable's domain, there must be a consistent value in the neighbor's domain.

For each arc (like A β†’ B):

  • If A = Red, then B must have at least one value β‰  Red
  • If no such value exists in B, we remove Red from A's domain
  • This reduces search space before backtracking begins!
Arc Consistency AC-3 Visualization

Triangle graph: 3 regions (A-B-C) all connected, with domains {Red, Blue} each

A
R
B
B
R
B
C
R
B
Arc Processing Queue
A→B B→A A→C C→A B→C C→B
Arc Consistency Log

Step-by-step AC-3 algorithm execution and domain updates

Ready to start AC-3 algorithm - observe domain reduction!
AC-3 State
Current Arc: None
Queue Size: 6
Phase: Initialize
Statistics
0
Arcs Processed
0
Values Eliminated
0
Iterations
AC-3 Algorithm
Arc Consistency Process:
  1. Initialize: Add all arcs to queue
  2. Process Arc: Remove arc (X,Y) from queue
  3. Check Values: For each value in X's domain
  4. Find Support: Check if value has support in Y
  5. Eliminate: Remove unsupported values from X
  6. Propagate: If X changed, add arcs (Z,X) to queue

Goal: Make every arc consistent
Benefit: Reduces search space before backtracking

πŸ’‘ The Challenge: Solving the Same Path CSP
🎯 Same Problem:
  • 3 regions A-B-C in a line (path graph)
  • A↔B connected, B↔C connected
  • A and C are NOT connected
  • Domains: {Red, Blue} for each region
❌ WITHOUT AC-3:
  • Start with full domains
  • Discover conflicts during search
  • Many dead-end paths
βœ… WITH AC-3:
  • Reduce domains first
  • Eliminate impossible values
  • Smarter search decisions
WITHOUT AC-3 Preprocessing

Pure backtracking with full domains {Red, Blue}

Search Tree Progress
Root
A:{R,B} B:{R,B} C:{R,B}
Current Assignment
A: ? B: ? C: ?
0
Nodes Explored
0
Backtracks
0
Conflicts Found
Search Log (Without AC-3)
Ready to start backtracking WITHOUT arc consistency...
WITH AC-3 Preprocessing

AC-3 first, then backtracking with reduced domains

Search Tree Progress
Root (AC-3)
A:{R,B} B:{R,B} C:{R,B}
Current Assignment
A: ? B: ? C: ?
0
Nodes Explored
0
Backtracks
0
Conflicts Found
Search Log (With AC-3)
Ready to start AC-3 preprocessing followed by backtracking...
πŸ“Š Performance Comparison
Nodes Explored
- vs -
Backtracks
- vs -
Conflicts Found
- vs -
Efficiency Gain
Run both to see!
🚨 Impossible CSP: Conflicting Pre-assignments
⚠️ Setup for Failure:
  • Triangle Graph: A↔B↔C↔A (all connected)
  • Pre-assigned Values: A=Red, B=Red
  • Constraint: Adjacent regions β‰  same color
  • Result: A=Red β‰  B=Red violated!
Why impossible: A and B are both forced to be Red, but A↔B constraint requires Aβ‰ B!
βœ… AC-3 Early Detection:
  • Smart Preprocessing: Detects impossibility quickly
  • Domain Reduction: Eliminates values systematically
  • Empty Domain: Proves no solution exists
  • Saves Time: No wasted backtracking!
AC-3 Benefit: Discovers impossibility in preprocessing phase, avoiding futile search!
AC-3 Failure Detection

Watch AC-3 systematically prove this CSP has no solution

Triangle Constraint Graph
A
R
B
B
R
B
C
R
B
Arc Processing Queue
A→B B→A A→C C→A B→C C→B
AC-3 Failure Detection Log

Watch AC-3 systematically discover the impossibility

Ready to demonstrate early failure detection with AC-3!
AC-3 State
Current Arc: None
Queue Size: 6
Phase: Initialize
Status: Ready
Detection Stats
0
Arcs Processed
0
Values Eliminated
0
Empty Domains
Early Detection Benefits
Without AC-3 Preprocessing:
  • Exhaustive backtracking search
  • Try all combinations: A=Red,B=Blue,C=?
  • Discover conflicts during search
  • Wasted computation time
With AC-3 Preprocessing:
  • Domain Analysis: Systematic constraint propagation
  • Empty Domain: Immediate failure detection
  • Proof of Impossibility: No search needed
  • Time Saved: Avoid futile backtracking
πŸ“ Mathematical Background
Constraint Logic:
  • Pre-assignment: A=Red, B=Red
  • Adjacent Constraint: Aβ‰ B
  • Logical Contradiction: Red β‰  Red is FALSE
  • Result: No solution possible
Constraint Analysis:
  • 6 Binary Arcs: Aβ†’B, Bβ†’A, Aβ†’C, Cβ†’A, Bβ†’C, Cβ†’B
  • Critical Arc Aβ†’B: A=Red needs Bβ‰ Red
  • But B Domain: B={Red} only
  • No Support: A=Red has no valid B value
AC-3 Discovery:
  • Propagation: Eliminates inconsistent values
  • Domain Reduction: Systematically shrinks domains
  • Empty Domain: Proves impossibility
  • Early Termination: No search required