Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that...
Transcript of Artificial Intelligence, Lecture 4.1, Page 1 · 2014-03-25 · any partial assignment that...
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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