Global Variables Irit Katriel BRICS University of Aarhus
Global Variables Irit Katriel BRICS, University of Aarhus ACP Advanced Summer School on Global Constraints - Samos, Greece. 1
Roles of Global Constraints n Syntactic: Simplify models ACP Advanced Summer School on Global Constraints - Samos, Greece. 2
Roles of Global Constraints n Speed up solving (by propagation) ACP Advanced Summer School on Global Constraints - Samos, Greece. 3
Global Variables n Assigned structured data, e. g. , q q n A set of scalar values A graph A function … Same roles as global constraints q q Simplify models Improve propagation ACP Advanced Summer School on Global Constraints - Samos, Greece. 4
Bin Packing n items of different sizes: s 1, …, sn ACP Advanced Summer School on Global Constraints - Samos, Greece. Bin size: b 5
Bin Packing Pack items in as few bins as possible ACP Advanced Summer School on Global Constraints - Samos, Greece. 6
Bin Packing - Model 1 A variable for each item: x 1, …, xn At most n bins: D(x 1) = {1, …, n} Constraints: Objective: ACP Advanced Summer School on Global Constraints - Samos, Greece. 7
Bin Packing - Model 1 A variable for each item: x 1, …, xn At most n bins: D(x 1) = {1, …, n} Constraints: Complicated constraints Symmetry breaking? Objective: ACP Advanced Summer School on Global Constraints - Samos, Greece. 8
Bin Packing - Model 2 A set for each bin: b 1, …, bn D(bi) = P({1, …, n}) Constraints: Objective: ACP Advanced Summer School on Global Constraints - Samos, Greece. 9
Bin Packing - Model 2 A set for each bin: b 1, …, bn D(bi) = P({1, …, n}) Constraints: Simple constraints Symmetry: lex order among sets. Objective: ACP Advanced Summer School on Global Constraints - Samos, Greece. 10
Shift Assignment (a generalization of GCC) Shifts [1, 2] [1, 1] [0, 1] [2, 3] [0, 2] [0, 1] [1, 3] [1, 2] [1, 1] [0, 1] Employees Each employee is assigned a set of shifts! ACP Advanced Summer School on Global Constraints - Samos, Greece. 11
Domain Representation n Enumerate all subsets q q Pro: Accurate (any domain can be expressed) Con: Exponential blowup D(X)= { {1, 2, 3}, {3} } ACP Advanced Summer School on Global Constraints - Samos, Greece. 12
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. 13
Compact Set Representation n Collection of domain variables q q q x 1, …, xn, D(xi) = Universe All. Different(x 1, …, xn) Break symmetry: x 1< … <xn If cardinality is unknown, add a dummy value (and replace All. Different by NValue) Pro: Compact (in terms of space requirements) Con: Inaccurate, clumsy n Set variables are an abstraction of this representation ACP Advanced Summer School on Global Constraints - Samos, Greece. 14
Set Bounds [Puget’ 92, Gervet’ 97] The domain is specified by two sets: U (upper bound) Set inclusion lattice L (lower bound) ACP Advanced Summer School on Global Constraints - Samos, Greece. 15
Compact Domain Representation D(X)= { {1, 2, 3}, {3} } Becomes D(X) = [ {3}, {1, 2, 3} ] ACP Advanced Summer School on Global Constraints - Samos, Greece. 16
Compact Domain Representation D(X)= { {1, 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. 17
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. 18
Filtering Bound consistency: Narrow the domain as much as possible without losing any solutions U (upper bound) L (lower bound) ACP Advanced Summer School on Global Constraints - Samos, Greece. 19
Filtering Bound consistency: Narrow the domain as much as possible without losing any solutions U (upper bound) L (lower bound) ACP Advanced Summer School on Global Constraints - Samos, Greece. 20
A Simple Example Subset(S, X) (S is a subset of X) Where D(S)=[LS, US], D(X)=[LX, UX] 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] Running time: O(|Us|+|Ux|) ACP Advanced Summer School on Global Constraints - Samos, Greece. 22
Lattice Domain Representation n Pro q Compact (space and specification) n n Filtering time depends on size of representation and not on cardinality of domain Con q Not all domains can be expressed accurately n Partial filtering (only bounds) ACP Advanced Summer School on Global Constraints - Samos, Greece. 23
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] ACP Advanced Summer School on Global Constraints - Samos, Greece. [1, 3] 24
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004] s [1, 2] [1, 1] [2, 3] [0, 1] [4, 7] [1, 2] [0, 1] [1, 1] [0, 2] [1, 3] t ACP Advanced Summer School on Global Constraints - Samos, Greece. 25
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004] s [1, 2] [1, 1] [2, 3] [0, 1] [4, 7] [1, 2] [0, 1] [1, 1] [0, 2] [1, 3] t ACP Advanced Summer School on Global Constraints - Samos, Greece. 26
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004] s Residual graph: [0, 1] [0, 3] [0, 1] [0, 2] t ACP Advanced Summer School on Global Constraints - Samos, Greece. 27
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004] Strongly Connected Components: s [0, 1] [0, 3] [0, 1] [0, 2] t ACP Advanced Summer School on Global Constraints - Samos, Greece. 28
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004] Non-flow edge between SCCs: Infeasible. s [0, 1] [0, 3] [0, 1] [0, 2] t ACP Advanced Summer School on Global Constraints - Samos, Greece. 29
Symmetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004] Flow edge between SCCs: Mandatory. s [0, 1] [0, 3] [0, 1] [0, 2] t ACP Advanced Summer School on Global Constraints - Samos, Greece. 30
Symetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004] Algorithm: n Connect each employee with possible shifts q q 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. 31
Symetric Cardinality Constraint [Kocjan, Kreuger – CPAIOR 2004] Algorithm: n Connect employee with all possible shifts q q n n 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 q Non-flow edges are deleted n q Inconsistency if one of them was mandatory Flow edges become mandatory n If they were not already ACP Advanced Summer School on Global Constraints - Samos, Greece. 32
Fixed. Cardinality. Disjoint(X 1, …, Xn, C) n Set Variables X 1, …, Xn A constant C n Semantics: n [Sadler and Gevret, Techreport’ 04 / Bessiere et al. CP’ 04 / Implemented in ILOG solver] ACP Advanced Summer School on Global Constraints - Samos, Greece. 33
Fixed. Cardinality. Disjoint(X 1, …, Xn, C) Special case of the symmetric cardinality constraint: [0, 1] values Set variables [C, C] ACP Advanced Summer School on Global Constraints - Samos, Greece. [C, C] 34
Fixed. Cardinality. Disjoint(X 1, …, Xn, C) Actually, this is an upside-down GCC: Set variables [C, C] [C, C] values [0, 1] ACP Advanced Summer School on Global Constraints - Samos, Greece. [0, 1] Domain variables 35
Multiset Variables [Walsh CP’ 03] n Domain representations: q Domain Variables n q Bounds: Generalization of Gervet/Puget’s set intervals n q Same problems as with sets D(X)=[L, U] where L and U are multisets Occurrence representation n D(X)=(a, {0, 1}), (b, {3, 4}), (c, {2, 5}) ACP Advanced Summer School on Global Constraints - Samos, Greece. 36
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}] q Includes {a, a} Occurrence: D(X)=[(a, {1, 3})] ACP Advanced Summer School on Global Constraints - Samos, Greece. 37
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. 38
Set vs. Multiset Variables It’s all the same, but with repetitions. right? ACP Advanced Summer School on Global Constraints - Samos, Greece. 39
Fixed. Cardinality. Disjoint(X 1, …, Xn, C) It’s all the same, but with repetitions. right? values Multiset variables [ 0, occi ] [C, C] ACP Advanced Summer School on Global Constraints - Samos, Greece. [C, C] 40
Fixed. Cardinality. Disjoint(X 1, …, Xn, C) It’s all the same, but with repetitions. right? [ 0, max{occi} ] values [ 0, occi ] Multiset variables [C, C] ACP Advanced Summer School on Global Constraints - Samos, Greece. [C, C] 41
Fixed. Cardinality. Disjoint(X 1, …, Xn, C) It’s all the same, but with repetitions. right? [ 0, max{occi} ] values [ 0, occi ] Multiset variables [C, C] [C, C] But how do we enforce disjointness? ACP Advanced Summer School on Global Constraints - Samos, Greece. 42
Fixed. Cardinality. Disjoint(X 1, …, Xn, C) It’s all the same, but with repetitions. right? [ 0, max{occi} ] values { 0, occi } Multiset variables [C, C] [C, C] But how do we enforce disjointness? ACP Advanced Summer School on Global Constraints - Samos, Greece. 43
Fixed. Cardinality. Disjoint(X 1, …, Xn, C) It’s all the same, but with repetitions. right? [ 0, max{occi} ] values { 0, occei s} low Multiset variables [C, C] [C, C] F m o c be Hard P N But how do we enforce disjointness? ACP Advanced Summer School on Global Constraints - Samos, Greece. 44
Fixed. Cardinality. Disjoint(X 1, …, 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. 45
Reduction from 3 -SAT Value Set variable x 11 x 13 x 23 p 1 x 24 p 2 !x 12 p 3 p 4 n 1 n 2 ACP Advanced Summer School on Global Constraints - Samos, Greece. n 3 !x 21 n 4 46
Reduction from 3 -SAT Value Set variable x 11 x 13 x 23 Value for each non-negated occurrence x 24 !x 12 Variable for each clause !x 21 Value for each negated occurrence Cardinality = 1 Clause variables ”take” one literal from each clause ACP Advanced Summer School on Global Constraints - Samos, Greece. 47
Reduction from 3 -SAT Value Set variable x 11 x 13 x 24 !x 12 !x 21 ni if xi is false pi if xi is true p 1 p 2 p 3 Variable for each nonnegated occurrence Cardinality = # occurrences p 4 n 1 n 2 ”True” and ”False” value for each variable ACP Advanced Summer School on Global Constraints - Samos, Greece. n 3 n 4 Variable for each negated occurrence Cardinality = # occurrences 48
Reduction from 3 -SAT Value Set variable x 11 x 13 x 23 p 1 x 24 p 2 !x 12 p 3 p 4 n 1 n 2 n 3 !x 21 n 4 Consistency variables Cardinality = 1 ACP Advanced Summer School on Global Constraints - Samos, Greece. 49
Reduction from 3 -SAT X 2=x 4 =FALSE x 11 x 13 x 23 p 1 Value Set variable X 1= X 3 =TRUE x 24 p 2 !x 12 p 3 p 4 n 1 n 2 ACP Advanced Summer School on Global Constraints - Samos, Greece. n 3 !x 21 n 4 ” 0 times” 50
Reduction from 3 -SAT Value Set variable Multisets allow us to encode choices! x 11 x 13 x 23 p 1 x 24 p 2 !x 12 p 3 p 4 n 1 n 2 ACP Advanced Summer School on Global Constraints - Samos, Greece. n 3 !x 21 n 4 51
Graph Variables [Dooms et al. CP’ 05] Graph variable: Two set variables, V and E with Conceptually: U (upper bound) graph inclusion lattice L (lower bound) ACP Advanced Summer School on Global Constraints - Samos, Greece. 52
Filtering With Graph Variables 1. Useless dashed nodes and edges are removed. 2. 2. Mandatory dashed nodes and edges are made solid. ACP Advanced Summer School on Global Constraints - Samos, Greece. 53
ACP Advanced Summer School on Global Constraints - Samos, Greece. 54
Part 2 n Different Domain Representations q q n Length-Lex BDD Exercises ACP Advanced Summer School on Global Constraints - Samos, Greece. 55
Cardinality constraints n Often a solution is a collection of sets of fixed cardinality q n E. g. , sports scheduling D(X) = [{}, {1, 2, 3, 4}] and Cardinality(X) = 2 q No filtering ACP Advanced Summer School on Global Constraints - Samos, Greece. 56
Lexicographic constraints n Symmetry breaking q q n Lexicographic constraints: q n Enforce order within a set (mentioned) Enforce order between sets X << Y: X is lexicographically smaller than Y. D(X) = [{}, {2, 3, 4, 5}] q and X >> {2, 3, 4} No filtering ACP Advanced Summer School on Global Constraints - Samos, Greece. 57
Length-Lex Domains [Gervet, Van Hentenryck AAAI’ 06] n Total order of sets q first by length, then lexicographically n n Domain is an interval of this total order q n Example: a, b, c, ab, ac, bc, abc [{b}, {a, c}] = {{b}, {c}, {a, b}, {a, c}} Filtering: Bounds consistency q q Closer to the scalar domain case E. g. , the bounds are consistent ACP Advanced Summer School on Global Constraints - Samos, Greece. 58
Cardinality and Lex Constraints n D(X) = [{}, {1, 2, 3, 4}] and Cardinality(X) = 2 q n Filter to D(X)=[{1, 2}, {3, 4}] D(X) = [{2}, {1, 2, 3}], D(Y)=[{}, {2, 3}] and X << Y q Filter to D(X)=[{2}, {1, 3}] and D(Y)=[{3}, {2, 3}] ACP Advanced Summer School on Global Constraints - Samos, Greece. 59
Other Constraints n D(X) = [{1, 3, 6, 7}, {2, 4, 6, 7}] Constraint: {3, 4} is a subset of X n The new domain: n q q 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. 60
Basic Successor Operation n n U = {1, …, 7} Succ({1, 3, 6, 7}) = {1, 4, 5, 6} ! e m r ti a e n i L Location phase Reconstruction phase ACP Advanced Summer School on Global Constraints - Samos, Greece. 61
Complex Successor Operations n n Use variants of the location-reconstruction algorithm Example: q q U = {1, …, 7} Find first successor of {1, 3, 6, 7} that contains {3, 4} n n It’s {2, 3, 4, 5}. Why? For location phase: q Subroutine LR(m, R, i, p) n n n I am in position i of m {R 1…Rp-1 } are inside {m 1. . mi-1} can I reconstruct from i? ACP Advanced Summer School on Global Constraints - Samos, Greece. 62
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 ACP Advanced Summer School on Global Constraints - Samos, Greece. 63
Reconstruction Phase start at i and need to cover {Rp, …} Use smallest possible elements Use elements from R when no more space ACP Advanced Summer School on Global Constraints - Samos, Greece. 64
Length-Lex Domains n See other results in the AAAI’ 06 paper. n Brand-new idea, with many open problems q In particular, global constraints/ filtering ACP Advanced Summer School on Global Constraints - Samos, Greece. 65
Binary Decision Diagrams (BDDs) [Hawkins et al. - JAIR ’ 05] n n A completely different approach to set domains BDD: A data structure that represents a boolean function (set of sets) q q 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. 66
Binary Decision Trees x 1 x 2 x 3 T F T x 3 F ACP Advanced Summer School on Global Constraints - Samos, Greece. F T 67
Binary Decision Trees x 1 x 2 x 3 T F T x 3 F ACP Advanced Summer School on Global Constraints - Samos, Greece. F T 68
Binary Decision Trees x 1 x 2 x 3 T F T x 3 F ACP Advanced Summer School on Global Constraints - Samos, Greece. F T 69
Binary Decision Trees x 1 x 2 x 3 T F T x 3 F ACP Advanced Summer School on Global Constraints - Samos, Greece. F T 70
Binary Decision Trees x 1 x 2 x 3 T F x 3 F T ACP Advanced Summer School on Global Constraints - Samos, Greece. F T 71
Binary Decision Trees x 1 x 2 x 3 T F x 3 F T ACP Advanced Summer School on Global Constraints - Samos, Greece. F T 72
Binary Decision Trees Diagrams x 1 x 2 x 3 T F x 3 F T ACP Advanced Summer School on Global Constraints - Samos, Greece. F T 73
Binary Decision Trees Diagrams x 1 x 2 x 3 T F F T ACP Advanced Summer School on Global Constraints - Samos, Greece. 74
Binary Decision Trees Diagrams x 1 x 2 x 3 T F ACP Advanced Summer School on Global Constraints - Samos, Greece. 75
Operations on BDDs n Given BDDs B 1 and B 2 representing functions f 1 and f 2, we can compute a BDD for the result of basic boolean operations in linear or quadratic time in the sizes of the BDDs. n 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. 76
Operations on BDDs: Given BDDs B 1 and B 2, compute a BDD for B 1 v B 2 Case 1: if B 1=T or B 2=T then return T Case 2: if B 1=F then return B 2 Case 3: if B 2=F then return B 1 ACP Advanced Summer School on Global Constraints - Samos, Greece. 77
Operations on BDDs: B 1 x 1 L 1 B 2 x 2 R 1 L 2 Case 3: if x 1=x 2 then return e v i rs u c e R L 1 v L 2 ACP Advanced Summer School on Global Constraints - Samos, Greece. R 2 x 1 R 1 v R 2 78
Operations on BDDs: B 1 x 1 L 1 B 2 x 2 R 1 L 2 Case 4: if x 1<x 2 then return e v i rs u c e R L 1 v B 2 ACP Advanced Summer School on Global Constraints - Samos, Greece. R 2 x 1 R 1 v B 2 79
Domains as Boolean Functions n Let S be a subset of U={x 1, …, xn}. B(S): a boolean formula describing S: n For a set of sets D, n ACP Advanced Summer School on Global Constraints - Samos, Greece. 80
Constraints as Boolean n Sets v, w from universe {1, 2, 3} Functions n Boolean variables for v, w: <v 1, v 2, v 3>, <w 1, w 2, w 3> n The constraint boolean formula: n I. e. , we can make a BDD for the constraint is described by the ACP Advanced Summer School on Global Constraints - Samos, Greece. 81
Filtering With BDDs n D(v) = {{1}, {1, 3}, {2, 3}}, B(v) D(w) = {{2}, {1, 3}} B(w) v 1 v 2 w 1 w 2 v 2 w 3 v 3 F w 3 T T ACP Advanced Summer School on Global Constraints - Samos, Greece. F 82
Filtering With BDDs n BDD B(c) for the constraint v 1 w 1 v 2 w 2 v 3 w 3 F ACP Advanced Summer School on Global Constraints - Samos, Greece. T 83
Filtering With BDDs n Compute v 1 w 1 v 2 w 2 v 3 w 3 F T Advanced Summer School on Global ACP Constraints - Samos, Greece. 84
Filtering With BDDs n Project on {v 1, v 2, v 3} v 1 w 1 B’(v) v 2 w 2 v 3 w 3 F v 1 F T Advanced Summer School on Global ACP Constraints - Samos, Greece. T 85
Filtering With BDDs n Project on {w 1, w 2, w 3} v 1 B’(w) w 1 w 2 v 2 w 2 v 3 w 3 w 3 F F T Advanced Summer School on Global ACP Constraints - Samos, Greece. T 86
Bibliography n n n 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. 87
Bibliography – cont. n n n 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. ACP Advanced Summer School on Global Constraints - Samos, Greece. 88
- Slides: 88