0% found this document useful (0 votes)
10 views

Lecture 16 - CSPs IV

Uploaded by

fageyib324
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lecture 16 - CSPs IV

Uploaded by

fageyib324
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Lecture slides adapted from AIMA & EECS UC, Berkeley

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

• Constraint Satisfaction Problem (CSP)


• Solving CSPs
• Filtering: Constraint propagation
• Arc consistency & AC-3 algorithm

• Heuristics: MRV, DH, LCV

AI2002 - Spring 2024


Filtering: Constraint Propagation 3

• Limitations of simple forward checking: propagates information from assigned to


unassigned variables, but doesn't provide early detection for all failures:
• NT and SA cannot both be blue!
• Why didn’t we detect this yet?

NT Q
WA
SA
NSW
V

• Constraint propagation: reason from constraint to constraint


AI2002 - Spring 2024
Consistency of A Single Arc 4
• An arc X à Y is consistent iff 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

• Tail = NT, head = WA


• If NT = blue: we could assign WA = red How is this different from forward checking?
• If NT = green: we could assign WA = red
• If NT = red: there is no remaining assignment to WA that we can use
• Deleting NT = red from the tail makes this arc consistent
Forward
•AI2002 checking: Only enforce consistency of arcs pointing to each new assignment
- Spring 2024

• 𝑋 → 𝑌, ∀ 𝑋, 𝑌 ∈ 𝐸 and 𝑌 newly assigned


Arc Consistency of an Entire CSP (1/6) 5
• A simple form of propagation makes sure all arcs are consistent:

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

AI2002 - Spring 2024


Arc Consistency of an Entire CSP (2/6) 6
• A simple form of propagation makes sure all arcs are consistent:

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

AI2002 - Spring 2024


Arc Consistency of an Entire CSP (3/6) 7
• A simple form of propagation makes sure all arcs are consistent:

NT Q
WA
SA
NSW
V
Consistent or not?

• Arc NSW to SA is not consistent: if we assign NSW = blue, there is no valid


assignment left for SA
• To make this arc consistent, we delete NSW = blue from the tail

AI2002 - Spring 2024


Arc Consistency of an Entire CSP (4/6) 8
• A simple form of propagation makes sure all arcs are consistent:

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).

AI2002 - Spring 2024


Arc Consistency of an Entire CSP (6/6) 10
• A simple form of propagation makes sure all arcs are consistent:

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

AI2002 - Spring 2024


Arc Consistency 11

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

Arc <A, (A<B)> is inconsistent Arc <B, (A<B)> is consistent


No value in the domain of B
AI2002 - Spring 2024 Both B=2 and B=3 have valid
that satisfies A=3 values in the domain of A, A=1
Which arcs need to be reconsidered? 13
When we reduce the domain of a variable X to make an arc〈X,c〉consistent,
which arcs do we need to reconsider?
every arc <Z,c’> where c’ ≠ c
involves Z and X

Pruning elements of D(X) may remove


Z1 T values that made one or more of 〈 Z,c’ 〉
c1
inconsistent
H

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

Algorithm: general idea


• Go through all the arcs in the network
• Make each arc consistent by pruning the appropriate domain,
when needed
• Reconsider arcs that could be turned back to being inconsistent
by this pruning
• Eventually reach a ‘fixed point’: all arcs consistent
New: Constraint
Propagation
AI2002 - Spring 2024
AC-3 algorithm: Enforcing Arc Consistency in
17
a CSP

Time complexity: O(n2d3)


Terminates either with every arc
being consistent, or with one or
more variables with an empty
domain, meaning that the CSP
cannot be solved.

Compared to O(dN) of DFS with


pruning (backtracking search),
Arc consistency is MUCH faster!
AI2002 - Spring 2024
Filtering: Constraint Propagation 18

• Constraint propagation may be intertwined with search, or it may


be done as a preprocessing step, before search starts.
• Sometimes this preprocessing can solve the whole problem, so no
search is required at all.

AI2002 - Spring 2024


Limitations of Arc Consistency 19

What went wrong here?


• After enforcing arc consistency:
• Can have one solution left
• Can have multiple solutions left
• Can have no solutions left (and not know it)

• Arc consistency only checks local consistency


conditions

• Arc consistency still runs inside a backtracking


search!
AI2002 - Spring 2024
Improvingbacktracking efficiency 21

• So far, we have selected the next variable and the next value by
using a fixed order

• Is there a better way to pick next variable?


• Is there a better way to select next value to assign to the current
variable?

AI2002 - Spring 2024


Improving Backtracking 22

• General-purpose ideas give huge gains in speed

• Ordering:
• Which variable should be assigned next?
• In what order should its values be tried?

• Filtering: Can we detect inevitable failure early?

• Structure: Can we exploit the problem structure?


AI2002 - Spring 2024
Improvingbacktracking efficiency 23

• Pure backtracking is typically inefficient, because it is an


uninform algorithm.

• Backtracking search relies on one or more heuristics.

AI2002 - Spring 2024


Meaning of ‘heuristic’ in CSP as search 24

• This is a different use of the word ‘heuristic’ from the


definition we have given in the search module
• Qualifications of ‘heuristic’ still true in the context of CSP as search
• Can be computed cheaply during the search
• Provides guidance to the search algorithm
• Qualification that is not true anymore in this context
• ‘Estimate of the distance to the goal’

• In general
• ‘heuristic’ means ‘serves to discover’

AI2002 - Spring 2024


CSP Heuristics 25

AI2002 - Spring 2024


CSP Heuristics 26

• Variable ordering
• Minimum Remaining Value (MRV)
• Degree Heuristic (DH)

• Value ordering
• Least Constraining Value (LCV)

AI2002 - Spring 2024


MinimumRemainingValue (MRV) 27

• MRV selects the next variable to assign:


• which has the fewest number of legal values remaining for assignment

• Legal values: those which satisfy the respective constraint(s)

• Most likely to fail, “fail earlier”

AI2002 - Spring 2024


MinimumRemainingValue (MRV) 28

However, this province has the


MRV=1, i.e., only blue can be
assigned to it. So, we color it.

In this step, we could have


assigned color to this province
as well, i.e., either red or blue.
AI2002 - Spring 2024 Here, MRV=2
Degree Heuristic (DH) 29

• MRV doesn’t tell which variable to select at the beginning: can be


done using DH

• 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

• Tie breaker for MRV

AI2002 - Spring 2024


Degree Heuristic (DH) 30

2 constraints
Initially, we color this: degree = 5
3 constraints
(variable with max degree)

AI2002 - Spring 2024


Least Constraining Value (LCV) 31

• MRV and DH concentrate on choosing variables


• LCV is concerned with choosing the values of variables

• 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

AI2002 - Spring 2024


Least Constraining Value (LCV) 32

SA
SA can’t be assigned
any color now

AI2002 - Spring 2024


Generic CSP Solution 33

• Repeat until all variables have been assigned:


• Apply a consistency enforcement procedure
• Forward checking
• Constraint propagation (AC-3)
• If no solutions left:
• Backtrack to a previous variable
• Else
• Select the next variable to be assigned
• Using variable ordering heuristic (MCV + DH)
• Select a value to try for this variable
• Using value ordering heuristic (LCV)

AI2002 - Spring 2024


Solving CSPs 34

Solving CSPs with combination of heuristics plus forward


checking is more efficient than either approach alone

AI2002 - Spring 2024


Reading Material 36

• AIMA: Chapter # 6

AI2002 - Spring 2024

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy