Title: Sliding Constraints
1Sliding Constraints
- Toby Walsh
- National ICT Australia and
- University of New South Wales
- www.cse.unsw.edu.au/tw
- Joint work with Christian Bessiere, Emmanuel
Hebrard, Brahim Hnich, Zeynep Kiziltan
2SLIDE meta-constraint
- Hot off the press
- Some of this is to appear at ECAI 06
- Some is even under review for IJCAI 07!
3SLIDE meta-constraint
- A constructor for generating many sequencing and
related global constraints - REGULAR Pesant 04
- AMONG SEQ Beldiceanu and Contegjean
94 - CARD PATH Beldiceanu and Carlsson
01 - VALUE PRECEDENCE Lee and Law 04
-
- Slides a constraint down one or more sequences of
variables - Ensuring constraint holds at every point
- Fixed parameter tractable
4Basic SLIDE
- SLIDE(C,X1,..Xn) holds iff
- C(Xi,..Xik) holds for every I
- INCREASING(X1,..Xn)
- SLIDE(lt,X1,..Xn)
- Unfolds into
- X1 lt X2, X2 lt X3, Xn-1 lt Xn
5Basic SLIDE
- SLIDE(C,X1,..Xn) holds iff
- C(Xi,..Xik) holds for every I
- ALWAYS_CHANGE(X1,..Xn)
- SLIDE(/,X1,..Xn)
- Unfolds into
- X1 / X2, X2 / X3, Xn-1 / Xn
6Basic SLIDE
- AMONG SEQ constraint Beldiceanu and Contegjean
94 - Car sequencing, staff rostering,
- E.g. at most 1 in 3 cars have a sun roof,
- at most 3 in 7 night shifts,
- SLIDE(C,X1,..Xn) where C(X1..,Xk) holds iff
AMONG(X1,..,Xk,l,u,v)
7Basic SLIDE
- AMONG SEQ constraint Beldiceanu and Contegjean
94 - Car sequencing, staff rostering,
- E.g. at most 1 in 3 cars have a sun roof,
- at most 3 in 7 night shifts,
- SLIDE(C,X1,..Xn) where C(X1..,Xk) holds iff
AMONG(X1,..,Xk,l,u,v) - E.g. lu2, k3 and va
- SLIDE(C,X1,..X5) where X1a, X2, .. X5 in a,b
8Basic SLIDE
- AMONG SEQ constraint Beldiceanu and Contegjean
94 - Car sequencing, staff rostering,
- E.g. at most 1 in 3 cars have a sun roof,
- at most 3 in 7 night shifts,
- SLIDE(C,X1,..Xn) where C(X1..,Xk) holds iff
AMONG(X1,..,Xk,l,u,v) - E.g. lu2, k3 and va
- SLIDE(C,X1,..X5) where X1a, X2, .. X5 in a,b
- Enforcing GAC sets X4a since only satisfying
tuples are a,a,b,a,a and a,b,a,a,b. Enforcing GAC
on decomposition does nothing!
9GSC
- Global sequence constraint in ILOG Solver
- Combines AMONG SEQ with GCC
- Regin and Puget have given partial propagator
10GSC
- Global sequence constraint in ILOG Solver
- Combines AMONG SEQ with GCC
- Regin and Puget have given partial propagator
- We can show why!
- It is NP-hard to enforce GAC on GSC
- Can actually prove this when GSC is AMONG SEQ
plus an ALL DIFFERENT - ALL DIFFERENT is a special case of GCC
11GSC
- Reduction from 1in3 SAT on positive clauses
- The jth block of 2N clauses will ensure jth
clause satisfied - Even numbered CSP vars represent truth assignment
- Odd numbered CSP vars junk to ensure N odd
values in each block - X_2jN2i odd iff xi true
- AMONG SEQ(X1,,N,N,2N,1,3,..)
- This ensures truth assignment repeated along
variables!
12GSC
- Reduction from 1in3 SAT on positive clauses
- Suppose jth clause is (x or y or z)
- X_2jN2x, X_2jN2y, X_2jN2z in 4NM4j,
4NM4j1, 4NM4j2 - As ALL DIFFERENT, only one of these odd
- For i other than x, y or z, X_2jN2i in 4jN4i,
4jN4i1 and X_2jN2i1 in 4jN4i2, 4jn4i3
13SLIDE down multiple sequences
- Can SLIDE down more than one sequence at a time
- LEX(X1,..Xn,Y1,..Yn) Frisch et
al CP 02 - Introduce sequence of Boolean vars B1,..Bn1
- Play role of alpha in LEX propagator
14SLIDE down multiple sequences
- Can SLIDE down more than one sequence at a time
- LEX(X1,..Xn,Y1,..Yn)
- Set B10
- Bn11 (strict lex), Bn1 in 0,1 (lex)
- SLIDE(C,X1..Xn,Y1,..Yn,B1,..Bn1) holds iff
C(Xi,Yi,Bi,Bi1) holds for each i
15SLIDE down multiple sequences
- Can SLIDE down more than one sequence at a time
- LEX(X1,..Xn,Y1,..Yn)
- Set B10
- Bn11 (strict lex), Bn1 in 0,1 (lex)
- SLIDE(C,X1..Xn,Y1,..Yn,B1,..Bn1)
- C(Xi,Yi,Bi,Bi1) holds iff BiBi11 or
(BiBi10 and XiYi) or (Bi0, Bi11 and
XiltYi)
16SLIDE down multiple sequences
- Can SLIDE down more than one sequence at a time
- LEX(X1,..Xn,Y1,..Yn)
- Set B10
- Bn11 (strict lex), Bn1 in 0,1 (lex)
- SLIDE(C,X1..Xn,Y1,..Yn,B1,..Bn1)
- C(Xi,Yi,Bi,Bi1) holds iff BiBi11 or
(BiBi10 and XiYi) or (Bi0, Bi11 and
XiltYi) - 2 1,3,4 2,3,4 1 3,4,5
- 0,1,2 1 1,2,3 0 0,1,2
17SLIDE down multiple sequences
- Can SLIDE down more than one sequence at a time
- LEX(X1,..Xn,Y1,..Yn)
- Set B10
- Bn11 (strict lex), Bn1 in 0,1 (lex)
- SLIDE(C,X1..Xn,Y1,..Yn,B1,..Bn1)
- C(Xi,Yi,Bi,Bi1) holds iff BiBi11 or
(BiBi10 and XiYi) or (Bi0, Bi11 and
XiltYi) - 2 1,3,42,3,4 1 3,4,5
- 2 1 1,2,3 0 0,1,2
18SLIDE down multiple sequences
- Can SLIDE down more than one sequence at a time
- LEX(X1,..Xn,Y1,..Yn)
- Set B10
- Bn11 (strict lex), Bn1 in 0,1 (lex)
- SLIDE(C,X1..Xn,Y1,..Yn,B1,..Bn1)
- C(Xi,Yi,Bi,Bi1) holds iff BiBi11 or
(BiBi10 and XiYi) or (Bi0, Bi11 and
XiltYi) - 2 1 2,3,4 1 3,4,5
- 2 1 1,2,3 0 0,1,2
19SLIDE down multiple sequences
- Can SLIDE down more than one sequence at a time
- LEX(X1,..Xn,Y1,..Yn)
- Set B10
- Bn11 (strict lex), Bn1 in 0,1 (lex)
- SLIDE(C,X1..Xn,Y1,..Yn,B1,..Bn1)
- C(Xi,Yi,Bi,Bi1) holds iff BiBi11 or
(BiBi10 and XiYi) or (Bi0, Bi11 and
XiltYi) - 2 1 2 1 3,4,5
- 2 1 3 0 0,1,2
20SLIDE down multiple sequences
- Can SLIDE down more than one sequence at a time
- LEX(X1,..Xn,Y1,..Yn)
- Set B10
- Bn11 (strict lex), Bn1 in 0,1 (lex)
- SLIDE(C,X1..Xn,Y1,..Yn,B1,..Bn1)
- C(Xi,Yi,Bi,Bi1) holds iff BiBi11 or
(BiBi10 and XiYi) or (Bi0, Bi11 and
XiltYi) - Highly efficient, incremental, ..
21SLIDE down multiple sequences
- CONTIGUITY(X1,..Xn) Maher 02
- 001100
- Two simple SLIDEs
22SLIDE down multiple sequences
- CONTIGUITY(X1,..Xn)
- 001100
- Two simple SLIDEs
- Introduce Yi in 0,1,2
- SLIDE(lt,Y1,..Yn)
23SLIDE down multiple sequences
- CONTIGUITY(X1,..Xn)
- 001100
- Two simple SLIDEs
- Introduce Yi in 0,1,2
- SLIDE(lt,Y1,..Yn)
- SLIDE(C,X1,..Xn,Y1,..Yn) where C(Xi,Yi) holds
iff Xi1 lt-gt Yi1
24SLIDE down multiple sequences
- REGULAR(A,X1,..Xn) Pesant
04 - X1 .. Xn is a string accepted by FDA A
- Can encode many useful constraints including LEX,
AMONG, STRETCH, CONTIGUITY
25SLIDE down multiple sequences
- REGULAR(A,X1,..Xn) Pesant
04 - X1 .. Xn is a string accepted by FDA A
- Encodes into simple SLIDE
- Introduce Qi to represent state of the automaton
after i symbols
26SLIDE down multiple sequences
- REGULAR(A,X1,..Xn)
- X1 .. Xn is a string accepted by FDA A
- Introduce Qi to represent state of the automaton
after i symbols - SLIDE(C,X1,..Xn,Q1,..Qn1) where
- Q1 is starting state of A
- Qn1 is limited to accepting states of A
- C(Xi,Qi,Qi1) holds iff A moves from state Qi to
state Qi1 on seeing Xi
27SLIDE down multiple sequences
- REGULAR(A,X1,..Xn)
- X1 .. Xn is a string accepted by FDA A
- Introduce Qi to represent state of the automaton
after i symbols - SLIDE(C,X1,..Xn,Q1,..Qn1) where
- Q1 is starting state of A
- Qn1 is limited to accepting states of A
- C(Xi,Qi,Qi1) holds iff A moves from state Qi to
state Qi1 on seeing Xi - Gives highly efficient and effective propagator!
- Introducing Qi also gives modelling access to
state variables
28SLIDE with counters
- AMONG(X1,..Xn,v,N)
- Introduce sequence of counts, Yi
- SLIDE(C,X1,..Xn,Y1,..Yn1) where
- Y10, Yn1N
- C(Xi,Yi,Yi1) holds iff (Xi in v and Yi11Yi)
or (Xi not in v and Yi1Yi)
29SLIDE with counters
- CARD PATH Beldiceanu and Carlsson
01 - SLIDE is a special case of CARD PATH
- SLIDE(C,X1,..Xn) iff CARD PATH(C,X1,..Xn,n-k1
)
30SLIDE with counters
- CARD PATH
- SLIDE is a special case of CARD PATH
- SLIDE(C,X1,..Xn) iff CARD PATH(C,X1,..Xn,n-k1
) - CARD PATH is a special case of SLIDE
- SLIDE(D,X1,..Xn,Y1,..Yn1) where
- Y10, Yn1N, and
- D(Xi,..Xik,Yi,Yi1) holds iff
- (Yi11Yi and C(Xi,..Xik)) or
- (Yi1Yi and not C(Xi,..Xik))
31Global constraints for symmetry breaking
- Decision variables
- ColItaly, ColFrance, ColAustria ...
- Domain of values
- red, yellow, green, ...
- Constraints
- binary relations like
- ColItaly/ColFrance
- ColItaly/ColAustria
-
32Value symmetry
- Solution
- ColItalygreen ColFrancered
- ColSpaingreen
-
- Values (colours) are interchangeable
- Swap red with green everywhere will still give us
a solution
33Value symmetry
- Solution
- ColItalygreen ColFrancered
- ColSpaingreen
-
- Values (colours) are interchangeable
- ColItalyred
- ColFrancegreen
- ColSpainred
-
34Value precedence
- Old idea
- Used in bin-packing and graph colouring
algorithms - Only open the next new bin
- Only use one new colour
- Applied now to constraint satisfaction Law and
Lee 04
35Value precedence
- Suppose all values from 1 to m are
interchangeable - Might as well let X11
36Value precedence
- Suppose all values from 1 to m are
interchangeable - Might as well let X11
- For X2, we need only consider two choices
- X21 or X22
37Value precedence
- Suppose all values from 1 to m are
interchangeable - Might as well let X11
- For X2, we need only consider two choices
- Suppose we try X22
38Value precedence
- Suppose all values from 1 to m are
interchangeable - Might as well let X11
- For X2, we need only consider two choices
- Suppose we try X22
- For X3, we need only consider three choices
- X31, X32, X33
39Value precedence
- Suppose all values from 1 to m are
interchangeable - Might as well let X11
- For X2, we need only consider two choices
- Suppose we try X22
- For X3, we need only consider three choices
- Suppose we try X32
40Value precedence
- Suppose all values from 1 to m are
interchangeable - Might as well let X11
- For X2, we need only consider two choices
- Suppose we try X22
- For X3, we need only consider three choices
- Suppose we try X32
- For X4, we need only consider three choices
- X41, X42, X43
41Value precedence
- Global constraint
- Precedence(X1,..Xn) iff
- min(i Xij or in1) lt
- min(i Xik or in2) for
all jltk - In other words
- The first time we use j is before the first time
we use k
42Value precedence
- Global constraint
- Precedence(X1,..Xn) iff
- min(i Xij or in1) lt
- min(i Xik or in2) for
all jltk - In other words
- The first time we use j is before the first time
we use k - E.g
- Precedence(1,1,2,1,3,2,4,2,3)
- But not Precedence(1,1,2,1,4)
43Value precedence
- Global constraint
- Precedence(X1,..Xn) iff
- min(i Xij or in1) lt
- min(i Xik or in2) for
all jltk - In other words
- The first time we use j is before the first time
we use k - E.g
- Precedence(1,1,2,1,3,2,4,2,3)
- But not Precedence(1,1,2,1,4)
- Proposed by Law and Lee 2004
- Pointer based propagator (alpha, beta, gamma) but
only for two interchangeable values at a time
44Value precedence
- Precedence(i,j,X1,..Xn) iff
- min(i Xij or
in1) lt - min(i Xik or
in2) - Of course
- Precedence(X1,..Xn) iff Precedence(i,j,X1,..X
n) for all iltj
45Value precedence
- Precedence(i,j,X1,..Xn) iff
- min(i Xij or
in1) lt - min(i Xik or
in2) - Of course
- Precedence(X1,..Xn) iff Precedence(i,j,X1,..X
n) for all iltj - Precedence(X1,..Xn) iff Precedence(i,i1,X1,.
.Xn) for all i
46Value precedence
- Precedence(i,j,X1,..Xn) iff
- min(i Xij or
in1) lt - min(i Xik or
in2) - Of course
- Precedence(X1,..Xn) iff Precedence(i,j,X1,..X
n) for all iltj - But this hinders propagation
- GAC(Precedence(X1,..Xn)) does strictly more
pruning than GAC(Precedence(i,j,X1,..Xn)) for
all iltj - Consider
- X11, X2 in 1,2, X3 in 1,3 and X4 in 3,4
47Pugets method
- Introduce Zj to record first time we use j
- Add constraints
- Xij implies Zj lt i
- Zji implies Xij
- Zi lt Zi1
48Pugets method
- Introduce Zj to record first time we use j
- Add constraints
- Xij implies Zj lt I
- Zji implies Xij
- Zi lt Zi1
- Binary constraints
- easy to implement
49Pugets method
- Introduce Zj to record first time we use j
- Add constraints
- Xij implies Zj lt I
- Zji implies Xij
- Zi lt Zi1
- Unfortunately hinders propagation
- AC on encoding may not give GAC on
Precedence(X1,..Xn) - Consider X11, X2 in 1,2, X3 in 1,3, X4 in
3,4, X52, X63, X74
50Propagating Precedence
- Simple SLIDE encoding
- Introduce sequence of variables, Yi
- Record largest value used so far
- Y10
51Propagating Precedence
- Simple SLIDE encoding
- SLIDE(C,X1,..Xn,Y1,..Yn1) where C(Xi,Yi,Yi1)
holds iff - Xilt1Yi and Yi1max(Yi,Xi)
52Propagating Precedence
- Simple SLIDE encoding
- SLIDE(C,X1,..Xn,Y1,..Yn1) where C(Xi,Yi,Yi1)
holds iff - Xilt1Yi and Yi1max(Yi,Xi)
- Consider Y10, X1 in 1,2,3, X2 in 1,2,3 and
X33
53Precedence and matrix symmetry
- Alternatively, could map into 2d matrix
- Xij1 iff Xij
- Value precedence now becomes column symmetry
- Can lex order columns to break all such symmetry
- Alternatively view value precedence as ordering
the columns of a matrix model
54Precedence and matrix symmetry
- Alternatively, could map into 2d matrix
- Xij1 iff Xij
- Value precedence now becomes column symmetry
- However, we get less pruning this way
- Additional constraint that rows have sum of 1
- Consider, X11, X2 in 1,2,3 and X31
55Precedence for set variables
- Social golfers problem
- Each foursome can be represented by a set of
cardinality 4 - Values (golfers) within this set are
interchangeable - Value precedence can be applied to such set
variables - But idea is now conceptually more complex!
56Precedence for set variables
- We might as well start with X11,2,3
57Precedence for set variables
- We might as well start with X11,2,3,4
- Now 1, 2, 3 and 4 are still symmetric
58Precedence for set variables
- We might as well start with X11,2,3,4
- Lets try X22,5,6,7
59Precedence for set variables
- We might as well start with X11,2,3,4
- Lets try X22,5,6,7
- But if we permute 1 with 2 we get
- X11,2,3,4 and X21,5,6,7
- And X2 is lower than X2 in the multiset ordering
60Precedence for set variables
- We might as well start with X11,2,3,4
- Lets try X21,5,6,7
61Precedence for set variables
- We might as well start with X11,2,3,4
- Lets try X21,5,6,7
- Lets try X31,2,4,5
62Precedence for set variables
- We might as well start with X11,2,3,4
- Lets try X21,5,6,7
- Lets try X31,2,4,5
- But if we permute 3 with 4 we get
- X11,2,3,4, X21,5,6,7 and X31,2,3,5
- This is again lower in the multiset ordering
63Precedence for set variables
- We might as well start with X11,2,3,4
- Lets try X21,5,6,7
- Lets try X31,2,3,5
64Precedence for set variables
- Precedence(S1,..Sn) iff
- min(i, i j in Si not(k in Si) or in1)
lt - min(i, i k in Si not(j in Si) or in2)
- for all jltk
- In other words
- The first time we distinguish apart j and k (by
one appearing on its own), j appears and k does
not
65SLIDE over sets
- Value precedence for set vars
- PRECENDCE(vj,vk,S1,..Sn) holds iff
- min(i,i vj in Si and vk not in Si or in1) lt
- min(i,i vk in Si and vj not in Si or in2)
- Introduce sequence of Booleans to indicate
whether vars have been distinguished apart yet or
not
66SLIDE over sets
- Value precedence for set vars
- PRECENDCE(vj,vk,S1,..Sn) holds iff
- min(i,i vj in Si and vk not in Si or in1) lt
- min(i,i vk in Si and vj not in Si or in2)
- SLIDE(C,S1,..Sn,B1,..Bn1) where
- B10 and
- C(Si,Bi,Bi1) holds iff
- BiBi11,
- or BiBi10 and (vj, vk in Si or vj, vk not
in Si), or Bi0, Bi11, vj in Si and vk not in Si
67SLIDE over sets
- Open stacks problem
- IJCAI 05 modelling challenge
- Three SLIDEs and one ALL DIFFERENT
- First SLIDE Si1 Si u customer(Xi)
- Second SLIDE Ti-1 Ti u customer(Xi)
- Third SLIDE Si intersect Ti lt OpenStacks
68Circular SLIDE
- STRETCH used in shift rostering Hellsten et al
04 - Given sequence of vars X1,.. Xn
- Each stretch of identical values a occurs at
least shortest(a) and at most longest(a) time - For example, at least 0 and at most 3 night
shifts in a row - Each transition Xi/Xi1 is limited to given
patterns - For example, only Xinight, Xi1off is permitted
69Circular SLIDE
- STRETCH can be efficiently encoded using SLIDE
- SLIDE(C,X1,..Xn,Y1,..Yn1) where
- Y11
- C(Xi,Xi1,Yi,Yi1) holds iff
- XiXi1, Yi11Yi, Yi1ltlongest(Xi),
- or Xi/Xi1, Yigtshortest(Xi) and (Xi,Xi1) in
set of permitted changes
70Circular SLIDE
- Circular forms of STRETCH are needed for
repeating shift patterns - Circular form of SLIDE useful in such situations
- SLIDEo(C,X1,..Xn) holds iff
- C(Xi,..X1(ik-1)mod n) holds for 1ltiltn
71SLIDE algebra
- SLIDEOR(C,X1..Xn) holds iff
- C(Xi,..Xik) holds for some I
- Encodes as CARD PATH (and thus as SLIDE)
- Other more complex combinations
- NOT(SLIDE(C,X1,..Xn)) iff SLIDEOR(NOT(C),X1,..X
n) - SLIDE(C1,X1,..Xn) and SLIDE(C2,X1,..Xn) iff
SLIDE(C1 and C2,X1,..Xn) - ..
72Propagating SLIDE
- But how do we propagate global constraints
expressed using SLIDE?
73Propagating SLIDE
- SLIDE(C,X1,..Xn)
- Just post sequence of constraints, C(Xi,..Xik)
- If constraint graph is Berge acyclic, then we
will achieve GAC - Gives efficient GAC propagators for CONTIGUITY,
DOMAIN, ELEMENT, LEX, PRECEDENCE, REGULAR,
74Propagating SLIDE
- SLIDE(C,X1,..Xn)
- Just post sequence of constraints, C(Xi,..Xik)
- If constraint graph is Berge acyclic, then we
will achieve GAC - Gives efficient GAC propagators for CONTIGUITY,
DOMAIN, ELEMENT, LEX, PRECEDENCE, REGULAR, - But what about case constraint graph is not
Berge-acyclic? - Slide constraints overlap on more than one
variable
75Propagating SLIDE
- SLIDE(C,X1,..Xn)
- Slide constraints overlap on more than one
variable - Enforce GAC using dynamic programming
- pass support down sequence
76Propagating SLIDE
- SLIDE(C,X1,..Xn)
- Equivalently a dual encoding
- Consider AMONG SEQ(2,2,3,X1,..X5,a) where
- X1a, X2,X3,X4,X5 in a,b
- AMONG(X1,X2,X3,2,a)
- AMONG(X2,X3,X4,2,a)
- AMONG(X3,X4,X5,2,a)
- Enforcing GAC sets X4a
- GAC can be enforced in O(ndk1) time and O(ndk)
space where constraints overlap on k variables - Fixed parameter tractable
77Conclusions
- SLIDE is a very useful meta-constraint
- Many global constraints for sequencing and other
problems can be encoded as SLIDE - SLIDE can be propagated easily
- Constraints overlap on just one variable gt
simply post slide constraints - Constraints overlap on more than one variable gt
use dynamic programming or equivalently a simple
dual encoding