Presentation is loading. Please wait.

Presentation is loading. Please wait.

Global Constraints Toby Walsh NICTA and University of New South Wales www.cse.unsw.edu.au/~tw.

Similar presentations


Presentation on theme: "Global Constraints Toby Walsh NICTA and University of New South Wales www.cse.unsw.edu.au/~tw."— Presentation transcript:

1 Global Constraints Toby Walsh NICTA and University of New South Wales www.cse.unsw.edu.au/~tw

2 Quick advert ZUNSW is in Sydney ZRegularly voted in top 10 cities in World ZUNSW is one of top universities in Australia ZIn top 100 universities in world ZTalk to me about our PhD programme! ZAlso happy to have PhDs/PostDocs visit for weeks/months/years …

3 Quick advert ZUNSW is in Sydney ZRegularly voted in top 10 cities in World ZUNSW is one of top universities in Australia ZIn top 100 universities in world ZTalk to me about our PhD programme! ZAlso happy to have PhDs/PostDocs visit for weeks/months/years … ZAttend CP/KR/ICAPS in Sept

4 Constraint programming Z“Constraint programming represents one of the closest approaches computer science has yet made to the Holy Grail of programming: the user states the problem, the computer solves it”. ZGene Freuder, Constraints, April 1997

5 Suduko Puzzle = [X11,X12,X13, …X19, X21,X22, ………X29,.. X91,X92, ……….X99] Puzzle :: 1..9 alldifferent([X11,..X19]) alldifferent([X21,..X29]).. alldifferent([X11,..X91]).. alldifferent([X11,..X33])..

6 Comparison with OR ZCP Zrich modelling language Zmany different global constraints Zfast local inference on these global constraints Zgood for finding feasible and tightly constrained solutions Z(I)LP Zeverything has to be a linear inequality Zlimited range of solution methods (simplex,...) Zgood at proving optimality

7 Global constraints ZAny non-binary constraint ZAllDifferent ZNvalues ZElement ZLex ordering ZStretch constraint ZSequence constraint Z... ZEach comes with an efficient propagator...

8 All Different

9 Golomb rulers ZMark ticks on a rule ZDistance between any two ticks (not just neighbouring) is distinct ZSpecial type of graceful graph ZApplications ZRadio-astronomy, crystallorgraphy,... ZProb006 in CSPLib

10 Golomb rulers ZSimple solution ZExponentially long ruler ZTicks at 0, 1, 3, 7, 15, 31,... ZGoal is to find minimal length ruler ZSequence of optimization problems ZIs there a ruler of length m? ZIs there a ruler of length m-1? Z...

11 Optimal Golomb rulers ZKnown for up to 23 ticks ZDistributed internet project to find larger Z0,1 Z0,1,3 Z0,1,4,6 Z0,1,4,9,11 Z0,1,4,10,12,17 ZSolutions grow as approximately O(n^2)

12 Golomb rulers as CSP ZVariable Xi for each tick ZValue is position ZAuxiliary variable Dij for each inter-tick distance ZDij=|Xi-Xj| ZTwo (global) constraints ZX1<X2<..Xn ZAllDifferent(D11,D12,D13,...)

13 Golomb ruler as CSP ZNot yet achieved “dream” of declarative programming ZNeed to break symmetry of inverting ruler ZD12< Dn-1n ZAdd implied constraints ZD12<D13... ZPure declarative specifications not quite enough!

14 AllDifferent ZAllDifferent([X1,..Xn]) iff Xi=/=Xj for i<j ZUseful in wide range of applications ZTimetabling (exams with common student must occur at different times) ZProduction (each product must be produced at a different time) Z... ZCan propagate just using binary inequalities ZBut this decomposition hurts propagation

15 AllDifferent ZAllDifferent([X1,..Xn]) iff Xi=/=Xj for i<j ZCan propagate just using binary inequalities ZBut this decomposition hurts propagation ZX1 in {1,2}, X2 in {1,2}, X3 in {1,2,3} ZX3 cannot be 1 or 2 ZHow can we automate such reasoning? ZHow can we do this efficiently (less than O(n^2) time)

16 AllDifferent ZOne of the oldest global constraints ZIn ALICE language [Lauriere 78] ZFound in every constraint solver today ZGAC algorithm based on matching theory due to Regin [AAAI 94], runs in O(dn^3/2) ZBC algorithm using combinatorics due to Puget [AAAI98], runs in O(nlogn)

17 BC on AllDifferent ZApplication of Hall's Theorem ZSometimes called the “marriage” theorem ZGiven k sets ZThen 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 ZE.g. S1={1,2}, S2={1,2} but not S1={1,2},S2={1,2} and S3={1,2}

18 Hall's theorem ZYou wish to marry n men and women ZEach woman declares who they are willing to marry (some set of men) ZEach man will be “happy” with whoever is willing to marry them ZGiven any subset of j women, the number of men they are willing to marry must be j or more (thus this condition is necessary) ZWhat is surprising is that it is also sufficient!

19 BC on AllDifferent ZHall Interval ZInterval of values in which as many variables as domain values ZE.g. X1 in {1,2,3}, X2 in {1,2}, X3 in {1,2,3} Z3 variables in the interval [1..3] ZAllDifferent([X1,..Xn]) is BC iff ZEach interval, the number of vars it covers is less than or equal to the width of the interval ZNo variable outside a Hall Interval has a value within it

20 BC on AllDifferent ZConsider X1 in {1,2}, X2 in {1,2}, X3 in {1,2,3}

21 BC on AllDifferent ZConsider X1 in {1,2}, X2 in {1,2}, X3 in {1,2,3} ZThen [1..2] is a Hall Interval covered by X1 and X2 ZX3 has values inside this Hall Interval ZWe can prune these and make AllDifferent BC

22 BC on AllDifferent ZNaïve algorithm considers O(n^2) intervals ZPuget orders intervals ZOrdering has O(nlogn) cost ZThen can go through them in order

23 Beyond AllDifferent ZNValues([X1,...,Xn],M) iff |{j | Xi=j}|=M ZAllDifferent is special case when M=n ZUseful when values represent a resource ZMinimize the number of resources used

24 Beyond AllDifferent ZGlobal cardinality constraint ZGCC([X1,..Xn],[a1,..am],[b1,...bm]) iff aj <= |{i | Xi=j }| <= bj for all j ZIn other words, j occurs between aj and bj times ZAgain useful when values represent a resource ZYou have at least one night shift but no more than four each week

25 Conclusions ZAllDifferent is one of the oldest (and most useful) global constraints ZEfficient propagators exist for achieving GAC and BC ZWhen to choose BC over GAC? ZHeuristic choice: BC often best when many more values than variables, GAC when we are close to a permutation (number of vars=number of values)

26 Lex ordering ZWidely useful ZEspecially for symmetry breaking ZBreaking row and column symmetry in matrix models ZAvailable in most (all?) solvers ZGood example of pointer based global constraint ZPointers save re-doing work ZGood incremental behaviour ZO(n) in general, but amortised O(n) cost down a branch

27 Motivation ZMany problems can be modelled by matrices of decision variables.

28 Motivation ZMany problems can be modelled by matrices of decision variables. ZE.g. Combinatorial Problems ZBalanced Incomplete Block Design. ZX[i,j]=0 or 1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 Parameters = (7,7,3,3,1) 0 0 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 1 0 0

29 Motivation ZMany problems can be modelled by matrices of decision variables ZFrequently these matrices exhibit row and/or column symmetry

30 Motivation ZMany problems can be modelled by matrices of decision variables ZFrequently these matrices exhibit row and/or column symmetry ZWe can permute the rows/columns in any (non)solution to obtain another (non)solution

31 Motivation ZWhen rows and columns can be permuted ZAn n by m matrix model with row and column symmetry has Zn! m! symmetries Zgrows super-exponentially ZToo many symmetric search states ZIt can be very expensive to visit all the symmetric branches of a search tree

32 Motivation ZBreaking symmetry is very important! ZBreaking all row and column symmetries is difficult ZNo one has an effective way of dealing with all row and column symmetries. ZSymmetry breaking methods have to deal with very large number of symmetries. ZThe effort required could easily be exponential.

33 Symmetry in CP ZAdd symmetry breaking constraints ZLeave at least one solution ZEliminate some/all symmetric solutions ZModify search algorithm ZIgnore symmetric parts of the search space ZAdapt branching heuristic ZTo explore branches which are most likely not to be symmetric

34 Example ZConsider 2 identical bins: BA

35 Example ZConsider 2 identical bins: We must pack 6 items: 341652 BA

36 Example ZHere is one solution: 12 3 65 4 BA

37 Example ZHere is another: BA 1 3 5 2 6 4

38 Example ZIs there any fundamental difference? 1 3 5 2 6 4 a) b) AB BA 1 3 5 2 6 4

39 Example ZConsider a matrix model: 1 3 5 2 6 4 a) b) AB BA 1 3 5 2 6 4 1 2 3 4 5 6 A 1 0 1 0 1 0 B 0 1 0 1 0 1 1 2 3 4 5 6 A 0 1 0 1 0 1 B 1 0 1 0 1 0

40 Example ZConsider a matrix model: If we insist that row A  lex row B, we remove a) from the solution set. b) BA 1 3 5 2 6 4 1 2 3 4 5 6 A 1 0 1 0 1 0 B 0 1 0 1 0 1 1 2 3 4 5 6 A 0 1 0 1 0 1 B 1 0 1 0 1 0

41 Example ZNotice that items 3 and 4 are identical. b) BA 1 3 5 2 6 4 c) 1 4 5 2 6 3 1 2 3 4 5 6 A 1 0 1 0 1 0 B 0 1 0 1 0 1 1 2 3 4 5 6 A 0 1 1 0 0 1 B 1 0 0 1 1 0

42 Example ZNotice that items 3 and 4 are identical. b) BA 1 3 5 2 6 4 If we insist that col 3  lex col 4, we remove c) from the solution set. 1 2 3 4 5 6 A 1 0 1 0 1 0 B 0 1 0 1 0 1 1 2 3 4 5 6 A 0 1 1 0 0 1 B 1 0 0 1 1 0

43 Lexicographic Ordering ZUsed to order dictionaries [A,B,C] ≤ lex [D,E,F] ZA<D or Z(A=D and B<E ) or Z(A=D and B=E and C<F) or Z(A=D and B=E and C=F)

44 ZLexicographic ordering is total ZForcing the rows to be lexicographically ordered breaks all row symmetry Breaking Row (Column) Symmetry ABC DEF GHI [A B C]  lex [D E F]  lex [G H I] [G H I] lexicographic ordering anti-lexicographic ordering

45 Breaking Row and Column Symmetries ZBreaking both row and column symmetries is difficult ZRows and columns intersect ZAfter constraining the rows to be lexicographically ordered Zwe distinguish the columns Zthe columns are not symmetric anymore!

46 Good News ZEach symmetry class of assignments has at least one element where both the rows and the columns are lexicographically ordered ZBut there may be no element with rows lex ordered and columns anti-lex ordered ZTo break row and column symmetries, we can insist that the rows and columns are both lexicographically ordered (double-lex) ZExtends to higher dimensions

47 Bad News  ZA symmetry class of assignments may have more than one element where both the rows and the columns are lexicographically ordered ZDouble-lex does not break all row and column symmetries 01 01 10 01 10 10 swap the columns swap row 1 and row 3

48 GACLex ZA new family of global constraints.

49 GACLex ZA new family of global constraints. Non-binary constraint. Specialised propagator.

50 GACLex ZA new family of global constraints ZLinear time complexity

51 GACLex ZA new family of global constraints ZLinear time complexity ZEnsures that a pair of vectors of variables are lexicographically ordered. 0142 2987  lex

52 How GACLex Works ZConsider the following example x{2}{1,3,4}{2,3,4}{1}{3,4,5} y{0,1,2}{1}{1,2,3}{0}{0,1,2} We want to enforce GAC on: x  lex y.

53 A Tale of Two Pointers ZWe use two pointers, alpha and beta, to avoid repeatedly traversing the vectors

54 A Tale of Two Pointers x{2}{1,3,4}{2,3,4}{1}{3,4,5} y{0,1,2}{1}{1,2,3}{0}{0,1,2} Most significant index Alpha: all variables at more significant indices are ground and equal

55 A Tale of Two Pointers beta: most significant index from which the two vectors’ tails necessarily violate the constraint. x{2}{1,3,4}{2,3,4}{1}{3,4,5} y{0,1,2}{1}{1,2,3}{0}{0,1,2}

56 Pointer initialization Zalpha ZScan through vector from start ZAt most O(n) time Zbeta ZScan through vector from end ZAt most O(n) time

57 Failure Inconsistent if beta < alpha. alpha: index such that all variables at more significant indices are ground and equal. beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

58 How GACLex Works We maintain alpha and beta as assignments made. alpha: index such that all variables at more significant indices are ground and equal. beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

59 How GACLex Wroks We maintain alpha and beta as assignments made. When beta = alpha + 1 we enforce bounds consistency on: x alpha < y alpha alpha: index such that all variables at more significant indices are ground and equal. beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

60 How GACLex Works We maintain alpha and beta as assignments made. When beta = alpha + 1 we enforce bounds consistency on: x alpha < y alpha When beta > alpha + 1 we enforce bounds consistency on: x alpha <= y alpha alpha: index such that all variables at more significant indices are ground and equal. beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

61 Complexity ZInitialisation: O(n) ZPropagation: We enforce bounds consistency between at most n pairs of variables: x alpha < y alpha or x alpha  y alpha. Cost: b. Overall cost: O(nb). Complexity can be amortized down branch of search tree alpha and beta move at most O(n) steps

62 Conclusions ZGlobal constraints ZOne of the special features of constraint programming ZInteresting meeting point for algorithms, combinatorics, computational complexity, formal languages, …


Download ppt "Global Constraints Toby Walsh NICTA and University of New South Wales www.cse.unsw.edu.au/~tw."

Similar presentations


Ads by Google