Constraint
( slides courtesy o ( y based on slides court
t Networks
- f Natalia Flerova,
tesy of Rina Dechter)
Constraint t Networks ( slides courtesy o ( y of Natalia - - PowerPoint PPT Presentation
Constraint t Networks ( slides courtesy o ( y of Natalia Flerova, based on slides court tesy of Rina Dechter) Read ding Russell and Norvig Chapter 6 (3 rd ed.); Cha 6 (3 rd d ) Ch apter 5 (2 nd ed.) 5 (2 nd d ) Ch t t For next week:
( slides courtesy o ( y based on slides court
tesy of Rina Dechter)
3
Constraint Satisfaction Pro
Definition and simple mod
Definition, and simple mod
Representing constraints
Consistency algorithms (ar General search strategy
deling examples deling examples
4
Variables - countries (A Values - colors (e.g., r Constraints:
A≠ B,
A B A
red green red black green red green black bl k
B D
black green black red
C
A,B,C,etc.) red, green, black)
A≠ D, D≠ E , etc.
E D F G
A constraint network is: R=(X,D,C
X variables
D domains C constraints
D= {D
C constraints R expresses allowed tuples over scopes
C= {C
A solution is an assignment to all vari all relations). T k i t ? ll l ti
Tasks: consistency?, one or all solutio
C)
D1,..., Dn}, Di= {v1,...vk}
s
1,...Ct},,,Ci=
Si ,Ri
ables that satisfies all constraints (join of ti ti i ti
6
The network has four variables, all w (a) The labeled chess board. (b) The c
Sp
with domains Di = {1, 2, 3, 4}. constraints between variables.
ring 2009 7
Place 4 Queens on a chess board of 4x4 such that no two queens reside in the same row, column or diagonal.
D {1 2 3 4}
Di= {1,2,3,4}.
4 2
( )
2
R12= { 1,3
}
R13= { 1,2
R = { 1 2
R14= { 1,2
R23= { 1,3
}
R24= { 1,2
R { 1 3
} R34= { 1,3
}
Standard CSP formulation of the problem:
1 2 3 4
X1 X 2
1 2 3 4
X 4
X 3
2
raints involved:
4,3 }
}
X1
X 3
}
}
X 2 X 4
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 correspon solution (2, 4, 1,3). c) The placement of the queens correspon (3, 1, 4, 2).
Sp
art of a solution. di t th nding to the nding to the solution
ring 2009 9
Sp
ring 2009 10
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 highway
g y
Sp
ments, houses, cemetery,
area recreation and lake
ring 2009 11
CSP: Definition, and simp
Representing constraints Consistency algorithms (ar General search strategy
12
Relation: allowed tuples
p
Algebraic expression:
Propositional formula:
Sp
X Y Z 1 3 2
2 1 3
ring 2009 13
Intersection
Union Difference Selection Projection
Join
Composition
14
Figure 1.8: Example of set operation applied to
Sp
ns intersection, union, and difference
ring 2009 15
selection, projection, and jo
Sp
ring 2009 16
Primal, Dual an
A (primal) constraint graph: a node per variable t t i d i bl
arcs connect constrained variables.
A dual constraint graph: a node per constraint’s sc arc connect nodes sharing variables =hypergraph 1 2 4 1,2,3,4,5 5 3 6 9 7 11 5 12 8 10 5,7,11 Sp 13 (a)
nd Hypergraphs
cope, an 12,13 3,6,9,12 3 12 13 9 8,9,10,11 10,13 10 11 ring 2009 17 (b)
CSP: Definition, and simp
Representing constraints Consistency algorithms (ar General search strategy
18
Constraint propagation
Can get such an explic
Approximation of infer
Arc, path and i-consiste
Methods that transform
19
1 X Y Z T 3 X 3 2, 1, 1 X, Y, Z, T 3 X Y Y = Z T Z
3 2, 1, T Z X T , , T Insures that every legal value in the dom a legal match In the domain of any othe
pairs of variables
3 2, 1, Y
3 2, 1,
, , Z
20
main of a single variable has er selected variable
1 X Y Z T 3 X 1 1 X, Y, Z, T 3 X Y Y = Z T Z
T Z X T 2 T
Y
3
3 Z
21
22
23
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
O enk 3
s
24
t-case = ek,
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
25
be processed in O(2k) be processed in O(2k) ues
Implement AC-1 distributedly.
Node x j sends the message to node _j g x_i
Node x_i updates its domain:
Messages can be sent asynchronously or scheduled in a topological order
j π i
Di Di∩ π i Rij D j = D D ∩ h j Di Di∩ hi
j
26
Arc-consistency can be
A B C D F G 27
a Constraint network a Constraint network
The message that R2 sends to R1 is R1 updates its relation and domains and send messages to neighbors
A 1 2 3 A B 1 2 1 3
R1 R2
R3
A 3 A C 1 2 3 2 2 1 2 3 3 1 3 2 A B C 3 2 B C F
R5
D F
ds
B C F 1 2 3 3 2 1 A B D 1 2 3 1 3 2
R4
D F G 28 1 3 2 2 1 3 2 3 1 3 1 2 D F G 1 2 3 2 1 3
R6
3 2 1 2 1 3
A 1
R1
DRAC on
2 3 A B 1 2
R2
1 2 1 3 2 1 2 3 2
A
3 1 3 2
R4
AB
B
4
A
A B D 1 2 3 1 3 2 2 1 3
4 ABD
4
D
2 1 3 2 3 1 3 1 2 3 2 1 D 1
R6
1 2 A
1the dual join-graph
R
1 A C 1 2 3 2
R3
A
3
A
1
R5
AC
5
B C
B C F 1 2 3 3 2 1
BCF DFG
5 6
F
29 F G 2 3
DFG
2 3 1 3
P ti
Each row, column and major blo “Well posed” if it has unique solu
{ 1,2,3,4,5,6,7,8,9}
27 all-different 2 3 4 6
2
30
ution: 27 constraints
31
32
Complexity: O(k^3) Best-case: O(t) Worst-case O(tk)
e = number of arcs, n variables, k valu e number of arcs, n variables, k valu constraint relation
33
ues, t = tightness: number of tuples in the ues, t tightness: number of tuples in the
Complexity:
e = number of arcs, n variables, k values constraint relation
O n5k5
constraint relation
34
s, t = tightness: number of tuples in the
O n3k5
Complexity: Optimal PC-4:
O n3k3
(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, t constraint relation
35
ber of pairs: O(n^2 k^2) size of Q is
t ti ht b f t l i th t = tightness: number of tuples in the
PC-1 requires 2 processings of each ar
Can we do path-consistency distribute
36
rc while PC-2 may not edly?
37
CSP: Definition, and simp
Representing constraints Consistency algorithms (ar General search strategy
38
No matter how much we rea
are still left with choices → possible choices.
Backtracking search – assi
ki h i turn, making sure each assig values assigned thus far. E t i bl ith d
Encounter variable with no d
previous assignment – dead- the value of previous variabl
ason about the problem – we need to search the space of ign values to each variable in d l i i i h gned value is consistent with d i l i t t ith domain value consistent with
les.
39
A tree of all partial solu
A partial solution: (a1,
The size of the underly
Variable ordering Level of consistency po
Z evenly divides x,y,l 20 legal states 1 dead-end leaf 48 legal states 18 dead-end leaves
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
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)
Before search: (reducing
Arc consistenc path consist
Arc-consistency, path-consist Variable ordering (fixed)
During search:
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
tenc tency
ed) ed) racking
CSP: Definition, and simp
Representing constraints Consistency algorithms (ar General search strategy
51
Before search: (reducin
Arc-consistency, path-c Variable ordering (fixe
During search:
Look-ahead schemes:
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
dead-end ch node in the search tree parately) parately) )
The most limited form
Propagates the effect o
If domain of one of the
Complexity of selectValue-forward-che p y
O ek 2
cking at each node:
O ek
g
(Gashni
Applies full arc-consistenc
Complexity:
If optimal arc-consisten
SelectValue-Arc-Consiste
Maintaining-Arc-Consiste
ig, 1977)
Full looking ahead:
Make one full pass thro
Partial look-ahead:
Applies (similar-to) dir
Complexity: also More efficient than MA
CSP: Definition, and simp
Representing constraints Consistency algorithms (a General search strategy
62
Rank functions Rank functions
MC (min conflict) – choose
MD (min domain) – choose MD (min domain) – choose
domain size in future variab
SC (expected solution count
u t p y g t after incompatible values ar
s value that removes the smallest number future variables s value that creates the largest minimum s value that creates the largest minimum bles ts) – 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.
Following constraint propa
Intuition: early discovery Highly effective: the single
Most popular with FC Dynamic search rearrangem
(Purdon,1983)