1 / 93

Global Constraints

Global Constraints . Toby Walsh NICTA and University of New South Wales www.cse.unsw.edu.au/~tw. Overview: a tale of 3 global constraints. Value PRECEDENCE Symmetry breaking Decomposition does not hinder propagation NVALUES Computational complexity to the rescue REGULAR

Download Presentation

Global Constraints

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Overview: a tale of 3 global constraints • Value PRECEDENCE • Symmetry breaking • Decomposition does not hinder propagation • NVALUES • Computational complexity to the rescue • REGULAR • Formal languages to the rescue

  3. Why GLOBAL constraints? • The one thing that people in LP most envy about CP! • Capture common patterns • E.g. AllDifferent: variables take all different values • Each queen must be on a different column

  4. Why GLOBAL constraints? • The one thing that people in LP most envy about CP! • Capture common patterns • Provide effective pruning • E.g. complex pigeonhole arguments (these 4 variables have just 4 values between them so other variables must take values outside)

  5. Why GLOBAL constraints? • The one thing that people in LP most envy about CP! • Capture common patterns • Provide effective pruning • E.g. complex pigeonhole arguments (these 4 variables have just 4 values between them so other variables must take values outside) • Do so efficiently • E.g. O(n log n) time to enforce BC on AllDifferent

  6. Typical CP solver • Backtracking search • Try Queen1=col1 • Try Queen2=col3 • Else Queen2=col4 • Else … • Else Queen1=col2 • Try Queen2=col4 • Else Queen2=col5 • … • Else Queen1=col3 • …

  7. Typical CP solver • Backtracking search • Try Queen1=col1 • Constraint pruning removes • Queen2=col1 • Queen2=col2 • Queen3=col1 • Queen3=col3 • …

  8. Search tree • Branching • Queen1=col1 • Queen2=col3 • .. • Propagation AllDifferent(Queen1,..,Queen8)

  9. Propagators • Effective pruning • Enforce GAC or BC • Complex pigeonhole arguments • X1, X3, X6  {1,2,3} then X2  {1,2,3} • Efficiently • BC on AllDifferent in O(n log n) time • GAC on AllDifferent on O(n2.5) time • Called each node in a potentially exponential sized search tree!

  10. Propagators • Incremental • Each time we call them only a little changes (i.e. one variable is instantiated) • On backtracking, need to restore their state quickly (efficient data structures to do so like watched literals)

  11. Propagation • GAC • Each value for each variable can be extended to a satisfying assignment (aka support) of the global constraint • E.g. AllDifferent({1,2},{1,2},{1,2,3})

  12. Propagation • GAC • Each value for each variable can be extended to a satisfying assignment (aka support) of the global constraint • AC • GAC on binary constraints

  13. Propagation • GAC • Each value for each variable can be extended to a satisfying assignment (aka support) of the global constraint • BC • Max and min can be extended to a bound support (assignment between max and min)

  14. Global constraint • Constraint over parameterized number of variables • E.g. AllDifferent(X1,..,Xn) • n is not fixed • Compare binary constraint • X < Y • Fixed to 2 variables

  15. Global constraint • Constraint over parameterized number of variables • E.g. AllDifferent(X1,..,Xn) • n is not fixed • Cannot use brute force to make GAC • dn possible supports to try out in general • Must use smart algorithms!

  16. Value PRECEDENCE Global constraint for dealing with symmetry in a problem

  17. Value precedence • Used to deal with value symmetry • Prevent us finding symmetric (equivalent) solutions • Good example of “global” constraint where we can use an efficient encoding • Encoding gives us GAC • Asymptotically optimal, achieve GAC in O(nd) time • Good incremental complexity

  18. Value symmetry • Decision variables: • Col[Italy], Col[France], Col[Austria] ... • Domain of values: • red, yellow, green, ... • Constraints Col[Italy]=/=Col[France] Col[Italy]=/=Col[Austria] …

  19. 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

  20. Value symmetry • Solution: • Col[Italy]=red Col[France]=green Col[Spain]=red … • Values (colours) are interchangeable: • Swap red with green everywhere will still give us a solution

  21. 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

  22. Value precedence • Suppose all values from 1 to m are interchangeable • Might as well let X1=1

  23. 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

  24. 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

  25. 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

  26. 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

  27. 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

  28. 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 • Now cannot swap j with k so symmetry is broken

  29. Value precedence • Global constraint • Precedence([X1,..Xn]) iff min({i | Xi=j or i=n+1}) < min({i | Xi=k or i=n+2}) • E.g • Precedence([1,1,2,1,3,2,4,2,3]) • But not Precedence([1,1,2,1,4])

  30. Value precedence • Global constraint • Precedence([X1,..Xn]) iff min({i | Xi=j or i=n+1}) < min({i | Xi=k or i=n+2}) • Propagator proposed by [Law and Lee 2004] • Pointer based propagator but only for two interchangeable values at a time

  31. Value precedence • Precedence([j,k],[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

  32. Value precedence • Precedence([j,k],[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,i+1],[X1,..Xn]) for all i

  33. Value precedence • Precedence([j,k],[X1,..Xn]) iff min({i | Xi=j or i=n+1}) < min({i | Xi=k or i=n+2}) • 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}

  34. 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

  35. 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

  36. 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

  37. Propagating Precedence • Simple ternary encoding • Introduce Yi+1 for largest value used up to Xi • 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)

  38. Propagating Precedence • 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

  39. Propagating Precedence • 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) • Decomposition does not hinder propagation • Enforcing GAC on decomposition makes Precedence([X1,…,Xn]) GAC • Reason: constraint graph is Berge-acyclic

  40. Berge acyclicity • Constraint graph • Node for each variable • Edge between variables in the same constraint • Berge acyclicity • Graph does not contain any cycles (tree) • Local consistency = global consistency Trees are our friends

  41. 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 ..

  42. Partial value precedence • Shift1=nursePaul, Shift2=nursePeter, Shift3=nurseJane, Shift4=nursePaul .. • If Paul and Jane have the same skills, we can swap them (but not with Peter who is less qualified) • Shift1=nurseJane, Shift2=nursePeter, Shift3=nursePaul, Shift4=nurseJane …

  43. Partial value precedence • Values may partition into equivalence classes • 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)

  44. Partial value precedence • Values may partition into equivalence classes • 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

  45. Partial value precedence • Values may partition into equivalence classes • 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

  46. Partial value precedence • Values may partition into equivalence classes • 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, …

  47. 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 • Berge acyclic constraint graph • Can be generalized in many directions • Partial interchangeability, …

  48. NVALUES Computational complexity to the rescue!

  49. Global constraints • Hardcore algorithms • Data structures • Graph theory • Flow theory • Combinatorics • … • Computational complexity • Global constraints are often balanced on the limits of tractability!

  50. Computational complexity 101 • Some problems are essentially easy • Multiplication, O(n1.58) • Sorting, O(n log n) • Regular language membership, O(n) • Context free language membership, O(n3) .. • P (for “polynomial”) • Class of decision problems recognized by deterministic Turing Machine in polynomial number of steps • Decision problem • Question with yes/no answer? E.g. is this string in the regular language? Is this list sorted? …

More Related