280 likes | 372 Views
Two Set-Constraints For Modeling and Efficiency. Willem-Jan van Hoeve Ashish Sabharwal Carnegie Mellon Univ. Cornell Univ. ModRef workshop at CP-07 Sept 23, 2007. CSPs, Global Constraints. CSP: Given variables x, y, z, … with domains D(x), D(y), D(z), …
E N D
Two Set-Constraints For Modeling and Efficiency Willem-Jan van Hoeve Ashish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23, 2007
CSPs, Global Constraints CSP: Given variables x, y, z, … with domains D(x), D(y), D(z), … and constraints over variables, find variable values such that all constraints are satisfied. Typical single-valued variable domains: discrete or continuous sets, e.g. {1,2,3,4,5}, {Su,Mo,Tu,…,Sa}, [0,1] Key to the success of CP: many useful global constraints with efficient, non-trivial filtering/propagation • Very different from, say, SAT or integer programming ModRef Workshop at CP-07
Constraints on Set Variables Set variable: domain values are sets E.g. domain(S) = {{1,2}, {1,3},{2,3},{1,2,3}} Arise naturally in many settings, e.g.A graph (V,E) is a set of vertices and a set of edges(representation of Dooms-Katriel ’06 for MST) A set of jobs to be scheduled on a set of machinesA set of packages to be moved using a set of trucks Often “grounded-down” to single-valued variables,especially in SAT and integer programming ModRef Workshop at CP-07
Set Variables: The Challenge A constraint on a single set variable may capture a structure that must otherwise be represented by a global constraint on multiple single-valued variables • Filtering constraints on a singleset may be as complex as global filtering on multiple single-valued variables Known that combining two overlapping global constraints can easily make them NP-complete • Implication: constraints on multiple set variables can be significantly harder to filter ModRef Workshop at CP-07
Our Contribution Efficient filtering algorithms establishing bounds consistency for set-constraints sum-free, pair-atmost1 Experiments with the Schur Number problem and the Social Golfer problem Message: in addition to providing modeling convenience, set constraints can help • Significantly reduce memory requirements • Increase efficiency through better filtering ModRef Workshop at CP-07
Constraints, Filtering, Propagation • Variables x, y, z, … with domains D(x), D(y), D(z), …E.g. D(x) = {1,2,3,4,5} • Constraints: e.g. x < max(y,z), yz, alldiff(x,y,z), … • Key step in constraint programming: Filtering • Given current variable domains and constraint C, remove domain values that do not belong to any solution to C • Note: considers C in isolation, thus not too difficult • Domain-delta(x) : change in D(x) between two successive filtering events ModRef Workshop at CP-07
Good Filtering Algorithm • Is efficient: usually called at every node of the search tree where relevant domains changed • Makes C domain consistent: provably removes all variable values that do not belong to a solution to C -- all remaining values can be extended to a solution • Is incremental: re-uses computation from parent nodes in the search tree, e.g., thru domain-deltas Goal: find efficient (near-linear time), incremental filtering algorithms that achieve domain consistency ModRef Workshop at CP-07
Set Variables: Representation If elements of S come, e.g., from {1, 2, …, k}, |D(S)| = 2k • Naïve domain representation too costly “Interval” representation: [L(S), U(S)] • Semantics: D(S) = {s | L(S) s U(S)} E.g. L(S) = {2,3}, U(S) = {1,…,k} \ {5} all subsets containing 2 and 3 but not 5 • All elements of L(S) must be in S --- lower bound No element not in U(S) may be in S --- upper bound • Domain-delta: provides L(S) and U(S) (Alternative: length-lex representation) ModRef Workshop at CP-07
Bounds Consistency Consistency notion for constraints on set variables(using the interval representation) : C(S1, S2, …, Sn) is bounds consistent if • x L(Si) iff x Si for all solutions to C • x U(Si) iff x Si for some solution to C • Note: L(Si) and U(Si) themselves may not satisfy C • Partial filtering: no bounds consistency Goal: establish bounds consistency efficiently “roughly speaking” ModRef Workshop at CP-07
Part 1: The sum-free constraint Application: The Schur Number problem Filtering algorithm: fairly straightforward Advantage: natural model enormous space savings! can solve problems couldn’t be modeled in 2GB
sum-free(S) Variable : set S with positive integer elements Constraint: i, j S i+j S Note: j may equal i, so that i S 2i S Filtering algorithm, establishing bounds consistency: for i L(S), for j L(S) remove i+j and |ij| from U(S) Amortizedcomplexity: O(n2) for any path from root to leaf (assuming linear-time element listing for L(S) and L(S), and constant-time deletion for U(S) ) ModRef Workshop at CP-07
Experiments: Schur Number Given k 0, Schur number of k is the largest integer n s.t. {1, 2, …, n} can be partitioned into k sum-free subsets. Decision problem: given k, n, is such a partition possible? Model #1: integer vars x1, …, xn with domain [k] • O(kn2) constraints: (xi = s) and (xj = s) (xi+j s) Model #2: set vars S1, …, Sk with domain [, [n]] • k+1 constraints: isum-free(Si), partition(S1,…,Sk, [n]) • Also added shadow integer vars of Model #1 to better control the search heuristic {1, …, k} ModRef Workshop at CP-07
Experiments: Schur Number schur-k-n Significantly reduced memory requirement (esp. n > 500) Often 4x speed-up Using ILOG Solver 6.3 ModRef Workshop at CP-07
Part 2: The atmost1 constraint Application: The Social Golfer problem Filtering algorithm: in general: complete filtering NP-hard (known) for pair-atmost1: constant time algorithm (after preprocessing) Advantage: efficiency thru better filtering
atmost1(S1, …, Sn, c1, …, cn) [Sadler-Gervet ’01] Variables: • Sets S1, S2, …, Snsets of integers • Integers c1, c2, …, cncardinalities Constraints: • |Si| = ci1 ≤ i ≤ n • |Si Sj| ≤ 1 1 ≤ i < j ≤ n Example: D(S1) = [{1,2}, {1,2,3,5,6}], D(S2) = [{3}, {1,2,3,4}], |S1| = |S2| = c1 = c2 = 3 (“softer alldifferent”) Solutions:S1 = {1,2,5} or {1,2,6}S2 = {1,3,4} or {2,3,4} ModRef Workshop at CP-07
Filtering atmost1 • NP-complete in general[Bessiere-Hebrard-Hnich-Walsh ’04] • Poly-time partial filtering algorithm known[Sadler-Gervet ’01] • Achieves partial filtering even for atmost1(S1,S2,c1,c2) How hard is the problem for two sets, i.e. pair-atmost1? • We propose BC-FilterPairAtmost1 for bounds consistency • Uses somewhat complex data structures and reasoning • But eventual filtering steps very simple! ModRef Workshop at CP-07
pair-atmost1: Standard Decomposition Implement as three separate standard set constraints: |S1| = c1, |S2| = c2, |S1 S2| ≤ 1 Disadvantage: • Treats cardinality and intersection constraints separately • Does not achieve bounds consistency(e.g. no element ever added to L(Si) ) Example: D(S1) = [{1,2}, {1,2,3,5,6}], D(S2) = [{3}, {1,2,3,4}], ci = 3 • Standard decomposition does not filter anything • However, could have concluded 4 L(S2) and 3 U(S1) ModRef Workshop at CP-07
pair-atmost1: Bounds Consistency • L1 : elements already in S1 • U1 : elements available to be added to S1 S1 : L1 = L(S1) U1 = U(S1) \ L(S1) S2 : L2 = L(S2) U2 = U(S2) \ L(S2) ModRef Workshop at CP-07
Partitioning into Classes 9 classes of elements • E.g. if x U1L2 must be removed from U(S1) then all y U1L2 must be removed from U(S1) • Need to process only a constant number of classes!Options: add class to L(Si) or remove class from U(Si) S1 : L1L2 L1rest U1L2 U1U2 U1only = S2 : L1L2 L2rest U2L1 U2U1 U2only Key observation: all elements within a classare indistinguishable w.r.t. pair-atmost1 ModRef Workshop at CP-07
The Filtering Process Implicitly go thru every “kind” of solution, maintaining two flags for each class T: • T.can-have : solution with some x T in Si • T.not-necessary : solution without needing all of T in Si • Initialize flags to False • Implicitly process all solutions • If T.can-have is still False, remove T from U(Si) • If T.not-necessary is still False, add T to L(Si) (typo on page 7 of paper) ModRef Workshop at CP-07
Updating Flags: “Case0” Case0: S1 and S2 do not share any element (other cases easily reduce to Case0 on a smaller problem) • Note: cannot use elements from U1L2 and U2L1 • Compute “slacks” • slack1 = (|U1only| + |U1U2|) (c1 |L1|) • Similarly slack2 • slack3 = (|U1only|+|U2only|+|U1U2|) (c1+c2 |L1|+|L2|) elements needed elements available ModRef Workshop at CP-07
Updating Flags: “Case0” If solution exists, • it can always use U1only, U2only (never hurts) • it cannot use U1L2, U2L1 at all (no shared elements) Therefore, set • U1only.can-have = True U2only.can-have = True • U1L2.not-necessary = True U2L1.not-necessary = True Further, e.g., if slack1 > 0, • U2U1.can-have = True U1U2.not-necessary = True (A few other similar updates.) There exists a solution in Case0 iffslack1 0, slack2 0, and slack3 0 ModRef Workshop at CP-07
BC-FilterPairAtmost1 Processing 9 classes takes constant time • Don’t need all elements of U1L2, etc. --- only their cardinalities and a representative element! • Eventual filtering of elements, of course, takes time proportional to class size Filtering complexity: O(n + k log n) • n : integer domain size of elements • k : #elements added to L(Si) or removed from U(Si) Stronger amortized analysis using domain-deltas: • O(n log n) combined for any path from root to leaf ModRef Workshop at CP-07
Experiments: Social Golfer golf-g-s-w: for each of wweeks, partition n golfers into ggroups of sizes each (gs = n), such that no two golfers are in the same group more than once Example: 1 2 3 4 5 6 7 8 9 week 1 1 4 7 2 5 8 3 6 9 week 2 1 5 9 2 6 7 3 4 8 week 3 Well-studied problem: surprisingly challenging! • Techniques based on symmetry, local search • Our work: orthogonal to these --- improve basic filtering [prob010 in CSPLib] ModRef Workshop at CP-07
Set-Based Model One set variable for each group Sij (week i, group j) Constraints: partition(Si1, Si2, …, Sig, [n]) week i atmost1(Sij, Skl, s, s) weeks ik; groups j,l For efficiency, we also have shadow integer variables xia with domain [g] for each week i and golfer a • Use xia’s to control search strategy • Add a redundant global cardinality constraint (gcc): each group in [g] must be assigned to exactly s xia’s ModRef Workshop at CP-07
Results: Social Golfer ModRef Workshop at CP-07 Using ILOG Solver 6.3
Conclusion • Discussed sum-free(S) and pair-atmost1(S1,S2,c1,c2) • Results generalize to atmostk and to k sets, for constant k • Demonstrated that set constraints not only offer convenience in modeling, they can also • Significantly reduce memory requirements • Provide much faster solutions • Observed that efficiently filtering set constraints to bounds consistency can be somewhat tricky, but does pay off ModRef Workshop at CP-07