Global Variables - PowerPoint PPT Presentation

About This Presentation
Title:

Global Variables

Description:

Value for each non-negated occurrence. Value for each negated occurrence ... Variable for each non-negated occurrence. Cardinality = # occurrences ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 89
Provided by: Irit5
Category:

less

Transcript and Presenter's Notes

Title: Global Variables


1
Global Variables
  • Irit Katriel
  • BRICS, University of Aarhus

2
Roles of Global Constraints
  • Syntactic Simplify models

3
Roles of Global Constraints
  • Speed up solving (by propagation)

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

5
Bin Packing
n items of different sizes s1,,sn
Bin size b
6
Bin Packing
Pack items in as few bins as possible
7
Bin Packing - Model 1
A variable for each item x1,,xn At most n
bins D(x1) 1,,nConstraints
Objective
8
Bin Packing - Model 1
A variable for each item x1,,xn At most n
bins D(x1) 1,,nConstraints
Objective
Complicated constraints
Symmetry breaking?
9
Bin Packing - Model 2
A set for each bin b1,,bn
D(bi) P(1,,n)Constra
ints Objective
10
Bin Packing - Model 2
A set for each bin b1,,bn
D(bi) P(1,,n)Constra
ints Objective
Simple constraints
Symmetry lex order among sets.
11
Shift Assignment (a generalization of GCC)
Shifts
1,2
1,1
2,3
0,1
1,3
1,2
0,1
0,2
1,2
1,1
1,1
1,2
1,3
0,1
Employees
Each employee is assigned a set of shifts!
12
Domain Representation
  • Enumerate all subsets
  • Pro Accurate (any domain can be expressed)
  • Con Exponential blowup
  • D(X) 1,2,3, 2,3, 3

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

14
Compact Set Representation
  • Collection of domain variables
  • x1,,xn, D(xi) Universe
  • AllDifferent(x1,,xn)
  • Break symmetry x1lt ltxn
  • 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

15
Set Bounds Puget92, Gervet97
The domain is specified by two sets
U (upper bound)
Set inclusion lattice
L (lower bound)
16
Compact Domain Representation
D(X) 1,2,3, 2,3, 3 Becomes
D(X) 3, 1,2,3
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 !
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

19
Filtering
Bound consistency Narrow the domain as much as
possible without losing any solutions
U (upper bound)
L (lower bound)
20
Filtering
Bound consistency Narrow the domain as much as
possible without losing any solutions
U (upper bound)
L (lower bound)
21
A Simple Example
Subset(S,X) (S is a subset of X) Where
D(S)LS,US, D(X)LX,UX
22
A Simple Example
Subset(S,X) (S is a subset of X) Where
D(S)LS,US, D(X)LX,UX
Running timeO(UsUx)
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)

24
Symmetric Cardinality Constraint
Kocjan, Kreuger CPAIOR 2004
1,2
1,1
2,3
0,1
Shifts
Employees
1,1
1,2
0,1
0,2
1,3

25
Symmetric Cardinality Constraint
Kocjan, Kreuger CPAIOR 2004
s
1,2
0,1
2,3
1,1
0,1
4,7
1,2
0,2
0,1
1,3

1,1
t
26
Symmetric Cardinality Constraint
Kocjan, Kreuger CPAIOR 2004
s
1,2
0,1
2,3
1,1
0,1
4,7
1,2
0,2
0,1
1,3

1,1
t
27
Symmetric Cardinality Constraint
Kocjan, Kreuger CPAIOR 2004
s
Residual graph
0,1
0,1
0,1
0,1
0,3
0,1
0,1
0,1
0,2

t
28
Symmetric Cardinality Constraint
Kocjan, Kreuger CPAIOR 2004
s
Strongly Connected Components
0,1
0,1
0,1
0,1
0,3
0,1
0,1
0,1
0,2

t
29
Symmetric Cardinality Constraint
Kocjan, Kreuger CPAIOR 2004
Non-flow edge between SCCs Infeasible.
s
0,1
0,1
0,1
0,1
0,3
0,1
0,1
0,1
0,2

t
30
Symmetric Cardinality Constraint
Kocjan, Kreuger CPAIOR 2004
Flow edge between SCCs Mandatory.
s
0,1
0,1
0,1
0,1
0,3
0,1
0,1
0,1
0,2

t
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

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

33
FixedCardinalityDisjoint(X1,,Xn,C)
  • Set Variables X1,,Xn
  • A constant C
  • Semantics

Sadler and Gevret, Techreport04 / Bessiere et
al. CP04 / Implemented in ILOG solver
34
FixedCardinalityDisjoint(X1,,Xn,C)
Special case of the symmetric cardinality
constraint
0,1
0,1
0,1
0,1
values
Set variables
C, C
C,C
C,C
C,C
C,C

35
FixedCardinalityDisjoint(X1,,Xn,C)
Actually, this is an upside-down GCC
C,C
C,C
C,C
C,C
C,C
Set variables
values
Domain variables
values
0,1
0,1
0,1
0,1

36
Multiset Variables Walsh CP03
  • Domain representations
  • Domain Variables
  • Same problems as with sets
  • Bounds Generalization of Gervet/Pugets 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)

37
Multiset Variables Walsh CP03
  • 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)

38
Multiset Variables Walsh CP03
  • 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

39
Set vs. Multiset Variables
  • Its all the same, but with repetitions. right?

40
FixedCardinalityDisjoint(X1,,Xn,C)
  • Its all the same, but with repetitions. right?

values
0, occi
Multiset variables
C, C
C,C
C,C
C,C
C,C
41
FixedCardinalityDisjoint(X1,,Xn,C)
  • Its all the same, but with repetitions. right?

0, maxocci
values
0, occi
Multiset variables
C, C
C,C
C,C
C,C
C,C
42
FixedCardinalityDisjoint(X1,,Xn,C)
  • Its all the same, but with repetitions. right?

0, maxocci
values
0, occi
Multiset variables
C, C
C,C
C,C
C,C
C,C
But how do we enforce disjointness?
43
FixedCardinalityDisjoint(X1,,Xn,C)
  • Its all the same, but with repetitions. right?

0, maxocci
values
0, occi
Multiset variables
C, C
C,C
C,C
C,C
C,C
But how do we enforce disjointness?
44
FixedCardinalityDisjoint(X1,,Xn,C)
  • Its all the same, but with repetitions. right?

0, maxocci
values
Flow becomes NP-Hard
0, occi
Multiset variables
C, C
C,C
C,C
C,C
C,C
But how do we enforce disjointness?
45
FixedCardinalityDisjoint(X1,,Xn,C)
  • Its all the same, but with repetitions. right?
  • Apparently not!
  • Thm Bessiere et al. CP04 It is NP-hard to
    check feasibility for FCDisjoint on multiset
    variables.

46
Reduction from 3-SAT
x11
x13
x23
x24
!x12
!x21
p3
p1
p2
p4
n1
n2
n3
n4
47
Reduction from 3-SAT
x11
x13
x23
x24
!x12
!x21
Value for each non-negated occurrence
Value for each negated occurrence
Variable for each clause Cardinality 1
Clause variables take one literal from each
clause
48
Reduction from 3-SAT
x11
x13
x23
x24
!x12
!x21
ni if xi is false
pi if xi is true
p3
p1
p2
p4
n1
n2
n3
n4
Variable for each non-negated occurrence Cardinali
ty occurrences
Variable for each negated occurrence Cardinality
occurrences
True and False value for each variable
49
Reduction from 3-SAT
x11
x13
x23
x24
!x12
!x21
p4
p3
p1
p2
n1
n2
n3
n4
Consistency variables Cardinality 1
50
Reduction from 3-SAT
X2x4 FALSE X1 X3 TRUE
x11
x13
x23
x24
!x12
!x21
p4
p3
p1
p2
n1
n2
n3
n4
0 times
51
Reduction from 3-SAT
Multisets allow us to encode choices!
x11
x13
x23
x24
!x12
!x21
p4
p3
p1
p2
n1
n2
n3
n4
52
Graph Variables Dooms et al. CP05
Graph variable Two set variables, V and E with
Conceptually
U (upper bound)
graph inclusion lattice
L (lower bound)
53
Filtering With Graph Variables
  • Useless dashed nodes and edges are removed.
  • 2. Mandatorydashed nodes and edges are made
    solid.

54
(No Transcript)
55
Part 2
  • Different Domain Representations
  • Length-Lex
  • BDD
  • Exercises

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

57
Lexicographic constraints
  • Symmetry breaking
  • Enforce order within a set (mentioned)
  • Enforce order between sets
  • Lexicographic constraints
  • X ltlt Y X is lexicographically smaller than Y.
  • D(X) ,2,3,4,5 and X gtgt 2,3,4
  • No filtering

58
Length-Lex Domains Gervet,
Van Hentenryck AAAI06
  • 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

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,3and X
    ltlt Y
  • Filter to D(X)2,1,3 and D(Y)3,2,3

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

61
Basic Successor Operation
  • U 1,,7
  • Succ(1,3,6,7) 1,4,5,6

Linear time!
Location phase
Reconstruction phase
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
  • Its 2,3,4,5. Why?
  • For location phase
  • Subroutine LR(m,R,i,p)
  • I am in position i of m
  • R1Rp-1 are inside m1 .. mi-1
  • can I reconstruct from i?

63
Location Phase
R is in m nothing to do
No place left or too small cannot reconstruct
from i
Try to see if you can reconstruct further
mi in Rp
64
Reconstruction Phase
start at i and need to cover Rp,
Use smallest possible elements
Use elements from R when no more space
65
Length-Lex Domains
  • See other results in the AAAI06 paper.
  • Brand-new idea, with many open problems
  • In particular, global constraints/ filtering

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)

67
Binary Decision Trees
x1
x2
x2
x3
x3
x3
x3
T
T
F
T
F
F
F
T
68
Binary Decision Trees
x1
x2
x2
x3
x3
x3
x3
T
T
F
T
F
F
F
T
69
Binary Decision Trees
x1
x2
x2
x3
x3
x3
T
F
T
F
F
F
T
70
Binary Decision Trees
x1
x2
x2
x3
x3
x3
T
F
T
F
F
F
T
71
Binary Decision Trees
x1
x2
x2
x3
x3
T
F
F
T
F
T
72
Binary Decision Trees
x1
x2
x2
x3
x3
T
F
F
T
F
T
73
Binary Decision Trees Diagrams
x1
x2
x2
x3
x3
T
F
F
T
F
T
74
Binary Decision Trees Diagrams
x1
x2
x2
x3
T
F
F
T
75
Binary Decision Trees Diagrams
x1
x2
x2
x3
F
T
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.

77
Operations on BDDs
Given BDDs B1 and B2, compute a BDD for B1 v B2
Case 1 if B1T or B2T then return T Case 2 if
B1F then return B2 Case 3 if B2F then return
B1
78
Operations on BDDs
B1
B2
x1
x2
L1
R1
L2
R2
x1
Case 3 if x1x2 then return
L1v L2
R1v R2
Recursive
79
Operations on BDDs
B1
B2
x1
x2
L1
R1
L2
R2
x1
Case 4 if x1ltx2 then return
L1v B2
R1v B2
Recursive
80
Domains as Boolean Functions
  • Let S be a subset of Ux1,,xn.
  • B(S) a boolean formula describing S
  • For a set of sets D,

81
Constraints as Boolean Functions
  • Sets v,w from universe 1,2,3
  • Boolean variables for v,w ltv1,v2,v3gt, ltw1,w2,w3gt
  • The constraint is described by
    the boolean formula
  • I.e., we can make a BDD for the constraint

82
Filtering With BDDs
  • D(v) 1,1,3,2,3, D(w)
    2,1,2,1,3
  • B(v) B(w)

w1
v1
w2
w2
v2
v2
w3
w3
v3
T
T
F
F
83
Filtering With BDDs
  • BDD B(c) for the constraint

v1
w1
v2
w2
v3
w3
F
T
84
Filtering With BDDs
  • Compute

v1
w1
v2
w2
v3
w3
w3
F
T
85
Filtering With BDDs
  • Project on v1,v2,v3

v1
w1
B(v)
v1
v2
w2
v2
v3
w3
w3
F
T
F
T
86
Filtering With BDDs
  • Project on w1,w2,w3

B(w)
v1
w1
w1
w2
v2
w2
w3
v3
w3
w3
w3
F
T
F
T
87
Bibliography
  • Bessiere, Hnich, Hebrard, Walsh. Disjoint,
    Partition and Itersection Constraints for Set and
    Multiset Variables, CP04.
  • Dooms, Deville, Dupont. CP(Graph) Introducing a
    Graph Computation Domain in Constraint
    Programming, CP05.
  • Gervet. Constraints over structured domains,
    Handbook of Constraint Programming, Elsevier06.
  • 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, AAAI06.
  • Gervet, Van Hentenryck. Private Communication, 06

88
Bibliography cont.
  • Hawkins, Lagoon, Stuckley. Solving Set Constraint
    Satisfaction Problems using ROBDDs, JAIR05.
  • Kocjan, Kreuger. Filtering Methods for Symmetric
    Cardinality Constraint, CPAIOR04.
  • Puget. PECOS a High Level Constraint
    Programming Language, Spicis92.
  • 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, CP03.
Write a Comment
User Comments (0)
About PowerShow.com