two set-constraints for modeling and efficiency willem-jan van hoeveashish sabharwal carnegie mellon...

28
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

Post on 21-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Two Set-Constraints For Modeling and Efficiency

Willem-Jan van Hoeve Ashish Sabharwal

Carnegie Mellon Univ. Cornell Univ.

ModRef workshop at CP-07Sept 23, 2007

Page 2: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 2

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

Page 3: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 3

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

Page 4: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 4

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 single set 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

Page 5: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 5

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

Page 6: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Background

Page 7: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 7

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

Page 8: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 8

Good Filtering Algorithm

1. Is efficient: usually called at every node of the search tree where relevant domains changed

2. 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

3. 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

Page 9: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 9

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 boundNo element not in U(S) may be in S --- upper bound

Domain-delta: provides L(S) and U(S)

(Alternative: length-lex representation)

Page 10: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 10

Bounds Consistency

Consistency notion for constraints on set variables(using the interval representation) :

C(S1, S2, …, Sn) is bounds consistent if

A. x L(Si) iff x Si for all solutions to C

B. 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”

Page 11: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

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

Page 12: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 12

sum-free(S)

Variable : set S with positive integer elementsConstraint: 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)

Amortized complexity: 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) )

Page 13: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 13

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: i sum-free(Si), partition(S1,…,Sk, [n])

Also added shadow integer vars of Model #1 to better control the search heuristic

{1, …, k}

Page 14: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 14

Experiments: Schur Number

Significantly reduced memory requirement (esp. n > 500)Often 4x speed-up

schur-k-n

Using ILOG Solver 6.3

Page 15: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

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

Page 16: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 16

atmost1(S1, …, Sn, c1, …, cn)

Variables: Sets S1, S2, …, Sn sets of integers

Integers c1, c2, …, cn cardinalities

Constraints: |Si| = ci 1 ≤ 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

Solutions:S1 = {1,2,5} or {1,2,6}S2 = {1,3,4} or {2,3,4}

[Sadler-Gervet ’01]

(“softer alldifferent”)

Page 17: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 17

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!

Page 18: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 18

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)

Page 19: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 19

pair-atmost1: Bounds Consistency

L1 : elements already in S1

U1 : elements available to be added to S1

U1 = U(S1) \ L(S1)

U2 = U(S2) \ L(S2)

L1 = L(S1)

L2 = L(S2)

S1 :

S2 :

Page 20: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 20

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)

L1rest U1L2 U1U2

L2rest U2L1 U2U1 U2only

U1only

L1L2

L1L2S1 :

S2 :

Key observation: all elements within a classare indistinguishable w.r.t. pair-atmost1

=

Page 21: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 21

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

o Initialize flags to False

o Implicitly process all solutions

o If T.can-have is still False, remove T from U(Si)

o If T.not-necessary is still False, add T to L(Si)

(typo on page 7 of paper)

Page 22: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 22

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 available elements needed

Page 23: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 23

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

Page 24: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 24

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

Page 25: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 25

Experiments: Social Golfer

golf-g-s-w: for each of w weeks, partition n golfers into g groups of size s 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 11 4 7 2 5 8 3 6 9 week 21 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]

Page 26: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 26

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

Page 27: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 27

Results: Social Golfer

Using ILOG Solver 6.3

Page 28: Two Set-Constraints For Modeling and Efficiency Willem-Jan van HoeveAshish Sabharwal Carnegie Mellon Univ.Cornell Univ. ModRef workshop at CP-07 Sept 23,

Sept 23, 2007 ModRef Workshop at CP-07 28

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