A parametric propagator for discretely convex pairs of

A parametric propagator for discretely
convex pairs of sum constraints1
¨ Monette∗ , Nicolas Beldiceanu∗∗ , Pierre Flener∗ ,
Jean-Noel
and Justin Pearson∗
∗ ASTRA
Research Group on Constraint Programming
Uppsala University
∗∗ TASC
Team (CNRS/INRIA)
Mines de Nantes
CP 2013
1
supported by grants 2011-6133 and 2012-4908 of VR, the Swedish
Research Council
Motivation
Motivation
Pair of Sums
S UM constraints are widely used.
Solving
Results
Conclusion
Alone: not much propagation.
With other constraints: better propagation is
possible, if considered together.
CP 2013
-2-
Example: D EVIATION(x, ∆, µ)
Motivation
Pair of Sums
Solving
Results
Conclusion
X
|xi − µ| ≤ ∆
i∈[1,n]
X
xi /n = µ
i∈[1,n]
[Schaus et al., CP 2007] propose a bounds-consistency
propagator that runs in O(n) time.
CP 2013
-3-
Example: D EVIATION(x, ∆, µ)
Motivation
Pair of Sums
Solving
Results
Conclusion
X
|n · xi − n · µ| ≤ ∆
i∈[1,n]
X
xi = n · µ
i∈[1,n]
[Schaus et al., CP 2007] propose a bounds-consistency
propagator that runs in O(n) time.
CP 2013
-4-
Example: S PREAD(x, ∆, µ)
Motivation
Pair of Sums
Solving
Results
Conclusion
X
(n · xi − n · µ)2 ≤ ∆
i∈[1,n]
X
xi = n · µ
i∈[1,n]
[Schaus and Regin, to appear] propose a
bounds-consistency propagator that runs in O(n log n) time.
CP 2013
-5-
Example: Linear Inequality and Counting
Motivation
Pair of Sums
Solving
Results
Conclusion
X
ai · xi ≤ b
i∈[1,n]
X
[xi = v ] = c
i∈[1,n]
[Razakarison et al., SoCS 2013] propose a
domain-consistency propagator that runs in
O(n · (log n + p)) time (where p is the complexity of filtering
one variable).
CP 2013
-6-
The general case
Motivation
Pair of Sums
Solving
X
Results
Conclusion
fi (xi ) ≤ f
i∈[1,n]
g≤
X
gi (xi ) ≤ g
i∈[1,n]
Reformulate the problem to simplify its presentation and
bring out some special structure.
CP 2013
-7-
The general case: Reformulation
Motivation
Pair of Sums
Solving
X
Results
Conclusion
fi (xi ) ≤ f
i∈[1,n]
g≤
X
gi (xi ) ≤ g
i∈[1,n]
Reformulate the problem to simplify its presentation and
bring out some special structure.
CP 2013
-7-
The general case: Reformulation
X
fi (xi ) ≤ f
Motivation
i∈[1,n]
Pair of Sums
Solving
g≤
Results
X
gi (xi ) ≤ g
i∈[1,n]
Conclusion
1
2
3
4
Introduce yi = gi (xi )
Define hi (v ) = min fi (gi−1 (v ))
Define
 H(b) = 
X

X
min
hi (yi ) yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )


i∈[1,n]
i∈[1,n]
X
Introduce z =
yi .
i∈[1,n]
The reformulated problem is equivalent to the original one.
CP 2013
-8-
The general case: Reformulation
X
fi (xi ) ≤ f
Motivation
i∈[1,n]
Pair of Sums
Solving
g≤
Results
X
gi (xi ) ≤ g
i∈[1,n]
Conclusion
1
2
3
4
Introduce yi = gi (xi )
Define hi (v ) = min fi (gi−1 (v ))
Define
 H(b) = 
X

X
min
hi (yi ) yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )


i∈[1,n]
i∈[1,n]
X
Introduce z =
yi .
i∈[1,n]
The reformulated problem is equivalent to the original one.
CP 2013
-8-
The general case: Reformulation
X
Motivation
min fi (gi−1 (yi )) ≤ f
i∈[1,n]
Pair of Sums
Solving
X
g≤
Results
yi ≤ g
i∈[1,n]
Conclusion
1
2
3
4
Introduce yi = gi (xi )
Define hi (v ) = min fi (gi−1 (v ))
Define
 H(b) = 
X

X
min
hi (yi ) yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )


i∈[1,n]
i∈[1,n]
X
Introduce z =
yi .
i∈[1,n]
The reformulated problem is equivalent to the original one.
CP 2013
-8-
The general case: Reformulation
X
Motivation
min fi (gi−1 (yi )) ≤ f
i∈[1,n]
Pair of Sums
Solving
X
g≤
Results
yi ≤ g
i∈[1,n]
Conclusion
1
2
3
4
Introduce yi = gi (xi )
Define hi (v ) = min fi (gi−1 (v ))
Define
 H(b) = 
X

X
min
hi (yi ) yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )


i∈[1,n]
i∈[1,n]
X
Introduce z =
yi .
i∈[1,n]
The reformulated problem is equivalent to the original one.
CP 2013
-8-
The general case: Reformulation
X
Motivation
hi (yi ) ≤ f
i∈[1,n]
Pair of Sums
Solving
g≤
Results
X
yi ≤ g
i∈[1,n]
Conclusion
1
2
3
4
Introduce yi = gi (xi )
Define hi (v ) = min fi (gi−1 (v ))
Define
 H(b) = 
X

X
min
hi (yi ) yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )


i∈[1,n]
i∈[1,n]
X
Introduce z =
yi .
i∈[1,n]
The reformulated problem is equivalent to the original one.
CP 2013
-8-
The general case: Reformulation
X
Motivation
hi (yi ) ≤ f
i∈[1,n]
Pair of Sums
Solving
g≤
Results
X
yi ≤ g
i∈[1,n]
Conclusion
1
2
3
4
Introduce yi = gi (xi )
Define hi (v ) = min fi (gi−1 (v ))
Define
 H(b) = 
X

X
min
hi (yi ) yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )


i∈[1,n]
i∈[1,n]
X
Introduce z =
yi .
i∈[1,n]
The reformulated problem is equivalent to the original one.
CP 2013
-8-
The general case: Reformulation
H(z) ≤ f
Motivation
Pair of Sums
g≤z≤g
Solving
Results
Conclusion
1
Introduce yi = gi (xi )
2
Define hi (v ) = min fi (gi−1 (v ))
3
4
Define
 H(b) = 
X

X
min
hi (yi ) yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )


i∈[1,n]
i∈[1,n]
X
Introduce z =
yi .
i∈[1,n]
The reformulated problem is equivalent to the original one.
CP 2013
-8-
The general case: Reformulation
H(z) ≤ f
Motivation
Pair of Sums
g≤z≤g
Solving
Results
Conclusion
1
Introduce yi = gi (xi )
2
Define hi (v ) = min fi (gi−1 (v ))
3
4
Define
 H(b) = 
X

X
min
hi (yi ) yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )


i∈[1,n]
i∈[1,n]
X
Introduce z =
yi .
i∈[1,n]
The reformulated problem is equivalent to the original one.
CP 2013
-8-
Examples of functions
Motivation
Pair of Sums
Common Name
fi (u)
gi (u)
Results
L INEAR
ai · u
0
Conclusion
W EIGHTEDAVERAGE
D EVIATION
S PREAD
Lp -N ORM
ai · u
|n · u − n · µ|
(n · u − n · µ)2
|n · u − n · µ|p
u
u
u
u
Solving
CP 2013
L INEAR and C OUNT
ai · u
[u ∈ V]
M ODA ND D IV (ai > 0)
u − ai · bu/ai c
bu/ai c
-9-
h
(i (v )
ai · min Dxi
if ai > 0
ai · max Dxi if ai ≤ 0
ai · v
|n · v − n · µ|
(n · v − n · µ)2
|n · v − n · µ|p

ai · min (Dxi \V) if v = 0 ∧ ai



a · max (D \V) if v = 0 ∧ a
xi
i
i

ai · min (Dxi ∩V) if v = 1 ∧ ai


ai · max (Dxi ∩V) if v = 1 ∧ ai
max (0, min Dxi −ai · v )
>0
≤0
>0
≤0
Checking for Satisfiability
Motivation
Pair of Sums
minimise
Solving
H(z)
such that g ≤ z ≤ g
Results
(1)
Conclusion
where

X

yi = b ∧ ∀i ∈ [1, n] : yi ∈ gi (Dxi )
H(b) = min
hi (yi ) 

i∈[1,n]
i∈[1,n]

X
Theorem
Problem (1) can be solved greedily if each hi is discretely convex.
CP 2013
- 10 -
Discrete Convexity
Definition (Discrete Convexity)
Motivation
Pair of Sums
Solving
Results
Conclusion
CP 2013
A function f : A → B, where A, B ⊆ Z, is discretely convex if
A is an interval, and
∀v ∈ A : (v − 1) ∈ A ∧ (v + 1) ∈ A ⇒
2 · f (v ) ≤ f (v − 1) + f (v + 1).
- 11 -
Properties
Motivation
Pair of Sums
Solving
Results
Theorem
Problem (1) can be solved greedily if each hi is discretely
convex.
Conclusion
Properties
H(.) is also discretely convex.
H(.) can be constructed in polynomial time from the hi .
min H(z) s.t. yj = v for some j can be computed
incrementally from v to v + 1 (used for filtering).
CP 2013
- 12 -
Propagator
Motivation
Pair of Sums
1
Construct H(.) and find its minimum (two ways)
Solving
2
Filter each variable (two ways)
Results
Conclusion
The algorithms are in the paper.
Time complexity of the different versions
Version
Traversing, general case
Sorting, general case
Traversing, special case
Sorting, special case
CP 2013
Time complexity
O(n · (s(h) · p + s(H) + r (h) · c)
O(n · (s(h) · p + s(h) · log(n · s(h)) + r (h) · c))
O(n · (s(h) · p + s(H) + c))
O(n · (s(h) · p + s(h) · log(n · s(h)) + s(H) + c))
- 13 -
Propagator
Motivation
Pair of Sums
1
Construct H(.) and find its minimum (two ways)
Solving
2
Filter each variable (two ways)
Results
Conclusion
The algorithms are in the paper.
Time complexity of the different versions
Version
Traversing, general case
Sorting, general case
Traversing, special case
Sorting, special case
CP 2013
Time complexity
O(n · (s(h) · p + s(H) + r (h) · c)
O(n · (s(h) · p + s(h) · log(n · s(h)) + r (h) · c))
O(n · (s(h) · p + s(H) + c))
O(n · (s(h) · p + s(h) · log(n · s(h)) + s(H) + c))
- 13 -
Parametric algorithms
Parameters to instantiate
Motivation
Pair of Sums
Solving
Results
Conclusion
Functions
argminv ∈gi (Dx ) hi (v )
i
∆+ (hi , v )
∆− (hi , v )
bp+ (hi , v )
bp− (hi , v )
Procedures
F ILTER(gi (xi ) ≤ v )
F ILTER(gi (xi ) ≥ v )
F ILTER(gi (xi ) = v ⇒ fi (xi ) ≤ u)
hi (v − 1)
∆− (hi , v )
hi (v )
hi (v + 1)
∆+ (hi , v )
bp− (hi , v v) − 1
CP 2013
v
v +1
- 14 -
bp+ (hi , v )
Example: Parameters for D EVIATION
Motivation
Pair of Sums
Solving
Results
Conclusion
dµe bµc
min Dxi
max Dxi
Parameters to instantiate
Functions
argminv ∈gi (Dx ) hi (v )
i
∆+ (hi , v )
∆− (hi , v )
bp+ (hi , v )
bp− (hi , v )
CP 2013
Procedures
F ILTER(gi (xi ) ≤ v )
F ILTER(gi (xi ) ≥ v )
F ILTER(gi (xi ) = v ⇒ fi (xi ) ≤ u)
- 15 -
Example: Parameters for D EVIATION
Parameter
Motivation
Pair of Sums
Solving
argminv ∈gi (Dx ) hi (v )
i
Results
Conclusion
∆+ (hi , v )
bp+ (hi , v )
F ILTER(gi (xi ) ≤ v )
F ILTER(gi (xi ) = v ⇒
mmmmmmmifi (xi ) ≤ u)
CP 2013
Instantiation

dµe
if min Dxi ≤ µ ≤ max Dxi ∧dµe − µ < µ − bµc



bµc
if min Dxi ≤ µ ≤ max Dxi ∧dµe − µ ≥ µ − bµc

min Dxi if µ < min Dxi


max Dxi if µ > max Dxi

+∞
if v = max Dxi



−n
if v < bµc

6 dµe
n · (dµe + bµc) − 2 · n · µ if v = bµc ∧ bµc =


n
if v ≥ dµe

+∞
if v = max Dxi



min (max D , bµc) if v < bµc
xi

dµe
if v = bµc ∧ bµc =
6 dµe



max Dxi
if v ≥ dµe
F ILTER(xi ≤ v )
F ILTER(|n · v − n · µ| > u ⇒ xi 6= v )
- 16 -
A Few Other Instantiations
Motivation
Pair of Sums
Solving
Results
Conclusion
Constraint
L INEAR
W EIGHTEDAVERAGE
D EVIATION
S PREAD
Lp -N ORM
L INEAR and C OUNT
Consistency
bounds(Z)
bounds(Z)
bounds(Z)
bounds(Z)
bounds(Z)
domain
Complexity
O(n · log n)
O(n · log n)
O(n)
O(n · d)
O(n · d)
O(n · (log n + p + c))
n: number of variables
d: size of the union of domains
p, c: complexity of the parameters
CP 2013
- 17 -
Literature
O(n)
O(n)
O(n)
O(n · log n)
O(n · (log n + p + c))
Experiments
Compare to existing implementations:
Motivation
Pair of Sums
Solving
Solving the Balanced Academic Curriculum Problem in
OscaR.
Results
Conclusion
D EVIATION as an objective: 7% slower with our propagator
S PREAD as an objective: 28% faster with our propagator
Code available at
http://www.it.uu.se/research/group/astra/software/convexpairs
CP 2013
- 18 -
Conclusion
Motivation
Pair of Sums
Solving
Discrete convexity
Results
Parametric propagator
Conclusion
Efficient
Extensions:
•
•
•
•
CP 2013
Generating the parameters
more than 2 sums
incrementality
...
- 19 -