Lecture 16 - CSPs IV
Lecture 16 - CSPs IV
AI2002 – Artificial
Intelligence
Lecture # 16
March 21, 2024
Spring 2024 Dr. Rabia Maqsood
FAST – NUCES, CFD Campus rabia.maqsood@nu.edu.pk
Today’s topics 2
NT Q
WA
SA
NSW
V
NT Q
WA
SA
NSW
V
NT Q
WA
SA
NSW
V
• Arc V to NSW is consistent: for every x in the tail there is some y in the head which
could be assigned without violating a constraint
NT Q
WA
SA
NSW
V
• Arc SA to NSW is consistent: for every x in the tail there is some y in the head
which could be assigned without violating a constraint
NT Q
WA
SA
NSW
V
Consistent or not?
NT Q
WA
SA
NSW
V
• Remember that arc V to NSW was consistent, when NSW had red and blue in
its domain
• After removing blue from NSW, this arc might not be consistent anymore! We need
to recheck this arc.
• Important: If X loses a value, neighbors of X need to be rechecked!
AI2002 - Spring 2024
Arc Consistency of an Entire CSP (5/6) 9
• A simple form of propagation makes sure all arcs are consistent:
NT Q
WA
SA
NSW
V
• Arc SA to NT is inconsistent.
• We make it consistent by deleting from the tail (SA = blue).
NT Q
WA
SA
NSW
V
• SA has an empty domain, so we detect failure. There is no way to solve this CSP
with WA = red and Q = green, so we backtrack.
• Arc consistency detects failure earlier than forward checking
An arc <x, r(x,y)> is arc consistent iff for each value of x in D(X)
there is some value y in D(Y) such that the binary constraint
r(x,y) on x and y is satisfied.
A graph is arc consistent if all its arcs are arc consistent.
A B
1,2,3 A< B 2,3
Z2 c2 X c Y
E
S
Z3 c3 c4 A
AI2002 - Spring 2024 E
Which arcs need to be reconsidered? 14
You do not need to reconsider other arcs
• If arc 〈Y,c〉was arc consistent before, it will still be arc consistent
“Consistent before” means each element yi in Y must have an element xi in X that
satisfies the constraint. Those xi would not be pruned from D(X), so arc 〈Y,c〉stays
consistent
• If an arc 〈X,ci〉was arc consistent before, it will still be arc consistent
The domains of Zi have not been touched
• Nothing changes for arcs of constraints not involving X
Z1 T
c1
H
Z2 c2 X c Y
E
S
AI2002 - Spring 2024 Z3 c3 c4 A
E
Arc Consistency Algorithm 15
Forward Checking
as before
• So far, we have selected the next variable and the next value by
using a fixed order
• Ordering:
• Which variable should be assigned next?
• In what order should its values be tried?
• In general
• ‘heuristic’ means ‘serves to discover’
• Variable ordering
• Minimum Remaining Value (MRV)
• Degree Heuristic (DH)
• Value ordering
• Least Constraining Value (LCV)
• DH: At each step, choose the variable with the maximum degree,
i.e., the one which has maximum no. of constraints with the
remaining variables
2 constraints
Initially, we color this: degree = 5
3 constraints
(variable with max degree)
• Given a variable, choose its LCV: the one that rules out the
fewest values in the remaining variables
• The one that imposes minimum constraints on the remaining variables
SA
SA can’t be assigned
any color now
• AIMA: Chapter # 6