View
221
Download
0
Embed Size (px)
Citation preview
ACP Advanced Summer School on Global Constraints - Samos, Greece.
1
Global Variables
Irit KatrielBRICS, University of Aarhus
ACP Advanced Summer School on Global Constraints - Samos, Greece.
2
Roles of Global Constraints Syntactic: Simplify models
nn
nnnn
n
n
xx
xxxx
xxxxxx
xxntAllDiffere
1
212
13121
1 vs.),...,(
ACP Advanced Summer School on Global Constraints - Samos, Greece.
3
Roles of Global Constraints Speed up solving (by propagation)
323121
321
321
vs.
),,(
}1,0{)()()(
xxxxxx
xxxntAllDiffere
xDxDxD
ACP Advanced Summer School on Global Constraints - Samos, Greece.
4
Global Variables
Assigned structured data, e.g., A set of scalar values A graph A function …
Same roles as global constraints Simplify models Improve propagation
ACP Advanced Summer School on Global Constraints - Samos, Greece.
5
Bin Packing
n items of different sizes: s1,…,sn
Bin size: b
ACP Advanced Summer School on Global Constraints - Samos, Greece.
6
Bin Packing
Pack items in as few bins as possible
ACP Advanced Summer School on Global Constraints - Samos, Greece.
7
Bin Packing - Model 1
A variable for each item: x1,…,xn
At most n bins: D(x1) = {1,…,n}
Constraints:
Objective: ixi jj :min
ixjji
j
bs:
ACP Advanced Summer School on Global Constraints - Samos, Greece.
8
A variable for each item: x1,…,xn
At most n bins: D(x1) = {1,…,n}
Constraints:
Objective:
Bin Packing - Model 1
ixi jj :min
ixjji
j
bs:Complicated
constraintsSymmetry breaking?
ACP Advanced Summer School on Global Constraints - Samos, Greece.
9
A set for each bin: b1,…,bn
D(bi) = P({1,…,n})
Constraints:
Objective:
Bin Packing - Model 2
ibi :min
bs
xxbb
bb
ij bxji
nn
jiji
},,{ 11
ACP Advanced Summer School on Global Constraints - Samos, Greece.
10
A set for each bin: b1,…,bn
D(bi) = P({1,…,n})
Constraints:
Objective:
Bin Packing - Model 2
ibi :min
bs
xxbb
bb
ij bxji
nn
jiji
},,{ 11
Simple constraints Symmetry:
lex order among sets.
ACP Advanced Summer School on Global Constraints - Samos, Greece.
11
Shift Assignment (a generalization of GCC)
Shifts
Employees
[1,2] [1,1] [2,3] [0,1] [1,3] [1,2]
[1,1] [1,2] [0,1] [0,2] [1,3] [1,2] [1,1] [0,1]
Each employee is assigned a set of shifts!
ACP Advanced Summer School on Global Constraints - Samos, Greece.
12
Domain Representation
Enumerate all subsets Pro: Accurate (any domain can be expressed) Con: Exponential blowup
D(X)= { {1,2,3}, {2,3}, {3} }
ACP Advanced Summer School on Global Constraints - Samos, Greece.
13
Domain Representation
Solution: Approximate domains
D(X)= {5, 7, 9, 15, 23, 27, 39, 43}
Can be approximated by an interval of the integers
D(X)= [5, 43]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
14
Compact Set Representation Collection of domain variables
x1,…,xn, D(xi) = Universe AllDifferent(x1,…,xn) Break symmetry: x1< … <xn
If cardinality is unknown, add a dummy value (and replace AllDifferent by NValue)
Pro: Compact (in terms of space requirements) Con: Inaccurate, clumsy
Set variables are an abstraction of this representation
ACP Advanced Summer School on Global Constraints - Samos, Greece.
15
Set Bounds [Puget’92, Gervet’97]The domain is specified by two sets:
}|{],[)( UsLsULXD
L (lower bound)
U (upper bound)
Set inclusion lattice
ACP Advanced Summer School on Global Constraints - Samos, Greece.
16
Compact Domain Representation D(X)= { {1,2,3}, {2,3}, {3} }
Becomes
D(X) = [ {3}, {1,2,3} ]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
17
Compact Domain Representation D(X)= { {1,2,3}, {2,3}, {3} }
Becomes
D(X) = [ {3}, {1,2,3} ]
Note: D(X) contains also {2,3} !
ACP Advanced Summer School on Global Constraints - Samos, Greece.
18
Partial vs. Total Order
Note: L and U may not belong to the domain!
D(X)= { {1,2}, {1,3} }
Becomes
D(X) = [ {1}, {1,2,3} ]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
19
Filtering
Bound consistency: Narrow the domain as much as possible without losing any solutions
L (lower bound)
U (upper bound)
ACP Advanced Summer School on Global Constraints - Samos, Greece.
20
Filtering
Bound consistency: Narrow the domain as much as possible without losing any solutions
L (lower bound)
U (upper bound)
ACP Advanced Summer School on Global Constraints - Samos, Greece.
21
A Simple Example
Subset(S,X) (S is a subset of X) Where D(S)=[LS,US], D(X)=[LX,UX]
SXX
XSS
XS
LLL
UUU
UL
.3
.2
solution no is there\ If.1
:Algorithmy Consistenc Bound
ACP Advanced Summer School on Global Constraints - Samos, Greece.
22
A Simple Example
Subset(S,X) (S is a subset of X) Where D(S)=[LS,US], D(X)=[LX,UX]
SXX
XSS
XS
LLL
UUU
UL
.3
.2
solution no is there\ If.1
:Algorithmy Consistenc Bound
Running time:O(|Us|+|Ux|)
ACP Advanced Summer School on Global Constraints - Samos, Greece.
23
Lattice Domain Representation Pro
Compact (space and specification) Filtering time depends on size of representation and not
on cardinality of domain
Con Not all domains can be expressed accurately
Partial filtering (only bounds)
ACP Advanced Summer School on Global Constraints - Samos, Greece.
24
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]
Shifts
Employees
[1,2] [1,1] [2,3] [0,1]
[1,1] [1,2] [0,1] [0,2] [1,3]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
25
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]
[1,2] [1,1] [2,3] [0,1]
[1,1]
[1,2] [0,1] [0,2][1,3]
[0,1]
s
t
[4,7]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
26
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]
[1,2] [1,1] [2,3] [0,1]
[1,1]
[1,2] [0,1] [0,2][1,3]
[0,1]
s
t
[4,7]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
27
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]
[0,1][0,1] [0,1]
[0,1] [0,1] [0,1][0,2]
[0,1]
s
t
[0,3]
Residual graph:
ACP Advanced Summer School on Global Constraints - Samos, Greece.
28
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]
[0,1][0,1] [0,1]
[0,1] [0,1] [0,1][0,2]
[0,1]
s
t
[0,3]
Strongly ConnectedComponents:
ACP Advanced Summer School on Global Constraints - Samos, Greece.
29
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]
[0,1][0,1] [0,1]
[0,1] [0,1] [0,1][0,2]
[0,1]
s
t
[0,3]
Non-flow edge betweenSCCs: Infeasible.
ACP Advanced Summer School on Global Constraints - Samos, Greece.
30
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]
[0,1][0,1] [0,1]
[0,1] [0,1] [0,1][0,2]
[0,1]
s
t
[0,3]
Flow edge betweenSCCs: Mandatory.
ACP Advanced Summer School on Global Constraints - Samos, Greece.
31
Symetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]Algorithm: Connect each employee with possible shifts
by edge of capacity [1,1] if the shift is mandatory by edge of capacity [0,1] otherwise
ACP Advanced Summer School on Global Constraints - Samos, Greece.
32
Symetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004]Algorithm: Connect employee with all possible shifts
by edge of capacity [1,1] if the shift is mandatory by edge of capacity [0,1] otherwise
Find a flow, construct the residual graph Edges between SCCs are filtered
Non-flow edges are deleted Inconsistency if one of them was mandatory
Flow edges become mandatory If they were not already
ACP Advanced Summer School on Global Constraints - Samos, Greece.
33
FixedCardinalityDisjoint(X1,…,Xn,C) Set Variables X1,…,Xn
A constant C
Semantics:
jiji
ii
XX
CX
[Sadler and Gevret, Techreport’04 / Bessiere et al. CP’04 / Implemented in ILOG solver]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
34
FixedCardinalityDisjoint(X1,…,Xn,C)
values
Set variables
[0,1] [0,1] [0,1] [0,1]
[C, C] [C,C] [C,C] [C,C] [C,C]
Special case of the symmetric cardinality constraint:
ACP Advanced Summer School on Global Constraints - Samos, Greece.
35
FixedCardinalityDisjoint(X1,…,Xn,C)
values
Set variables
[0,1] [0,1] [0,1] [0,1]
[C,C] [C,C] [C,C] [C,C] [C,C]
Actually, this is an upside-down GCC:
values
Domain variables
ACP Advanced Summer School on Global Constraints - Samos, Greece.
36
Multiset Variables [Walsh CP’03] Domain representations:
Domain Variables Same problems as with sets
Bounds: Generalization of Gervet/Puget’s set intervals D(X)=[L,U] where L and U are multisets
Occurrence representation D(X)=(a,{0,1}), (b,{3,4}), (c,{2,5})
ACP Advanced Summer School on Global Constraints - Samos, Greece.
37
Multiset Variables [Walsh CP’03]Thm: Occurrence representation is more
expressive than bound representation
D(X) = { {a} , {a,a,a} }
Bounds: D(X)=[{a},{a,a,a}] Includes {a,a}
Occurrence: D(X)=[(a,{1,3})]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
38
Multiset Variables [Walsh CP’03]Thm: Occurrence representation is more
expressive than bound representation
This does not hold if occurrences are described as intervals!
(a,[1,3]) = [{a},{a,a,a}]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
39
Set vs. Multiset Variables
It’s all the same, but with repetitions. right?
ACP Advanced Summer School on Global Constraints - Samos, Greece.
40
FixedCardinalityDisjoint(X1,…,Xn,C)It’s all the same, but with repetitions. right?
values
Multiset variables[ 0, occi ]
[C, C] [C,C] [C,C] [C,C] [C,C]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
41
FixedCardinalityDisjoint(X1,…,Xn,C)It’s all the same, but with repetitions. right?
values
Multiset variables
[ 0, occi ]
[C, C] [C,C] [C,C] [C,C] [C,C]
[ 0, max{occi} ]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
42
FixedCardinalityDisjoint(X1,…,Xn,C)It’s all the same, but with repetitions. right?
values
Multiset variables
[ 0, occi ]
[C, C] [C,C] [C,C] [C,C] [C,C]
[ 0, max{occi} ]
But how do we enforce disjointness?
ACP Advanced Summer School on Global Constraints - Samos, Greece.
43
FixedCardinalityDisjoint(X1,…,Xn,C)It’s all the same, but with repetitions. right?
values
Multiset variables
{ 0, occi }
[C, C] [C,C] [C,C] [C,C] [C,C]
[ 0, max{occi} ]
But how do we enforce disjointness?
ACP Advanced Summer School on Global Constraints - Samos, Greece.
44
FixedCardinalityDisjoint(X1,…,Xn,C)It’s all the same, but with repetitions. right?
values
Multiset variables
{ 0, occi }
[C, C] [C,C] [C,C] [C,C] [C,C]
[ 0, max{occi} ]
But how do we enforce disjointness?
Flow
becomes
NP-Hard
ACP Advanced Summer School on Global Constraints - Samos, Greece.
45
FixedCardinalityDisjoint(X1,…,Xn,C)It’s all the same, but with repetitions. right?
Apparently not!
Thm [Bessiere et al. CP’04]: It is NP-hard to check feasibility for FCDisjoint on multiset variables.
ACP Advanced Summer School on Global Constraints - Samos, Greece.
46
Reduction from 3-SAT )()( 431321 xxxxxx
x11 x13 x23 x24 !x12 !x21
p1 p2 p3 p4 n1 n2 n3 n4
ValueSet variable
ACP Advanced Summer School on Global Constraints - Samos, Greece.
47
Reduction from 3-SAT )()( 431321 xxxxxx
x11 x13 x23 x24 !x12 !x21
ValueSet variable
Value for each non-negated occurrence
Value for each negated occurrenceVariable for each clause
Cardinality = 1
Clause variables ”take” one literal from each clause
ACP Advanced Summer School on Global Constraints - Samos, Greece.
48
Reduction from 3-SAT )()( 431321 xxxxxx
x11 x13 x23 x24 !x12 !x21
p1 p2 p3 p4 n1 n2 n3 n4
ValueSet variable
Variable for each non-negated occurrence
Cardinality = # occurrences
Variable for each negated occurrence
Cardinality = # occurrences
”True” and ”False” value for each variable
pi if xi is trueni if xi is false
ACP Advanced Summer School on Global Constraints - Samos, Greece.
49
Reduction from 3-SAT )()( 431321 xxxxxx
x11 x13 x23 x24 !x12 !x21
p1 p2 p3 p4n1 n2 n3 n4
ValueSet variable
Consistency variables
Cardinality = 1
ACP Advanced Summer School on Global Constraints - Samos, Greece.
50
Reduction from 3-SAT )()( 431321 xxxxxx
x11 x13 x23 x24 !x12 !x21
p1 p2 p3 p4n1 n2 n3 n4
ValueSet variable
X2=x4 =FALSE X1= X3 =TRUE
”0 times”
ACP Advanced Summer School on Global Constraints - Samos, Greece.
51
Reduction from 3-SAT )()( 431321 xxxxxx
x11 x13 x23 x24 !x12 !x21
p1 p2 p3 p4n1 n2 n3 n4
ValueSet variable
Multisets allow us to encode choices!
ACP Advanced Summer School on Global Constraints - Samos, Greece.
52
Graph Variables [Dooms et al. CP’05]Graph variable: Two set variables, V and E with VVE Conceptually:
L (lower bound)
U (upper bound)
graph inclusion lattice
ACP Advanced Summer School on Global Constraints - Samos, Greece.
53
Filtering With Graph Variables1.Useless
dashed nodes and edges are removed.
2. Mandatorydashed nodes and edges are made solid.
ACP Advanced Summer School on Global Constraints - Samos, Greece.
55
Part 2
Different Domain Representations Length-Lex BDD
Exercises
ACP Advanced Summer School on Global Constraints - Samos, Greece.
56
Cardinality constraints
Often a solution is a collection of sets of fixed cardinality E.g., sports scheduling
D(X) = [{},{1,2,3,4}] and Cardinality(X) = 2 No filtering
ACP Advanced Summer School on Global Constraints - Samos, Greece.
57
Lexicographic constraints
Symmetry breaking Enforce order within a set (mentioned) Enforce order between sets
Lexicographic constraints: X << Y: X is lexicographically smaller than Y.
D(X) = [{},{2,3,4,5}] and X >> {2,3,4} No filtering
ACP Advanced Summer School on Global Constraints - Samos, Greece.
58
Length-Lex Domains [Gervet, Van Hentenryck AAAI’06] Total order of sets
first by length, then lexicographically Example: a, b, c, ab, ac, bc, abc
Domain is an interval of this total order [{b}, {a,c}] = {{b}, {c}, {a,b}, {a,c}}
Filtering: Bounds consistency Closer to the scalar domain case E.g., the bounds are consistent
ACP Advanced Summer School on Global Constraints - Samos, Greece.
59
Cardinality and Lex Constraints D(X) = [{},{1,2,3,4}] and Cardinality(X) = 2
Filter to D(X)=[{1,2},{3,4}]
D(X) = [{2},{1,2,3}], D(Y)=[{},{2,3}]and X << Y Filter to D(X)=[{2},{1,3}] and D(Y)=[{3},{2,3}]
ACP Advanced Summer School on Global Constraints - Samos, Greece.
60
Other Constraints
D(X) = [{1,3,6,7},{2,4,6,7}] Constraint: {3,4} is a subset of X
The new domain: First successor of {1,3,6,7} that contains {3,4} First predecessor of {2,4,6,7} that contains {3,4}
ACP Advanced Summer School on Global Constraints - Samos, Greece.
61
Basic Successor Operation
U = {1,…,7} Succ({1,3,6,7}) = {1,4,5,6}
Location phase
Reconstruction phase
Linear time!
ACP Advanced Summer School on Global Constraints - Samos, Greece.
62
Complex Successor Operations Use variants of the location-reconstruction
algorithm Example:
U = {1,…,7} Find first successor of {1,3,6,7} that contains {3,4}
It’s {2,3,4,5}. Why?
For location phase: Subroutine LR(m,R,i,p)
I am in position i of m {R1…Rp-1 } are inside {m1 .. mi-1} can I reconstruct from i?
ACP Advanced Summer School on Global Constraints - Samos, Greece.
63
Location Phase
R is in m: nothing to do
No place left or too small:cannot reconstruct from iTry to see if you can reconstruct further
mi in Rp
ACP Advanced Summer School on Global Constraints - Samos, Greece.
64
Reconstruction Phase
start at i and need to cover {Rp,…}
Use elements from R when no more space
Use smallest possible elements
ACP Advanced Summer School on Global Constraints - Samos, Greece.
65
Length-Lex Domains
See other results in the AAAI’06 paper.
Brand-new idea, with many open problems In particular, global constraints/ filtering
ACP Advanced Summer School on Global Constraints - Samos, Greece.
66
Binary Decision Diagrams (BDDs) [Hawkins et al. - JAIR ’05] A completely different approach to set
domains BDD: A data structure that represents a
boolean function (set of sets) Accurate domain representation Exponential-size in the worst case Usually much smaller Used in other fields (e.g., formal verification)
ACP Advanced Summer School on Global Constraints - Samos, Greece.
67
Binary Decision Trees
x1
x2
x3 x3
x2
x3 x3
T T F T F F F T
ACP Advanced Summer School on Global Constraints - Samos, Greece.
68
Binary Decision Trees
x1
x2
x3 x3
x2
x3 x3
T T F T F F F T
ACP Advanced Summer School on Global Constraints - Samos, Greece.
69
Binary Decision Trees
x1
x2
x3
x2
x3 x3T
F T F F F T
ACP Advanced Summer School on Global Constraints - Samos, Greece.
70
Binary Decision Trees
x1
x2
x3
x2
x3 x3T
F T F F F T
ACP Advanced Summer School on Global Constraints - Samos, Greece.
71
Binary Decision Trees
x1
x2
x3
x2
x3T
F T
F
F T
ACP Advanced Summer School on Global Constraints - Samos, Greece.
72
Binary Decision Trees
x1
x2
x3
x2
x3T
F T
F
F T
ACP Advanced Summer School on Global Constraints - Samos, Greece.
73
Binary Decision Trees Diagrams
x1
x2
x3
x2
x3T
F T
F
F T
ACP Advanced Summer School on Global Constraints - Samos, Greece.
74
Binary Decision Trees Diagrams
x1
x2
x3
x2
T
F T
F
ACP Advanced Summer School on Global Constraints - Samos, Greece.
75
Binary Decision Trees Diagrams
x1
x2
x3
x2
FT
ACP Advanced Summer School on Global Constraints - Samos, Greece.
76
Operations on BDDs
Given BDDs B1 and B2 representing functions f1 and f2, we can compute a BDD for the result of basic boolean operations in linear or quadratic time in the sizes of the BDDs.
Example: The BDD for the negation of is the same, with values flipped at the leaves.
ACP Advanced Summer School on Global Constraints - Samos, Greece.
77
Operations on BDDs: 21 ff
Case 1: if B1=T or B2=T then return T
Case 2: if B1=F then return B2
Case 3: if B2=F then return B1
Given BDDs B1 and B2, compute a BDD for B1 v B2
ACP Advanced Summer School on Global Constraints - Samos, Greece.
78
Operations on BDDs:
x1
21 ff
L1 R1
x2
L2 R2
Case 3: if x1=x2 then return x1
L1v L2 R1v R2
B1 B2
Recursive
ACP Advanced Summer School on Global Constraints - Samos, Greece.
79
Operations on BDDs:
x1
21 ff
L1 R1
x2
L2 R2
Case 4: if x1<x2 then return x1
L1v B2 R1v B2
B1 B2
Recursive
ACP Advanced Summer School on Global Constraints - Samos, Greece.
80
Domains as Boolean Functions Let S be a subset of U={x1,…,xn}. B(S): a boolean formula describing S:
For a set of sets D,
iSi
iSi
xxAB)(
)()( SBDBDS
ACP Advanced Summer School on Global Constraints - Samos, Greece.
81
Constraints as Boolean Functions Sets v,w from universe {1,2,3} Boolean variables for v,w: <v1,v2,v3>, <w1,w2,w3>
The constraint is described by the boolean formula:
I.e., we can make a BDD for the constraint
wv
332211 wvwvwv
ACP Advanced Summer School on Global Constraints - Samos, Greece.
82
Filtering With BDDs
D(v) = {{1},{1,3},{2,3}}, D(w) = {{2},{1,2},{1,3}}
B(v) B(w)
v1
v2 v2
v3
FT
w1
w2 w2
w3
F
T
w3
ACP Advanced Summer School on Global Constraints - Samos, Greece.
83
Filtering With BDDs
BDD B(c) for the constraint wv
v1
F T
w1
v2
w2
v3
w3
ACP Advanced Summer School on Global Constraints - Samos, Greece.
84
Filtering With BDDs
Compute )()()( cBwBvB
v1
F T
w1
v2
w2
v3w3
w3
ACP Advanced Summer School on Global Constraints - Samos, Greece.
85
Filtering With BDDs
Project on {v1,v2,v3}
v1
F T
w1
v2
w2
v3w3
w3
v1
F T
v2
B’(v)
ACP Advanced Summer School on Global Constraints - Samos, Greece.
86
Filtering With BDDs
Project on {w1,w2,w3}
v1
F T
w1
v2
w2
v3w3
w3F T
B’(w)w1
w2
w3w3
ACP Advanced Summer School on Global Constraints - Samos, Greece.
87
Bibliography Bessiere, Hnich, Hebrard, Walsh. Disjoint, Partition and
Itersection Constraints for Set and Multiset Variables, CP’04.
Dooms, Deville, Dupont. CP(Graph): Introducing a Graph Computation Domain in Constraint Programming, CP’05.
Gervet. Constraints over structured domains, Handbook of Constraint Programming, Elsevier’06.
Gervet. Interval Propagation to Reason about Sets: Definition and Implementation of a Practical Language, Constraints ’97.
Gervet, Van Hentenryck. Length-Lex Ordering for Set CSPs, AAAI’06.
Gervet, Van Hentenryck. Private Communication, ’06
ACP Advanced Summer School on Global Constraints - Samos, Greece.
88
Bibliography – cont.
Hawkins, Lagoon, Stuckley. Solving Set Constraint Satisfaction Problems using ROBDDs, JAIR’05.
Kocjan, Kreuger. Filtering Methods for Symmetric Cardinality Constraint, CPAIOR’04.
Puget. PECOS – a High Level Constraint Programming Language, Spicis’92.
Sadler, Gervet. Global Filtering for the Disjointness Constraint on Fixed Cardinality Sets. IC-PARC techreport, ’04.
Walsh. Consistency and Propagation with Multiset Constraints: A Formal Viewpoint, CP’03.