1 / 79

Case study 7: Langford’s problem

Case study 7: Langford’s problem. Model due to Barbara Smith. Outline. Introduction Langford’s problem Modelling it as a CSP Basic model Refined model Experimental Results Conclusions. Recipe. Create a basic model Decide on the variables Introduce auxiliary variables

raja
Download Presentation

Case study 7: Langford’s problem

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. Case study 7: Langford’s problem Model due to Barbara Smith

  2. Outline • Introduction • Langford’s problem • Modelling it as a CSP • Basic model • Refined model • Experimental Results • Conclusions

  3. Recipe • Create a basic model • Decide on the variables • Introduce auxiliary variables • For messy/loose constraints • Consider dual, combined or 0/1 models • Break symmetry • Add implied constraints • Customize solver • Variable, value ordering

  4. Langford’s problem • Prob024 @ www.csplib.org • Find a sequence of 8 numbers • Each number [1,4] occurs twice • Two occurrences of i are i numbers apart • Unique solution • 41312432

  5. Langford’s problem • L(k,n) problem • To find a sequence of k*n numbers [1,n] • Each of the k successive occrrences of i are i apart • We just saw L(2,4) • Due to the mathematician Dudley Langford • Watched his son build a tower which solved L(2,3)

  6. Langford’s problem • L(2,3) and L(2,4) have unique solutions • L(2,4n) and L(2,4n-1) have solutions • L(2,4n-2) and L(2,4n-3) do not • Computing all solutions of L(2,19) took 2.5 years! • L(3,n) • No solutions: 0<n<8, 10<n<17, 20, .. • Solutions: 9,10,17,18,19, .. A014552 Sequence: 0,0,1,1,0,0,26,150,0,0,17792,108144,0,0,39809640,326721800, 0,0,256814891280,2636337861200

  7. Basic model • What are the variables?

  8. Basic model • What are the variables? Variable for each occurrence of a number X11 is 1st occurrence of 1 X21 is 1st occurrence of 2 .. X12 is 2nd occurrence of 1 X22 is 2nd occurrence of 2 .. • Value is position in the sequence

  9. Basic model • What are the constraints? • Xij in [1,n*k] • Xij+1 = i+Xij • Alldifferent([X11,..Xn1,X12,..Xn2,..,X1k,..Xnk])

  10. Recipe • Create a basic model • Decide on the variables • Introduce auxiliary variables • For messy/loose constraints • Consider dual, combined or 0/1 models • Break symmetry • Add implied constraints • Customize solver • Variable, value ordering

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

  12. Break symmetry • Does the problem have any symmetry? • Of course, we can invert any sequence!

  13. Break symmetry • How do we break this symmetry?

  14. Break symmetry • How do we break this symmetry? • Many possible ways • For example, for L(3,9) • Either X92 < 14 (2nd occurrence of 9 is in 1st half) • Or X92=14 and X82<14 (2nd occurrence of 8 is in 1st half)

  15. Recipe • Create a basic model • Decide on the variables • Introduce auxiliary variables • For messy/loose constraints • Consider dual, combined or 0/1 models • Break symmetry • Add implied constraints • Customize solver • Variable, value ordering

  16. What about dual model? • Can we take a dual view?

  17. What about dual model? • Can we take a dual view? • Of course we can, it’s a permutation!

  18. Dual model • What are the variables? • Variable for each position i • What are the values?

  19. Dual model • What are the variables? • Variable for each position i • What are the values? • If use the number at that position, we cannot use an all-different constraint • Each number occurs not once but k times

  20. Dual model • What are the variables? • Variable for each position i • What are the values? • Solution 1: use values from [1,n*k] with the value i*n+j standing for the ith occurrence of j • Now want to find a permutation of these numbers subject to the distance constraint

  21. Dual model • What are the variables? • Variable for each position i • What are the values? • Solution 2: use as values the numbers [1,n] • Each number occurs exactly k times • Fortunately, there is a generalization of all-different called the global cardinality constraint (gcc) for this

  22. Global cardinality constraint • Gcc([X1,..Xn],l,u) enforces values used by Xi to occur between l and u times • All-different([X1,..Xn]) = Gcc([X1,..Xn],1,1) • Regin’s algorithm enforces GAC on Gcc in O(n^2.d) • Regin’s papers are tough to follow but this seems to beat his algorithm for all-different!?

  23. Dual model • What are the constraints? • Gcc([D1,…Dk*n],k,k) • Distance constraints?

  24. Dual model • What are the constraints? • Gcc([D1,…Dk*n],k,k) • Distance constraints: • Di=j then Di+j+1=j

  25. Combined model • Primal and dual variables • Channelling to link them • What do the channelling constraints look like?

  26. Combined model • Primal and dual variables • Channelling to link them • Xij=k implies Dk=i

  27. Solving choices? • Which variables to assign? • Xij or Di

  28. Solving choices? • Which variables to assign? • Xij or Di, doesn’t seem to matter • Which variable ordering heuristic? • Fail First or Lex?

  29. Solving choices? • Which variables to assign? • Xij or Di, doesn’t seem to matter • Which variable ordering heuristic? • Fail First very marginally better than Lex • How to deal with the permutation constraint? • GAC on the all-different • AC on the channelling • AC on the decomposition

  30. Solving choices? • Which variables to assign? • Xij or Di, doesn’t seem to matter • Which variable ordering heuristic? • Fail First very marginally better than Lex • How to deal with the permutation constraint? • AC on the channelling is often best for time

  31. Conclusions • Modelling is an art but there are patterns • Develop basic model • Decide on the variables and their values • Use auxiliary variables to represent constraints compactly/efficiently • Consider dual, combined and 0/1 models • Break symmetry • Add implied constraints • Customize solver for your model

  32. Case study 8: social golfers problem Model again due to Barbara Smith

  33. Outline • Introduction • Social golfers problem • Modelling it as a CSP • Basic model • Refined model • Experimental Results • Conclusions

  34. Social golfers problem • Prob013 @ www.csplib.org • 32 golfers wish to play in 8 groups of 4 each week • No two play in the same group more than once • How many weeks can they play?

  35. Social golfers problem • Prob013 @ www.csplib.org • 32 golfers wish to play in 8 groups of 4 each week • No two play in the same group more than once • How many weeks can they play? • 9 weeks and this is optimal

  36. Social golfers problem • Of course, generalize problem to g groups of s players over w weeks • Kirkman’s schoolgirls’ problem [Lady’s & Gentleman’s Diary 1850] “… a schoolmistress was in the habit of taking her girls for a daily walk. The girls were 15 in number, and were arranged in 5 rows of 3 each, so that each girl might have 2 companions. The problem is to so dispose them so that for 7 consecutive days no girl will walk with any of her school-fellows in a triplet twice …” This is equivalent to social golfers problem of 5 groups of 3 players over 7 weeks

  37. Recipe • Create a basic model • Decide on the variables • Introduce auxiliary variables • For messy/loose constraints • Consider dual, combined or 0/1 models • Break symmetry • Add implied constraints • Customize solver • Variable, value ordering

  38. Basic model • What are the variables?

  39. Basic model • What are the variables? • Group_ij is the set of s golfers assigned to group i in period j • But I haven’t shown you set variables before!

  40. Set variables • CSP variables can range over (finite) domains like integers • X1 is 1, 2, 3 or 4 • Or over sets of (finite) domains • Y1 is {}, {1}, {2}, or {1,2}

  41. Set variables • CSP variables can range over (finite) domains like integers • X1 is 1, 2, 3 or 4 • Or over sets of (finite) domains • Y1 is {}, {1}, {2}, or {1,2} • Usually set operations can be posted as constraints on these set variables • Y1 subset Z1, Y1 intersect Z1 = {}, 1 in Y1, …

  42. Set variables • Set variables are potentially expensive to reason about • If X1 is a subset of Y1, then X1 has exponentially many possible values • Compromise • CSP solvers just maintain upper and lower bounds on set variable • {} subseteq X1 subseteq {1,2}

  43. Set variables • Set variables are potentially expensive to reason about • If X1 is a subset of Y1, then X1 has exponentially many possible values • Compromise • CSP solvers just maintain upper and lower bounds on set variable • {} subseteq X1 subseteq {1,2} • We loose the ability to represent disjunction E.g. X1= {1} or X1={2} but X1=/ {1,2}

  44. Basic model • What are the variables? • Group_ij is the set of s golfers assigned to group i in period j • What are constraints?

  45. Basic model • What are the variables? • Group_ij is the set of s golfers assigned to group i in period j • What are constraints? • Size of group, |Group_ij|=s • Groups do not overlap, Group_ij intersect Group_i’j={} • Never meet twice, for j<l . | Group_ij intersect Group_kl | <= 1

  46. Break symmetry • What symmetry does the problem have?

  47. Break symmetry • What symmetry does the problem have? • Lots! • Players are symmetrical • Groups are symmetrical • Weeks are symmetrical

  48. Break symmetry • What symmetry does the problem have? • Lots! • Players are symmetrical • Groups are symmetrical • Weeks are symmetrical • Set variables saved us worrying about order within group

  49. Break symmetry • We can assign some values and break some of this symmetry

  50. Break symmetry • We can assign some values and break some of this symmetry • Make first week: {1,2,..s}, {s+1,s+2,..2s},…

More Related