Constraint Programming: modelling - PowerPoint PPT Presentation

constraint programming modelling n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Constraint Programming: modelling PowerPoint Presentation
Download Presentation
Constraint Programming: modelling

play fullscreen
1 / 84
Constraint Programming: modelling
146 Views
Download Presentation
bess
Download Presentation

Constraint Programming: modelling

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Constraint Programming: modelling Toby Walsh NICTA and UNSW

  2. Golomb rulers • Mark ticks on a ruler • Distance between any two ticks (not just neighbouring ticks) is distinct • Applications in radio-astronomy, cystallography, … • http://www.csplib.org/prob/prob006

  3. Golomb rulers • Simple solution • Exponentially long ruler • Ticks at 0,1,3,7,15,31,63,… • Goal is to find minimal length rulers • turn optimization problem into sequence of satisfaction problems Is there a ruler of length m? Is there a ruler of length m-1? ….

  4. Optimal Golomb rulers • Known for up to 23 ticks • Distributed internet project to find large rulers 0,1 0,1,3 0,1,4,6 0,1,4,9,11 0,1,4,10,12,17 0,1,4,10,18,23,25 Solutions grow as approximately O(n^2)

  5. Modelling the Golomb ruler • Variable, Xi for each tick • Value is position on ruler • Naïve model with quaternary constraints • For all i>j,k>l>j |Xi-Xj| \= |Xk-Xl|

  6. Problems with naïve model • Large number of quaternary constraints • O(n^4) constraints • Looseness of quaternary constraints • Many values satisfy |Xi-Xj| \= |Xk-Xl| • Limited pruning

  7. A better non-binary model • Introduce auxiliary variables for inter-tick distances • Dij = |Xi-Xj| • O(n^2) ternary constraints • Post single large non-binary constraint • alldifferent([D11,D12,…]). • Tighter constraints and denser constraint graph

  8. Other modeling issues • Symmetry • A ruler can always be reversed! • Break this symmetry by adding constraint: D12 < Dn-1,n • Also break symmetry on Xi X1 < X2 < … Xn • Such tricks important in many problems

  9. Other modelling issues • Additional (implied) constraints • Don’t change set of solutions • But may reduce search significantly E.g. D12 < D13, D23 < D24, … E.g. D1k at least sum of first k integers • Pure declarative specifications are not enough!

  10. Solving issues • Labeling strategies often very important • Smallest domain often good idea • Focuses on “hardest” part of problem • Best strategy for Golomb ruler is instantiate variables in strict order • Heuristics like fail-first (smallest domain) not effective on this problem!

  11. Experimental results

  12. Something to try at home? • Circular (or modular) Golomb rulers • Inter-tick distance variables more central, removing rotational symmetry? • 2-d Golomb rulers All examples of “graceful” graphs

  13. Summary • Modelling decisions: • Auxiliary variables • Implied constraints • Symmetry breaking constraints • More to constraints than just declarative problem specifications!

  14. Case study 2: all interval series

  15. All interval series • Prob007 at www.csplib.org • Comes from musical composition • Traced back to Alban Berg • Extensively used by Ernst Krenek Op.170 “Quaestio temporis”

  16. All interval series • Take the 12 standard pitch classes • c, c#, d, .. • Represent them by numbers 0, .., 11 • Find a sequence so each occurs once • Each difference occurs once

  17. All interval series • Can generalize to any n (not just 12) Find Sn, a permutation of [0,n) such that |Sn+1-Sn| are all distinct • Finding one solution is easy

  18. All interval series • Can generalize to any n (not just 12) Find Sn, a permutation of [0,n) such that |Sn+1-Sn| are all distinct • Finding one solution is easy [n,1,n-1,2,n-2,.., floor(n/2)+2,floor(n/2)-1,floor(n/2)+1,floor(n/2)] Giving the differences [n-1,n-2,..,2,1] Challenge is to find all solutions!

  19. Basic methodology • Devise basic CSP model • What are the variables? What are the constraints? • Introduce auxiliary variables if needed • Consider dual or combined models • Break symmetry • Introduce implied constraints

  20. Basic CSP model • What are the variables?

  21. Basic CSP model • What are the variables? Si = j if the ith note is j • What are the constraints?

  22. Basic CSP model • What are the variables? Si = j if the ith note is j • What are the constraints? Si in [0,n) All-different([S1,S2,… Sn]) Forall i<i’ |Si+1 - Si| =/ |Si’+1 - Si’| Will this model be any good? If so, why? If not, why not?

  23. Basic methodology • Devise basic CSP model • What are the variables? What are the constraints? • Introduce auxiliary variables if needed • Consider dual or combined models • Break symmetry • Introduce implied constraints

  24. Improving basic CSP model • Is it worth introducing any auxiliary variables? • Are there any loose or messy constraints we could better (more compactly?) express via some auxiliary variables?

  25. Improving basic CSP model • Is it worth introducing any auxiliary variables? • Yes, variables for the pairwise differences Di = |Si+1 - Si| • Now post single large all-different constraint Di in [1,n-1] All-different([D1,D2,…Dn-1])

  26. Basic methodology • Devise basic CSP model • What are the variables? What are the constraints? • Introduce auxiliary variables if needed • Consider dual or combined models • Break symmetry • Introduce implied constraints

  27. Break symmetry • Does the problem have any symmetry?

  28. Break symmetry • Does the problem have any symmetry? • Yes, we can reverse any sequence S1, S2, … Sn is an all-inverse series Sn, …, S2, S1 is also • How do we eliminate this symmetry?

  29. Break symmetry • Does the problem have any symmetry? • Yes, we can reverse any sequence S1, S2, …, Sn is an all-inverse series Sn, …, S2, S1 is also • How do we eliminate this symmetry? • As with Golomb ruler! D1 < Dn-1

  30. Break symmetry • Does the problem have any other symmetry?

  31. Break symmetry • Does the problem have any other symmetry? • Yes, we can invert the numbers in any sequence 0, n-1, 1, n-2, … map x onto n-1-x n-1, 0, n-2, 1, … • How do we eliminate this symmetry?

  32. Break symmetry • Does the problem have any other symmetry? • Yes, we can invert the numbers in any sequence 0, n-1, 1, n-2, … map x onto n-1-x n-1, 0, n-2, 1, … • How do we eliminate this symmetry? S1 < S2

  33. Basic methodology • Devise basic CSP model • What are the variables? What are the constraints? • Introduce auxiliary variables if needed • Consider dual or combined models • Break symmetry • Introduce implied constraints

  34. Implied constraints • Are there useful implied constraints to add?

  35. Implied constraints • Are there useful implied constraints to add? • Hmm, unlike Golomb ruler, we only have neighbouring differences • So, no need to consider transitive closure

  36. Implied constraints • Are there useful implied constraints to add? • Hmm, unlike Golomb ruler, we are not optimizing • So, no need to improve propagation for optimization variable

  37. Performance • Basic model is poor • Refined model able to compute all solutions up to n=14 or so • GAC on all-different constraints very beneficial • As is enforcing GAC on Di = |Si+1-Si| This becomes too expensive for large n So use just bounds consistency (BC) for larger n

  38. Case study 3: orthogonal Latin squares

  39. Modelling decisions • Many different ways to model even simple problems • Combining models can be effective • Channel between models • Need additional constraints • Symmetry breaking • Implied (but logically) redundant

  40. Latin square • Each colour appears once on each row • Each colour appears once on each column • Used in experimental design • Six people • Six one-week drug trials

  41. Orthogonal Latin squares • Find a pair of Latin squares • Every cell has a different pair of elements • Generalized form: • Find a set of m Latin squares • Each possible pair is orthogonal

  42. 1 2 3 4 1 2 3 4 2 1 4 3 3 4 1 2 3 4 1 2 4 3 2 1 4 3 2 1 2 1 4 3 11 22 33 44 23 14 41 32 34 43 12 21 42 31 24 13 Two 4 by 4 Latin squares No pair is repeated Orthogonal Latin squares

  43. History of (orthogonal) Latin squares • Introduced by Euler in 1783 • Also called Graeco-Latin or Euler squares • No orthogonal Latin square of order 2 • There are only 2 (non)-isomorphic Latin squares of order 2 and they are not orthogonal

  44. History of (orthogonal) Latin squares • Euler conjectured in 1783 that there are no orthogonal Latin squares of order 4n+2 • Constructions exist for 4n and for 2n+1 • Took till 1900 to show conjecture for n=1 • Took till 1960 to show false for all n>1 • 6 by 6 problem also known as the 36 officer problem “… Can a delegation of six regiments, each of which sends a colonel, a lieutenant-colonel, a major, a captain, a lieutenant, and a sub-lieutenant be arranged in a regular 6 by 6 array such that no row or column duplicates a rank or a regiment?”

  45. More background • Lam’s problem • Existence of finite projective plane of order 10 • Equivalent to set of 9 mutually orthogonal Latin squares of order 10 • In 1989, this was shown not to be possible after 2000 hours on a Cray (and some major maths) • Orthogonal Latin squares also used in experimental design

  46. A simple 0/1 model • Suitable for integer programming • Xijkl = 1 if pair (i,j) is in row k column l, 0 otherwise • Avoiding advice never to use more than 3 subscripts! • Constraints • Each row contains one number in each square Sum_jl Xijkl = 1 Sum_il Xijkl = 1 • Each col contains one number in each square Sum_jk Xijkl = 1 Sum_ik Xijkl = 1

  47. A simple 0/1 model • Additional constraints • Every pair of numbers occurs exactly once Sum_kl Xijkl = 1 • Every cell contains exactly one pair of numbers Sum_ij Xijkl = 1 Is there any symmetry?

  48. Symmetry removal • Important for solving CSPs • Especially for proofs of optimality? • Orthogonal Latin square has lots of symmetry • Permute the rows • Permute the cols • Permute the numbers 1 to n in each square • How can we eliminate such symmetry?

  49. Symmetry removal • Fix first row 11 22 33 … • Fix first column 11 23 32 .. • Eliminates all symmetry?

  50. What about a CSP model? • Exploit large finite domains possible in CSPs • Reduce number of variables • O(n^4) -> ? • Exploit non-binary constraints • Problem states that squares contain pairs that are all different • All-different is a non-binary constraint our solvers can reason with efficiently