global constraints toby walsh national ict australia and university of new south wales tw

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

Upload: hallie-engram

Post on 31-Mar-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Global Constraints

Toby WalshNational ICT Australia and

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

Page 2: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

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 Toby Walsh National ICT Australia and University of New South Wales tw

Conclusions

● Constraint programming is a powerful paradigm for solving many combinatorial optimization problems

● Global constraints are integral to this success● As we shall see, there are many different types of

global constraints– However, a few are central like AllDifferent, Roots,

Range, Slide, ...

Page 4: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

All Different

Example application

Page 5: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Golomb rulers

● Mark ticks on a rule– Distance between any two ticks (not just neighbouring)

is distinct● Applications

– Radio-astronomy– Crystallorgraphy– ...– Prob006 in CSPLib, www.csplib.org

Page 6: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Golomb rulers

● Simple solution– Exponentially long ruler– Ticks at 0, 1, 3, 7, 15, 31, ...

● Goal is to find minimal length ruler– Sequence of optimization problems– Is there a ruler of length m?– Is there a ruler of length m-1?– ...

Page 7: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Optimal Golomb rulers

● Known for up to 23 ticks● Distributed internet project to find larger

– 0,1– 0,1,3– 0,1,4,6– 0,1,4,9,11– 0,1,4,10,12,17

● Solutions grow as approximately O(n^2)

Page 8: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Golomb rulers as CSP

● Variable Xi for each tick– Value is position

● Auxiliary variable Dij for each inter-tick distance– Dij=|Xi-Xj|

● Two (global) constraints– X1<X2<..Xn– AllDifferent(D11,D12,D13,...)

Page 9: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Golomb ruler as CSP

● Not yet achieved “dream” of declarative programming– Need to break symmetry of inverting ruler

● D12< Dn-1n– Add implied constraints

● D12<D13 ...– Pure declarative specifications not quite enough!

Page 10: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

AllDifferent

● AllDifferent([X1,..Xn]) iff Xi=/=Xj for i<j● Useful in wide range of applications

– Timetabling (exams with common student must occur at different times)

– Production (each product must be produced at a different time)

– ...● Can propagate just using binary inequalities● But this decomposition hurts propagation

Page 11: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

AllDifferent

● AllDifferent([X1,..Xn]) iff Xi=/=Xj for i<j● Can propagate just using binary inequalities● But this decomposition hurts propagation

– X1 in {1,2}, X2 in {1,2}, X3 in {1,2,3}– X1 and X2 consume between them 2 values– X3 cannot therefore use either of these values– Therefore we can prune X3=1 and X3=2 leaving just

X3=3– How can we automate such reasoning?– How can we do this efficiently (< O(n^2))

Page 12: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

AllDifferent

● One of the oldest global constraints– In ALICE language [Lauriere 78]

● Found in every constraint solver today– GAC algorithm based on matching theory due to Regin

[AAAI 94], runs in O(dn^3/2)– BC algorithm using combinatorics due to Puget

[AAAI98], runs in O(nlogn)

Page 13: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

BC on AllDifferent

● Application of Hall's Theorem– Sometimes called the “marriage” theorem– Given k sets– Then there is an unique and distinct element in each set

iff any union of j of the sets has at least j elements for 0<j<=k

– E.g. S1={1,2}, S2={1,2} but not S1={1,2},S2={1,2} and S3={1,2}

Page 14: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Hall's theorem

● You wish to marry n men and women– Each woman declares who they are willing to marry

(some set of men)– Each man will be “happy” with whoever is willing to

marry them– Clearly any subset of j women, the number of men they

are willing to marry must be j or more (thus this condition is necessary)

– What is surprising is that it is also sufficient!

Page 15: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

BC on AllDifferent

● Hall Interval– Interval of values in which as many variables as

domain values– E.g. X1 in {1,2,3}, X2 in {1,2}, X3 in {1,2,3}– 3 variables in the interval [1..3]

● AllDifferent([X1,..Xn]) is BC iff – Each interval, the number of vars it covers is less than

the width of the interval– No variable outside a Hall Interval has a value within it

Page 16: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

BC on AllDifferent

● Consider X1 in {1,2}, X2 in {1,2}, X3 in {1,2,3}

Page 17: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

BC on AllDifferent

● Consider X1 in {1,2}, X2 in {1,2}, X3 in {1,2,3}● Then [1..2] is a Hall Interval covered by X1 and

X2● X3 has values inside this Hall Interval● We can prune these and make AllDifferent BC

Page 18: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

BC on AllDifferent

● Naïve algorithm considers O(n^2) intervals● Puget orders intervals

– Ordering has O(nlogn) cost– Then can go through them in order

Page 19: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

GAC on AllDifferent

● GAC algorithm based on matching theory due to Regin [AAAI 94]– runs in O(dn^3/2)

● Matching = set of edges with no two edges having a node in common

● Maximal matching = largest possible matching● Value graph = bipartite graph between variables

and their possible values

Page 20: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

GAC on AllDifferent

● Consider X1 in {1,3}, X2 in {1,3} and X3 in {1,2}

Page 21: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

GAC on AllDifferent

● Consider X1 in {1,3}, X2 in {1,3} and X3 in {1,2}

X1

X2

X3

1

2

3

Page 22: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

GAC on AllDifferent

● Consider X1 in {1,3}, X2 in {1,3} and X3 in {1,2}

X1

X2

X3

1

2

3

Page 23: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

GAC on AllDifferent

● Consider X1 in {1,3}, X2 in {1,3} and X3 in {1,2}

X1

X2

X3

1

2

3

Page 24: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

GAC on AllDifferent

● Consider X1 in {1,3}, X2 in {1,3} and X3 in {1,2}

X1

X2

X3

1

2

3

Page 25: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

GAC on AllDifferent

● Consider X1 in {1,3}, X2 in {1,3} and X3 in {2}

X1

X2

X3

1

2

3

Page 26: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

GAC on AllDifferent

● How do we find edges that don't belong to any maximum matching?

● Find one maximum matching● Identify strongly connected components● Prune other edges● Dominate cost is that of finding maximum

matching– Augmenting path algorithm of Hopcroft and Karp

Page 27: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Beyond AllDifferent

● Symmetric AllDifferent– Xi=j iff Xj=i

● Useful in sports scheduling– Team1 plays 2 iff Team2 plays 1

● GAC can be enforced in O(nm) time● Again based on maximum matching but now in

non-bipartite graph

Page 28: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Beyond AllDifferent

● Soft AllDifferent– Relax constraint that all values are different– Introduce “cost” variable

● Number of variables that need to change value to make it all different

● Number of binary inequalities not satisfied

Page 29: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Beyond AllDifferent

● NValues([X1,...,Xn],M) iff |{j | Xi=j}|=M● AllDifferent is special case when M=n● Useful when values represent a resource

– Minimize the number of resources used

Page 30: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Beyond AllDifferent

● Global cardinality constraint– GCC([X1,..Xn],[a1,..am],[b1,...bm]) iff

aj <= |{i | Xi=j }| <= bj for all j– In other words, j occurs between aj and bj times

● Again useful when values represent a resource– You have at least one night shift but no more than four

each week

Page 31: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Propagating GCC

● Regin gives O(n^2d) flow based algorithm for achieving GAC [AAAI 96]

● Improved recently to O(n^3/2 d) using matching theory

● We'll come back to a similar flow based propagator for the RANGE constraint

Page 32: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw

Conclusions

● AllDifferent is one of the oldest (and most useful) global constraints

● Efficient propagators exist for achieving GAC and BC

● When to choose BC over GAC? – Heuristic choice: BC often best when many more

values than variables, GAC when we are close to a permutation (number of vars=number of values)