artificial intelligence, lecture 4.1, page 1 · 2014-03-25 · any partial assignment that...
TRANSCRIPT
![Page 1: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/1.jpg)
Learning Objectives
At the end of the class you should be able to:
recognize and represent constraint satisfaction problems
show how constraint satisfaction problems can be solved withsearch
implement and trace arc-consistency of a constraint graph
show how domain splitting can solve constraint problems
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 1
![Page 2: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/2.jpg)
Constraint satisfaction revisited
A Constraint Satisfaction problem consists of:
Ia set of variables
Ia set of possible values, a domain for each variable
Ia set of constraints amongst subsets of the variables
The aim is to find a set of assignments that satisfies all
constraints, or to find all such assignments.
c�D. Poole and A. Mackworth 2009 Artificial Intelligence, Lecture 4.3, Page 1
![Page 3: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/3.jpg)
Example: crossword puzzle
1 2
3
4 5
6
at, be, he, it, on,
eta, hat, her, him,
one,
desk, dove, easy,
else, help, kind,
soon, this,
dance, first, fuels,
given, haste, loses,
sense, sound, think,
usage
c�D. Poole and A. Mackworth 2009 Artificial Intelligence, Lecture 4.3, Page 2
![Page 4: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/4.jpg)
Dual Representations
Two ways to represent the crossword as a CSP
First representation:
Inodes represent word positions: 1-down. . . 6-across
Idomains are the words
Iconstraints specify that the letters on the intersections must
be the same.
Dual representation:
Inodes represent the individual squares
Idomains are the letters
Iconstraints specify that the words must fit
c�D. Poole and A. Mackworth 2009 Artificial Intelligence, Lecture 4.3, Page 3
![Page 5: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/5.jpg)
Posing a Constraint Satisfaction Problem
A CSP is characterized by
A set of variables V1,V2, . . . ,Vn.
Each variable Vi has an associated domain DVi of possiblevalues.
There are hard constraints on various subsets of the variableswhich specify legal combinations of values for these variables.
A solution to the CSP is an assignment of a value to eachvariable that satisfies all the constraints.
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 2
![Page 6: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/6.jpg)
Example: scheduling activities
Variables: A, B , C , D, E that represent the starting times ofvarious activities.
Domains: DA = {1, 2, 3, 4}, DB = {1, 2, 3, 4},DC = {1, 2, 3, 4}, DD = {1, 2, 3, 4}, DE = {1, 2, 3, 4}Constraints:
(B 6= 3) ^ (C 6= 2) ^ (A 6= B) ^ (B 6= C ) ^(C < D) ^ (A = D) ^ (E < A) ^ (E < B) ^(E < C ) ^ (E < D) ^ (B 6= D).
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 3
![Page 7: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/7.jpg)
Generate-and-Test Algorithm
Generate the assignment space D = DV1 ⇥DV2 ⇥ . . .⇥DVn .Test each assignment with the constraints.
Example:
D = DA ⇥DB ⇥DC ⇥DD ⇥DE
= {1, 2, 3, 4}⇥ {1, 2, 3, 4}⇥ {1, 2, 3, 4}⇥{1, 2, 3, 4}⇥ {1, 2, 3, 4}
= {h1, 1, 1, 1, 1i , h1, 1, 1, 1, 2i , ..., h4, 4, 4, 4, 4i}.
How many assignments need to be tested for n variables eachwith domain size d?
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 4
![Page 8: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/8.jpg)
Backtracking Algorithms
Systematically explore D by instantiating the variables one ata time
evaluate each constraint predicate as soon as all its variablesare bound
any partial assignment that doesn’t satisfy the constraint canbe pruned.
Example Assignment A = 1 ^ B = 1 is inconsistent withconstraint A 6= B regardless of the value of the other variables.
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 5
![Page 9: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/9.jpg)
CSP as Graph Searching
A CSP can be solved by graph-searching:
A node is an assignment values to some of the variables.
Suppose node N is the assignment X1 = v1, . . . ,Xk = vk .Select a variable Y that isn’t assigned in N.For each value yi 2 dom(Y )X1 = v1, . . . ,Xk = vk ,Y = yi is a neighbour if it is consistentwith the constraints.
The start node is the empty assignment.
A goal node is a total assignment that satisfies the constraints.
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 6
![Page 10: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/10.jpg)
![Page 11: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/11.jpg)
![Page 12: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/12.jpg)
Consistency Algorithms
Idea: prune the domains as much as possible before selectingvalues from them.
A variable is domain consistent if no value of the domain ofthe node is ruled impossible by any of the constraints.
Example: Is the scheduling example domain consistent?
DB = {1, 2, 3, 4} isn’t domain consistent as B = 3 violatesthe constraint B 6= 3.
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 7
![Page 13: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/13.jpg)
Consistency Algorithms
Idea: prune the domains as much as possible before selectingvalues from them.
A variable is domain consistent if no value of the domain ofthe node is ruled impossible by any of the constraints.
Example: Is the scheduling example domain consistent?DB = {1, 2, 3, 4} isn’t domain consistent as B = 3 violatesthe constraint B 6= 3.
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 8
![Page 14: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/14.jpg)
Constraint Network
There is a oval-shaped node for each variable.
There is a rectangular node for each constraint.
There is a domain of values associated with each variablenode.
There is an arc from variable X to each constraint thatinvolves X .
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 9
![Page 15: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/15.jpg)
![Page 16: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/16.jpg)
Example Constraint Network
{1,2,3,4} {1,2,4}
{1,2,3,4} {1,3,4}
{1,2,3,4}
A B
D C
E
A ! B
B ! D
C < D
A = D
E < A
B ! C
E < B
E < D E < C
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 10
![Page 17: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/17.jpg)
Arc Consistency
An arc⌦X , r(X ,Y )
↵is arc consistent if, for each value
x 2 dom(X ), there is some value y 2 dom(Y ) such thatr(x , y) is satisfied.
A network is arc consistent if all its arcs are arc consistent.
What if arc⌦X , r(X ,Y )
↵is not arc consistent?
All values of X in dom(X ) for which there is no correspondingvalue in dom(Y ) can be deleted from dom(X ) to make thearc
⌦X , r(X ,Y )
↵consistent.
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 11
![Page 18: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/18.jpg)
Arc Consistency
An arc⌦X , r(X ,Y )
↵is arc consistent if, for each value
x 2 dom(X ), there is some value y 2 dom(Y ) such thatr(x , y) is satisfied.
A network is arc consistent if all its arcs are arc consistent.
What if arc⌦X , r(X ,Y )
↵is not arc consistent?
All values of X in dom(X ) for which there is no correspondingvalue in dom(Y ) can be deleted from dom(X ) to make thearc
⌦X , r(X ,Y )
↵consistent.
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 12
![Page 19: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/19.jpg)
Arc Consistency Algorithm
The arcs can be considered in turn making each arc consistent.
When an arc has been made arc consistent, does it ever needto be checked again?
An arc⌦X , r(X ,Y )
↵needs to be revisited if the domain of
one of the Y ’s is reduced.
Three possible outcomes when all arcs are made arcconsistent: (Is there a solution?)
I One domain is empty =)
no solution
I Each domain has a single value =)
unique solution
I Some domains have more than one value =)
there may ormay not be a solution
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 13
![Page 20: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/20.jpg)
Arc Consistency Algorithm
The arcs can be considered in turn making each arc consistent.
When an arc has been made arc consistent, does it ever needto be checked again?An arc
⌦X , r(X ,Y )
↵needs to be revisited if the domain of
one of the Y ’s is reduced.
Three possible outcomes when all arcs are made arcconsistent: (Is there a solution?)
I One domain is empty =)
no solution
I Each domain has a single value =)
unique solution
I Some domains have more than one value =)
there may ormay not be a solution
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 14
![Page 21: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/21.jpg)
Arc Consistency Algorithm
The arcs can be considered in turn making each arc consistent.
When an arc has been made arc consistent, does it ever needto be checked again?An arc
⌦X , r(X ,Y )
↵needs to be revisited if the domain of
one of the Y ’s is reduced.
Three possible outcomes when all arcs are made arcconsistent: (Is there a solution?)
I One domain is empty =) no solutionI Each domain has a single value =) unique solutionI Some domains have more than one value =) there may or
may not be a solution
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 15
![Page 22: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/22.jpg)
![Page 23: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/23.jpg)
![Page 24: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/24.jpg)
![Page 25: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/25.jpg)
![Page 26: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/26.jpg)
Finding solutions when AC finishes
If some domains have more than one element =) search
Split a domain, then recursively solve each half.
It is often best to split a domain in half.
Do we need to restart from scratch?
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 16
![Page 27: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/27.jpg)
![Page 28: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/28.jpg)
![Page 29: Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that doesn’t satisfy the constraint can be pruned. Example Assignment A =1^B = 1 is inconsistent](https://reader034.vdocuments.us/reader034/viewer/2022050510/5f9ab855d7b3952bb530b9cd/html5/thumbnails/29.jpg)
Hard and Soft Constraints
Given a set of variables, assign a value to each variable thateither
I satisfies some set of constraints: satisfiability problems —“hard constraints”
I minimizes some cost function, where each assignment ofvalues to variables has some cost: optimization problems —“soft constraints”
Many problems are a mix of hard and soft constraints(called constrained optimization problems).
c�D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 4.1, Page 18