ModRef07: Two Set-Constraints For Modeling and Efficiency

Download Report

Transcript ModRef07: Two Set-Constraints For Modeling and Efficiency

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
Sept 23, 2007
ModRef Workshop at CP-07
2
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 machines
A set of packages to be moved using a set of trucks
Often “grounded-down” to single-valued variables,
especially in SAT and integer programming
Sept 23, 2007
ModRef Workshop at CP-07
3
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
Sept 23, 2007
ModRef Workshop at CP-07
4
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
Sept 23, 2007
ModRef Workshop at CP-07
5
Background
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), yz, 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
Sept 23, 2007
ModRef Workshop at CP-07
7
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
Sept 23, 2007
ModRef Workshop at CP-07
8
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)
Sept 23, 2007
ModRef Workshop at CP-07
9
Bounds Consistency
Consistency notion for constraints on set variables
(using the interval representation) :
C(S1, S2, …, Sn) is bounds consistent if
“roughly speaking”
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
Sept 23, 2007
ModRef Workshop at CP-07
10
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 |ij| 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) )
Sept 23, 2007
ModRef Workshop at CP-07
12
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?
{1, …, k}
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
Sept 23, 2007
ModRef Workshop at CP-07
13
Experiments: Schur Number
schur-k-n
Significantly reduced memory requirement (esp. n > 500)
Often 4x speed-up
Using ILOG Solver 6.3
Sept 23, 2007
ModRef Workshop at CP-07
14
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, …, Sn
 Integers c1, c2, …, cn
sets of integers
cardinalities
Constraints:
1≤i≤n
1≤i<j≤n
 |Si| = ci
 |Si  Sj| ≤ 1
(“softer alldifferent”)
Example: D(S1) = [{1,2}, {1,2,3,5,6}],
D(S2) = [{3}, {1,2,3,4}],
|S1| = |S2| = c1 = c2 = 3
Sept 23, 2007
ModRef Workshop at CP-07
Solutions:
S1 = {1,2,5} or {1,2,6}
S2 = {1,3,4} or {2,3,4}
16
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!
Sept 23, 2007
ModRef Workshop at CP-07
17
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)
Sept 23, 2007
ModRef Workshop at CP-07
18
pair-atmost1: Bounds Consistency
S1 :
S2 :
L1 = L(S1)
U1 = U(S1) \ L(S1)
L2 = L(S2)
U2 = U(S2) \ L(S2)
 L1 : elements already in S1
 U1 : elements available to be added to S1
Sept 23, 2007
ModRef Workshop at CP-07
19
Partitioning into Classes
L1L2
S2 :
L1L2
L1rest
U1L2
U1U2
U1only
=
S1 :
L2rest
U2L1
U2U1
U2only
9 classes of elements
Key observation: all elements within a class
are indistinguishable w.r.t. pair-atmost1
 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)
Sept 23, 2007
ModRef Workshop at CP-07
20
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
(typo on page 7 of paper)
1. Initialize flags to False
2. Implicitly process all solutions
3. If T.can-have is still False, remove T from U(Si)
4. If T.not-necessary is still False, add T to L(Si)
Sept 23, 2007
ModRef Workshop at CP-07
21
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|)
elements available
elements needed
 Similarly slack2
 slack3 = (|U1only|+|U2only|+|U1U2|)  (c1+c2  |L1|+|L2|)
Sept 23, 2007
ModRef Workshop at CP-07
22
Updating Flags: “Case0”
There exists a solution in Case0 iff
slack1  0, slack2  0, and slack3  0
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.)
Sept 23, 2007
ModRef Workshop at CP-07
23
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
Sept 23, 2007
ModRef Workshop at CP-07
24
Experiments: Social Golfer
golf-g-s-w: for each of w weeks, partition n golfers into g groups
of size s each (gs = n), such that no two golfers are in the
same group more than once
[prob010 in CSPLib]
Example:
123
147
159
456
258
267
789
369
348
week 1
week 2
week 3
Well-studied problem: surprisingly challenging!
 Techniques based on symmetry, local search
 Our work: orthogonal to these --- improve basic filtering
Sept 23, 2007
ModRef Workshop at CP-07
25
Set-Based Model
One set variable for each group Sij (week i, group j)
Constraints:
partition(Si1, Si2, …, Sig, [n])
atmost1(Sij, Skl, s, s)
week i
weeks ik; 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
Sept 23, 2007
ModRef Workshop at CP-07
26
Results: Social Golfer
Sept 23, 2007
ModRef Workshop at CP-07
Using ILOG Solver 6.3
27
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
Sept 23, 2007
ModRef Workshop at CP-07
28