Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Constraint( slides courtesy o( y
based on slides court
t Networksof Natalia Flerova,,tesy of Rina Dechter)
Read
Russell and NorvigCh t 6 (3rd d ) ChChapter 6 (3rd ed.); Cha
For next week:Ch t 7 (f T d )Chapter 7 (for Tuesday)Chapter 8 (for Thursday
ding
t 5 (2nd d )apter 5 (2nd ed.)
))y)
Good sourceGood sourceinform
Rina Dechter,
Constraint Processing,g,Morgan Kaufmann
e of advancede of advanced mation
3
Out
Constraint Satisfaction ProDefinition and simple mod Definition, and simple mod
Representing constraintsC i l i h ( Consistency algorithms (ar
General search strategy Look-ahead meth
tline
oblems (CSPs):deling examplesdeling examples
h d i i )rc-, path- and i-consistency)
hods
4
Constra
ExampleVariables - countries (AValues - colors (e.g., rConstraints: A≠ B,
A B Ared greenred blackgreen redgreen blackbl k
B
D
black greenblack red
C
aint Satisfaction
: map coloringA,B,C,etc.)red, green, black)
A≠ D, D≠ E , etc .
ED
FF
G
Constraint Netw A constraint network is: R=(X,D,C X variables X = {X D domains
C constraints
X {X
D= {D C constraints
R expresses allowed tuples over scopesC= {C
A solution is an assignment to all variall relations).
T k i t ? ll l ti Tasks: consistency?, one or all solutio
work; DefinitionC)
X1 X }X1 , .. . ,X n}D1 ,. . . , Dn} , Di= {v1 , . .. vk }
s1 ,. .. Ct },,, Ci= �Si ,Ri �
ables that satisfies all constraints (join of
ti ti i tions, counting, optimization
6
Example: The N-queens
The network has four variables, all w(a) The labeled chess board. (b) The c
Sp
problem
with domains Di = {1, 2, 3, 4}. constraints between variables.
ring 2009 7
Example The 4pPlace 4 Queens on a chess board of 4x4 such that no two queens reside in the same row, column or diagonal.
QQ Q
Q
Q QQ
QD {1 2 3 4}• Domains: Di= {1,2,3,4} .
• Constraints: There are = 6 constr42( )2
R12= {�1,3��1,4��2,4 ��3,1��4,1��4,2�}R13= {�1,2 ��1,4 ��2,1��2,3��3,2��3,4��4,1��4R = {�1 2��1 3��2 1��2 3��2 4��3 1��3 2��3R14= {�1,2��1,3��2,1��2,3��2,4��3,1��3,2��3R23= {�1,3��1,4��2,4 ��3,1��4,1��4,2 �}R24= {�1,2 ��1,4��2,1��2,3��3,2��3,4��4,1��4R {�1 3��1 4 ��2 4��3 1��4 1��4 2�}R34= {�1,3��1,4 ��2,4��3,1��4,1��4,2�}
4-queen problemq pStandard CSP formulation of the problem:• Variables: each row is a variable.
1 2 3 4
QQX1
X 2
1 2 3 4
QX 4
X 3
2
raints involved:
4,3�}�3 4��4 2 ��4 3�}
• Constraint Graph :X1 X 3
�3,4��4,2 ��4,3�}
�4,3�}X 2 X 4
A solution and a pA solution and a ptup
Not all consistent instantiations are part o(a)A consistent instantiation that is not pa(b) Th l t f th(b) The placement of the queens corresponsolution (2, 4, 1,3). c) The placement of the queens correspon(3, 1, 4, 2).
Sp
partial consistentpartial consistent pleof a solution: art of a solution.
di t thnding to the
nding to the solution
ring 2009 9
Configuratio Want to build: recreation area, apartm
dump
Recreation area near lake Steep slopes avoided except for recreation a
P il id d f d l t Poor soil avoided for developments Highway far from apartments, houses and r Dump not visible from apartments, houses Lots 3 and 4 have poor soil Lots 3 and 4 have poor soil Lots 3, 4, 7, 8 are on steep slopes Lots 2, 3, 4 are near lake Lots 1, 2 are near highwayg y
Sp
on and designments, houses, cemetery,
area
recreationand lake
ring 2009 11
Out
CSP: Definition, and simpRepresenting constraints Representing constraints
Consistency algorithms (ar General search strategy
Look-ahead meth
tline
ple modeling examples
rc-, path- and i-consistency)
hods
12
Constraint’s re
Relation: allowed tuplesp
Algebraic expression:X
Propositional formula:X
Sp
epresentationsX Y Z1 3 2
X Y 2 10 X≠ Y
2 1 3
X �Y 2≤ 10 , X≠ Y
� �b���a�b�� ¬c
ring 2009 13
Operations w Intersection
U i Union Difference Selection Projectionj Join
Composition Composition
with relations
14
Figure 1.8: Example of set operationapplied to
Sp
ns intersection, union, and difference o relations.
ring 2009 15
ConstrainPrimal, Dual an
A (primal) constraint graph: a node per variablet t i d i bl arcs connect constrained variables.
A dual constraint graph: a node per constraint’s scarc connect nodes sharing variables =hypergraph
1 2 4
1,2,3,4,5
536
9 7 11 5
12 8 105,7,11
Sp
13
(a)
nt Graphs: nd Hypergraphs
cope, an
12,133,6,9,12
3 12
139
8,9,10,11 10,131011
ring 2009 17(b)
Out
CSP: Definition, and simpRepresenting constraints Representing constraints
Consistency algorithms (ar General search strategy
Look-ahead meth
tline
ple modeling examples
rc-, path- and i-consistency)
hods
18
Consistenc Constraint propagation
constraintsconstraints Can get such an explic
ill fi d th l tiwill find the solution w Approximation of infer
Arc, path and i-consiste Methods that transform
into a tighter and tighte
cy methodsn – inferring new
it network that the search ith t d d dwithout dead-ends.
rence:ency
m the original network
19
er representations
Arc-consArc-cons- infer constraints based on p
1 X Y Z T 3
X
32,1,1 X, Y, Z, T 3X YY = ZT Z
32,1,
T ZX T
,,
T
Insures that every legal value in the doma legal match In the domain of any othe
sistencysistencypairs of variables
32,1,
Y
=
32,1, ,,
Z
20
main of a single variable haser selected variable
ACAC
Complexity (Mackworth and Freuder, 1986): e = number of arcs, n variables, k values (ek^2, each loop, nk number of loops), best Arc-consistency is:
� �ek 2�
C-1C-1
O�enk 3�s
24
t-case = ek,
ACAC
O�ek 3� Complexity: Best case O(ek) since each arc may Best case O(ek), since each arc may e = number of arcs, n variables, k valu
C-3C-3
25be processed in O(2k)be processed in O(2k)ues
Distributed arDistributed ar(Constraint p
Implement AC-1 distributedly.
Node x j sends the message to node _j gx_i
Node x_i updates its domain:
Messages can be sent asynchronously or scheduled in a topological order
rc-consistencyrc-consistencypropagation)
Di � Di∩ π i�Rij � D j �
hij � π i�Rij � D j �
Di � Di∩ π i�Rij � D j �=D D ∩ h jDi � Di∩ hi
j
26
Distributed ArA i b Arc-consistency can be algorithm:
rc-Consistencyf l d di ib dformulated as a distributed
A
B C
D F
G
27a Constraint networka Constraint network
Relational Ar
The message that R2 sends to R1 is
R1 updates its relation and domains and sendmessages to neighbors
rc-consistencyA123
A B1 21 3
R1R2 R3A 3 A C
1 23 2
2 1
2 3
3 13 2
A
B C
3 2
B C F
R5D F
ds
B C F1 2 33 2 1A B D
1 2 31 3 2
R4D F
G
28
1 3 22 1 32 3 13 1 2
D F G1 2 32 1 3
R6
3 2 1 2 1 3
A1
R1DRAC on
23
A B1 2
R2
1 21 32 12 3 2 A
3 13 2
R4
AB
B
4
A
A B D1 2 31 3 22 1 3
4
ABD
4
D
2 1 32 3 13 1 23 2 1 D
1
R6
12
A1the dual join-graph
R1
A C1 23 2
R3A
3A
1
R5
AC
5
B C
B C F1 2 33 2 1
BCF
DFG
5
6F
29F G2 3
DFG
2 31 3
SudConstraint
•Constraint P ti•Propagation
•Inference
Each row, column and major blo
“Well posed” if it has unique solu
doku –t Satisfactionf
•Variables: empty slots
•Domains = {1,2,3,4,5,6,7,8,9}
•Constraints: 27 all-different
2 34 62
30ock must be alldifferent
ution: 27 constraints
ReviRevi
Complexity: O(k^3) Best-case: O(t) Worst-case O(tk) e = number of arcs, n variables, k value number of arcs, n variables, k valu
constraint relation
ise-3ise-3
33ues, t = tightness: number of tuples in theues, t tightness: number of tuples in the
PC
Complexity: e = number of arcs, n variables, k values
constraint relation
O�n5 k5�
constraint relation
C-1
34s, t = tightness: number of tuples in the
PC-PC-
O�n3 k5� Complexity: Optimal PC-4: O�n3 k3� (each pair deleted may add: 2n-1 triplets, numb
O(n^3 k^2), processing is O(k^3))b f i bl k l t
O n k
e = number of arcs, n variables, k values, tconstraint relation
-2-2
35
ber of pairs: O(n^2 k^2) size of Q is
t ti ht b f t l i tht = tightness: number of tuples in the
Example: beforeExample: beforeconsis
PC-1 requires 2 processings of each ar Can we do path-consistency distribute
e and after path-e and after path-stency
36
rc while PC-2 may notedly?
Out
CSP: Definition, and simpRepresenting constraints Representing constraints
Consistency algorithms (ar General search strategy
Look-ahead meth
tline
ple modeling examples
rc-, path- and i-consistency)
hods
38
Backtrackin
No matter how much we reaare still left with choices → possible choices.
Backtracking search – assiki h iturn, making sure each assig
values assigned thus far.E t i bl ith d Encounter variable with no dprevious assignment – dead-the value of previous variabl
ng algorithm
ason about the problem – we need to search the space of
ign values to each variable in d l i i i hgned value is consistent with
d i l i t t ithdomain value consistent with -end → backtrack – change les.
39
The sear
A tree of all partial soluA i l l i ( 1 A partial solution: (a1,relevant constraints
The size of the underlyon: Variable ordering Level of consistency po
rch space
utionsj) i f i ll…,aj) satisfying all
ying search space depends
ossessed by the problem
S h d hSearch space and thh ff f d ihe effect of ordering
Z evenly divides x,y,l
20 legal states1 dead-end leaf
48 legal states18 dead-end leaves
Dependency on cDependency on c
After arc-consistency z=5 and l=5 are removed
After path-consistency R’_zx R’_zy R’_zl R’_xy R’_xl R’_yl
consistency levelconsistency level
BacktrBacktrrackingracking
Complexity of extending a partial solution: Complexity of consistent O(e log
t), t bounds tuples, e constraints Complexity of selectvalue O(e k
log t)log t)
Improving b
Before search: (reducingArc consistenc path consist Arc-consistency, path-consist
Variable ordering (fixed)
During search:g Look-ahead schemes:
value ordering, variable ordering (if not fixe variable ordering (if not fixe
Look-back schemes: Backjump
Constraint recording Constraint recording Dependency-directed backtr
backtracking
g the search space)tenctency
ed)ed)
racking
Out
CSP: Definition, and simpRepresenting constraints Representing constraints
Consistency algorithms (ar General search strategy
Look-ahead meth
tline
ple modeling examples
rc-, path- and i-consistency)
hods
51
Improving b
Before search: (reducinA i t th Arc-consistency, path-c
Variable ordering (fixeDuring search: During search:
Look-ahead schemes: Look-ahead schemes: value order
maximizesfuture assig
variable ori t ti tinstantiate variable
backtracking
ng the search space)i tconsistency
ed)
ring - first assign value that
s the number of options for pgnmentsrdering (if not fixed)- first
t hi hl t i dmost highly constrained
Look-ahead: v
Intuition: Choose value least likely to yield a y y Approach: apply propagation at eac
Forward-checking (check each unassigned variable sep(check each unassigned variable sep
Maintaining arc-consistency (MAC) (apply full arc-consistency)
Full look-ahead Full look ahead One pass of arc-consistency (AC-1)
Partial look-ahead directional-arc-consistency directional-arc-consistency
value orderings
dead-endch node in the search tree
parately)parately)
)
Forward-
The most limited form propagation during seapropagation during sea
Propagates the effect oselection to each futureselection to each future
If domain of one of thebecomes empty – valuenext value.
-checking
of constraint archarchf a tentative value
e variable separatelye variable separatelye future variables e is not selected → try
Arc-consisten(Gashni
Applies full arc-consistencvariables following each vvariables following each vcurrent variable.
Complexity:p y If optimal arc-consisten
SelectValue-Arc-Consisteessentially AC-1 with som
Maintaining-Arc-Consistearc-consistency after each
cy look-aheadig, 1977)
cy on all un-instantiated value assignment to thevalue assignment to the
O�ek 3�ncy is used:
O�ek �
ency: The repeat...until loop –me variables instantiated. ency (MAC): Performs full h domain value is rejected.
Full and parti
Full looking ahead:M k f ll th Make one full pass thro(remove repeat-until froconsistency)consistency)
Partial look-ahead:Applies (similar to) dir Applies (similar-to) dirfuture variables. - futurcompared with those vaO�e
Complexity: also More efficient than MA
O�e
ial look-ahead
h f t i blough future variables om selectValue-arc-
rectional arc consistency torectional arc-consistency to re variables are only ariables following them. ek 3�
AC
ek �
Out
CSP: Definition, and simpRepresenting constraints Representing constraints
Consistency algorithms (a General search strategy
Look-ahead meth Branching-ahead
tline
ple modeling examples
cr-, path- and i-consistency)
hodsd
62
Branching-ahead: Dy
Rank order the promise in non Rank functionsRank functions
MC (min conflict) – chooseof values from domains of f
MD (min domain) – choose MD (min domain) – choosedomain size in future variab
SC (expected solution countof solutions by multiplying to so ut o s by u t p y g tafter incompatible values ar
ynamic Value Ordering
n-rejected values
s value that removes the smallest number future variabless value that creates the largest minimums value that creates the largest minimum
blests) – computes upper bound on number the domains sizes of each future variable t e do a s s es o eac utu e va ab e
re removed.
BranchinDynamic Variable
Following constraint propaconstrained variableconstrained variable
Intuition: early discovery Highly effective: the singleg y e ec ve: t e s g e
cut down search space Most popular with FC Dynamic search rearrangem
(Purdon,1983)
ng-ahead: e Ordering (DVO)
agation, choose the most
of dead-endse most important heuristic to e ost po ta t eu st c to
ment (Bitner and Reingold, 1975)