58
Global Constraints Toby Walsh National ICT Australia and University of New South Wales www.cse.unsw.edu.au/~tw

Global Constraints

  • Upload
    moe

  • View
    37

  • Download
    0

Embed Size (px)

DESCRIPTION

Toby Walsh National ICT Australia and University of New South Wales www.cse.unsw.edu.au/~tw. Global Constraints. Course outline. Introduction All Different Lex ordering Value precedence Complexity GAC-Schema Soft Global Constraints Global Grammar Constraints Roots Constraint - PowerPoint PPT Presentation

Citation preview

Page 1: Global Constraints

Global Constraints

Toby WalshNational ICT Australia and

University of New South Waleswww.cse.unsw.edu.au/~tw

Page 2: Global Constraints

Course outline● Introduction● All Different● Lex ordering● Value precedence● Complexity● GAC-Schema● Soft Global Constraints● Global Grammar Constraints● Roots Constraint● Range Constraint● Slide Constraint● Global Constraints on Sets

Page 3: Global Constraints

Value precedence

● Global constraint proposed to deal with value symmetry– Hot off the press!– Propagator first described here [ECAI 06]

● Good example of “global” constraint where we can use an efficient encoding– Encoding gives us GAC– Asymptotically optimal, achieve GAC in O(nd) time

Page 4: Global Constraints

Value symmetry

● Decision variables:– Col[Italy], Col[France],

Col[Austria] ...● Domain of values:

– red, yellow, green, ...● Constraints

– binary relations like Col[Italy]=/=Col[France] Col[Italy]=/=Col[Austria] …

Page 5: Global Constraints

Value symmetry

● Solution:– Col[Italy]=green

Col[France]=red Col[Spain]=green …

● Values (colours) are interchangeable:– Swap red with green

everywhere will still give us a solution

Page 6: Global Constraints

Value symmetry

● Solution:– Col[Italy]=green

Col[France]=red Col[Spain]=green …

● Values (colours) are interchangeable:– Col[Italy]=red Col[France]=green Col[Spain]=red …

Page 7: Global Constraints

Value 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

Page 8: Global Constraints

Value precedence

● Suppose all values from 1 to m are interchangeable– Might as well let X1=1

Page 9: Global Constraints

Value precedence

● Suppose all values from 1 to m are interchangeable– Might as well let X1=1– For X2, we need only consider two choices

● X2=1 or X2=2

Page 10: Global Constraints

Value precedence

● Suppose all values from 1 to m are interchangeable– Might as well let X1=1– For X2, we need only consider two choices– Suppose we try X2=2

Page 11: Global Constraints

Value precedence

● Suppose all values from 1 to m are interchangeable– Might as well let X1=1– For X2, we need only consider two choices– Suppose we try X2=2– For X3, we need only consider three choices

● X3=1, X3=2, X3=3

Page 12: Global Constraints

Value precedence

● Suppose all values from 1 to m are interchangeable– Might as well let X1=1– For X2, we need only consider two choices– Suppose we try X2=2– For X3, we need only consider three choices– Suppose we try X3=2

Page 13: Global Constraints

Value precedence

● Suppose all values from 1 to m are interchangeable– Might as well let X1=1– For X2, we need only consider two choices– Suppose we try X2=2– For X3, we need only consider three choices– Suppose we try X3=2– For X4, we need only consider three choices

● X4=1, X4=2, X4=3

Page 14: Global Constraints

Value precedence

● Global constraint– Precedence([X1,..Xn]) iff

min({i | Xi=j or i=n+1}) < min({i | Xi=k or i=n+2}) for all j<k

– In other words● The first time we use j is before the first time we use k

Page 15: Global Constraints

Value precedence

● Global constraint– Precedence([X1,..Xn]) iff

min({i | Xi=j or i=n+1}) < min({i | Xi=k or i=n+2}) for all j<k

– 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])

Page 16: Global Constraints

Value precedence

● Global constraint– Precedence([X1,..Xn]) iff

min({i | Xi=j or i=n+1}) < min({i | Xi=k or i=n+2}) for all j<k

– 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

Page 17: Global Constraints

Value precedence

● Precedence([i,j],[X1,..Xn]) iff min({i | Xi=j or i=n+1}) <

min({i | Xi=k or i=n+2})

● Of course– Precedence([X1,..Xn]) iff Precedence([i,j],[X1,..Xn])

for all i<j

Page 18: Global Constraints

Value precedence

● Precedence([i,j],[X1,..Xn]) iff min({i | Xi=j or i=n+1}) <

min({i | Xi=k or i=n+2})

● Of course– Precedence([X1,..Xn]) iff Precedence([i,j],[X1,..Xn])

for all i<j– Precedence([X1,..Xn]) iff Precedence([i,i+1],[X1,..Xn])

for all i

Page 19: Global Constraints

Value precedence

● Precedence([i,j],[X1,..Xn]) iff min({i | Xi=j or i=n+1}) <

min({i | Xi=k or i=n+2})

● Of course– Precedence([X1,..Xn]) iff Precedence([i,j],[X1,..Xn]) for all i<j

● But this hinders propagation– GAC(Precedence([X1,..Xn])) does strictly more pruning than

GAC(Precedence([i,j],[X1,..Xn])) for all i<j– Consider

X1=1, X2 in {1,2}, X3 in {1,3} and X4 in {3,4}

Page 20: Global Constraints

Puget’s method

● Introduce Zj to record first time we use j● Add constraints

– Xi=j implies Zj <= i– Zj=i implies Xi=j– Zi < Zi+1

Page 21: Global Constraints

Puget’s method

● Introduce Zj to record first time we use j● Add constraints

– Xi=j implies Zj < I– Zj=i implies Xi=j– Zi < Zi+1

● Binary constraints– easy to implement

Page 22: Global Constraints

Puget’s method

● Introduce Zj to record first time we use j● Add constraints

– Xi=j implies Zj < I– Zj=i implies Xi=j– Zi < Zi+1

● Unfortunately hinders propagation– AC on encoding may not give GAC on

Precedence([X1,..Xn])– Consider X1=1, X2 in {1,2}, X3 in {1,3}, X4 in {3,4},

X5=2, X6=3, X7=4

Page 23: Global Constraints

Propagating Precedence

● Simple ternary encoding● Introduce sequence of variables, Yi

– Record largest value used so far– Y1=0

Page 24: Global Constraints

Propagating Precedence

● Simple ternary encoding● Post sequence of constraints

C(Xi,Yi,Yi+1) for each 1<=i<=n

These hold iff

Xi<=1+Yi and Yi+1=max(Yi,Xi)

Page 25: Global Constraints

Propagating Precedence

● Simple ternary encoding● Post sequence of constraints● Easily implemented within most solvers

● Implication and other logical primitives● GAC-Schema (alias “table” constraint)● …

Page 26: Global Constraints

Propagating Precedence

● Simple ternary encoding● Post sequence of constraints

– C(Xi,Yi,Yi+1) for each 1<=i<=n– This decomposition is Berge-acyclic– Constraints overlap on one variable and form a tree

Page 27: Global Constraints

Propagating Precedence

● Simple ternary encoding● Post sequence of constraints

– C(Xi,Yi,Yi+1) for each 1<=i<=n– This decomposition is Berge-acyclic– Constraints overlap on one variable and form a tree– Hence enforcing GAC on the decomposition achieves

GAC on Precedence([X1,..Xn])– Takes O(n) time– Also gives excellent incremental behaviour

Page 28: Global Constraints

Propagating Precedence

● Simple ternary encoding● Post sequence of constraints

– C(Xi,Yi,Yi+1) for each 1<=i<=n– These hold iff Xi<=1+Yi and Yi+1=max(Yi,Xi)

– Consider Y1=0, X1 in {1,2,3}, X2 in {1,2,3} and X3=3

Page 29: Global Constraints

Precedence and matrix symmetry

● Alternatively, could map into 2d matrix– Xij=1 iff Xi=j

● 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

Page 30: Global Constraints

Precedence and matrix symmetry

● Alternatively, could map into 2d matrix– Xij=1 iff Xi=j

● Value precedence now becomes column symmetry● However, we get less pruning this way

– Additional constraint that rows have sum of 1– Consider, X1=1, X2 in {1,2,3} and X3=1

Page 31: Global Constraints

Precedence 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!

Page 32: Global Constraints

Precedence for set variables

● We might as well start with X1={1,2,3}

Page 33: Global Constraints

Precedence for set variables

● We might as well start with X1={1,2,3,4}● Now 1, 2, 3 and 4 are still symmetric

Page 34: Global Constraints

Precedence for set variables

● We might as well start with X1={1,2,3,4}● Let’s try X2={2,5,6,7}

Page 35: Global Constraints

Precedence for set variables

● We might as well start with X1={1,2,3,4}● Let’s try X2={2,5,6,7}● But if we permute 1 with 2 we get

– X1’={1,2,3,4} and X2’={1,5,6,7}– And X2’ is lower than X2 in the multiset ordering

Page 36: Global Constraints

Precedence for set variables

● We might as well start with X1={1,2,3,4}● Let’s try X2={1,5,6,7}

Page 37: Global Constraints

Precedence for set variables

● We might as well start with X1={1,2,3,4}● Let’s try X2={1,5,6,7}● Let’s try X3={1,2,4,5}

Page 38: Global Constraints

Precedence for set variables

● We might as well start with X1={1,2,3,4}● Let’s try X2={1,5,6,7}● Let’s try X3={1,2,4,5}● But if we permute 3 with 4 we get

– X1’={1,2,3,4}, X2’={1,5,6,7} and X3’={1,2,3,5}– This is again lower in the multiset ordering

Page 39: Global Constraints

Precedence for set variables

● We might as well start with X1={1,2,3,4}● Let’s try X2={1,5,6,7}● Let’s try X3={1,2,3,5}● …

Page 40: Global Constraints

Precedence for set variables

● Precedence([S1,..Sn]) iff min(i, {i | j in Si & not(k in Si) or i=n+1}) < min(i, {i | k in Si & not(j in Si) or i=n+2})

for all j<k

● In other words– The first time we distinguish apart j and k (by one

appearing on its own), j appears and k does not

Page 41: Global Constraints

Precedence for set variables

● Precedence([S1,..Sn]) iff min(i, {i | j in Si & not(k in Si) or i=n+1}) < min(i, {i | k in Si & not(j in Si) or i=n+2}) for all j<k

● To enforce BC– Consider 2d matrix, Xij=1 iff j in Si– This has column symmetry– Apply lex to this!– No longer row sum=1 and no loss in pruning

Page 42: Global Constraints

Precedence for set variables

● Precedence([S1,..Sn]) iff min(i, {i | j in Si & not(k in Si) or i=n+1}) < min(i, {i | k in Si & not(j in Si) or i=n+2}) for all j<k

● To enforce BC– Consider 2d matrix, Xij=1 iff j in Si– This has column symmetry– Apply lex to this!– {1} subseteq S1 subseteq {1,2}, S2={2}, S3={1,2,3}

Page 43: Global Constraints

Precedence for set variables

● Set variables may have cardinality information– E.g. every set variable has 4 values– Solvers often include finite domain variable for the

cardinality of a set variable

● If we add such cardinality information, enforcing BC on Precedence([S1,..Sn]) is NP-hard!– More about this in the Complexity lecture

Page 44: Global Constraints

Partial value precedence

● Values may partition into equivalence classes● Values within each equivalence class are

interchangeable

● E.g. Shift1=nursePaul, Shift2=nursePeter, Shift3=nurseJane, Shift4=nursePaul ..

Page 45: Global Constraints

Partial value precedence

● Values may partition into equivalence classes● Values within each equivalence class are

interchangeable

● E.g. Shift1=nursePaul, Shift2=nursePeter, Shift3=nurseJane, Shift4=nursePaul .. If Paul and Jane have the same skills, we might be

able to swap them (but not with Peter who is less qualified)

Shift1=nurseJane, Shift2=nursePeter, Shift3=nursePaul, Shift4=nurseJane …

Page 46: Global Constraints

Partial value precedence

● Values may partition into equivalence classe● Value precedence easily generalized to cover this

case– Within each equivalence class, vi occurs before vj for

all i<j (ignore values from other equivalence classes)

Page 47: Global Constraints

Partial value precedence

● Values may partition into equivalence classe● Value precedence easily generalized to cover this

case– Within each equivalence class, vi occurs before vj for

all i<j (ignore values from other equivalence classes)– For example

● Suppose vi are one equivalence class, and ui another

Page 48: Global Constraints

Partial value precedence

● Values may partition into equivalence classe● Value precedence easily generalized to cover this

case– Within each equivalence class, vi occurs before vj for

all i<j (ignore values from other equivalence classes)– For example

● Suppose vi are one equivalence class, and ui another● X1=v1, X2=u1, X3=v2, X4=v1, X5=u2

Page 49: Global Constraints

Partial value precedence

● Values may partition into equivalence classe● Value precedence easily generalized to cover this

case– Within each equivalence class, vi occurs before vj for

all i<j (ignore values from other equivalence classes)– For example

● Suppose vi are one equivalence class, and ui another● X1=v1, X2=u1, X3=v2, X4=v1, X5=u2● Since v1, v2, v1 … and u1, u2, …

Page 50: Global Constraints

Wreath value precedence

● Variables are assigned pair of values in D1 x D2● Values in D1 are interchangeable● Given a fixed value in D1, values in D2 are

interchangeable

Page 51: Global Constraints

Wreath value precedence

● Variables are assigned pair of values in D1 x D2– Values in D1 are interchangeable– Given a fixed value in D1, values in D2 are

interchangeable● For example,

– Scheduling a conference– Days of week might be interchangeable– Given a day of week, rooms might then be

interchangeable

Page 52: Global Constraints

Wreath value precedence

● Variables are assigned pair of values in D1 x D2– Values in D1 are interchangeable– Given a fixed value in D1, values in D2 are

interchangeable● For example,

– Scheduling a conference– Session1=<Tu,roomA>, Session2=<Wed,roomB>,

Session3=<Tu,roomB> …

Page 53: Global Constraints

Wreath value precedence

● Variables are assigned pair of values in D1 x D2– Values in D1 are interchangeable– Given a fixed value in D1, values in D2 are

interchangeable● For example,

– Scheduling a conference– Session1=<Tu,roomA>, Session2=<Wed,roomB>,

Session3=<Tu,roomB> …– Session1=<Wed,roomB>, Session2=<Tu,roomB>,

Session3=<Wed,roomA> …

Page 54: Global Constraints

Wreath value precedence

● Variables are assigned pair of values in D1 x D2– Values in D1 are interchangeable– Given a fixed value in D1, values in D2 are

interchangeable● Value precedence again generalizes to this case

min(i, {Xi[1]=uj or i=n+1}) < min(i, {Xi[1]=uj+1 or i=n+2}) andmin(i, {Xi=(uj,vk) or i=n+1}) <min(i, {Xi=(uj,vk+1) or i=n+2})

Page 55: Global Constraints

Variable and value precedence

● Value precedence compatible with other symmetry breaking methods– Interchangeable values and lex ordering of rows and

columns in a matrix model

Page 56: Global Constraints

Variable and value precedence

● Value precedence compatible with other symmetry breaking methods– Interchangeable values and lex ordering of rows and

columns in a matrix model– Interchangeable values and variables

● But does not break all symmetry● Consider [1.2,2] and [1,1,2]● Use instead IncreasingSeq([X1,…Xn])● Values and number of occurrences increase

Page 57: Global Constraints

Variable and value precedence

● Value precedence compatible with other symmetry breaking methods– Interchangeable values and lex ordering of rows and

columns in a matrix model– Interchangeable values and variables

● But does not break all symmetry● Consider [1.2,2] and [1,1,2]● Use instead IncreasingSeq([X1,…Xn])● Values and number of occurrences increase

– Interchangeable values and rotation symmetry on variables

● But does not break all symmetry: [1,1,2,1,2] and [1,2,1,2,2]

Page 58: Global Constraints

Conclusions

● Symmetry of interchangeable values can be broken with value precedence constraints

● Value precedence can be decomposed into ternary constraints– Efficient and effective method to propagate

● Closely related to lex ordering columns– But combines row sum=1

● Can be generalized in many directions– Partial interchangeability– Set variables– …