1 / 67

Constraint Patterns

Constraint Patterns. Toby Walsh 4C, UCC & Uppsala.

brady-day
Download Presentation

Constraint Patterns

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. Constraint Patterns Toby Walsh 4C, UCC & Uppsala

  2. Fahiem Bacchus, David Basin, Christian Bessiere, Alan Bundy, Xinguang Chen, Berthe Choueiry, Elizabeth Churchill, Dave Clarke, Simon Colton, Joe Culberson, Carmel Domshlak, Pierre Flener, Jeremy Frank, Alan Frisch, Ian Gent, Fausto Giunchiglia, Ian Green, Emmanel Hebrard, Brahim Hnich, Holger Hoos, Zeynep Kiziltan, Ewan MacIntyre, Suresh Manandhar, Pedro Meseguer, Ian Miguel, Alex Nunes, Justin Pearson, Patrick Prosser, Francesca Rossi, Roberto Sebastiani, Paul Shaw, Dan Sheridan, John Slaney, Barbara Smith, Graham Steel, Kostas Stergiou, Armagan Tarim, Neven Tomov, Peter van Beek, Hans van Maaren, Brent Venable, Adolfo Villafiorita, Tetsuya Yoshida Thanks

  3. Thanks • Funding agencies SFI, EPSRC, SERC, EU, Royal Society, British Council • Universities & Research Institutes 4C, UCC, Uppsala Univ, ANU, Univ. of York, Strathclyde Univ., Edinburgh Univ., Univ. of Genova, IRST, INRIA

  4. Outline • Design patterns • Constraint patterns • Matrix model • Matrix symmetry • Dual model • Implied constraints • Constraint pattern repository • How to help

  5. Patterns • Christopher Alexander • Professor of architecture (UC Berkeley) • A Pattern Language • OUP, 1977 • Patterns document the implicit knowledge people need when designing buildings

  6. Patterns • 151. Small Meeting Rooms May be part of University (43), Town Hall (44), Office (146) .. • Conflict The larger meetings are, the less people get out of them • Resolution Make at least 70% of all meeting rooms really small, for 12 or less. Locate them in the most public parts, evenly scattered among the workplaces

  7. Design patterns • Design Patterns: Elements of Reusable OO Software • Eric Gamma, Richard Helm, Ralph Johnson & John Vlissides (aka Gang of Four) • 1998 Dr Dobb’s Journal Excellence in Programming award

  8. Design patterns • A recurring solution to a standard problem • Patterns have a context in which they apply • They must balance a set of opposing forces

  9. Design patterns • Mechanism for describing best practice & good design • Well engineered code exhibits many common patterns • Design patterns support and encourage good software engineering

  10. So you want to be an America’s Cup helmsman? • Learn the rules • Port tack gives way to starboard, ... • Learn basic principles • Cover tack to protect any lead, … • Study past races to learn winning patterns • Riding a gust to overtake on a downwind leg, …

  11. So you want to be a good software engineer? • Learn the rules • Algorithms, data structures, … • Learn basic principles • Data abstraction, … • Study other software engineers to learn winning patterns • Construct an iterator method so elements of a compound object can be accessed without exposing the underlying representation

  12. Constraint patterns • Record recurring patterns in constraint models • Deal with complex, interacting forces • Capture knowledge of expert modellers Smith in a Box

  13. Benefits • Help tackle modelling “bottleneck” • Toolkits extended to support common patterns • Row & col symmetry • Pattern automation • Implied constraint generation

  14. Possible drawbacks • Hard work • Effort of community not one individual • Modelling will remain an art • New problems often have unique feature or combination of features • Patterns are not executable • But we can automate aspects of them

  15. Constraint pattern • Pattern name • Context • Circumstances in which pattern occurs • Problem • Specific problem pattern solves • Forces • Opposing considerations when deciding a solution • Solution • Example

  16. Matrix models • Context for many constraint patterns • Itself a pattern! • Constraint program with array(s) of decision variables

  17. Matrix models • Often the problem has a matrix in the specification • Many timetabling and scheduling problems • Mike Trick schedules the College baseball league using a matrix model

  18. Matrix models • Common in other applications • Even if the matrix is not so obvious in the problem specification

  19. Warehouse location problem What warehouses to build to supply a set of stores? Prob034 in CSPLib Problem (and solution) taken from OPL manual Matrix models

  20. Open 0..1 0..1 0..1 0..1 Warehouse Supply 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Store 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Warehouse Warehouse location

  21. Each store has a warehouse: sum(i,Supply[i,j])=1 Warehouse capacity: sum(j,Supply[i,j]) <= c[i] Channelling constraints: Supply[i,j] <= Open[i] Optimization variable: Cost = sum(i,sum(j,Supply[i,j]*dist[i,j])) + c*sum(i,Open[i]) Open 0..1 0..1 0..1 0..1 Warehouse Supply 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Store 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Warehouse Warehouse location

  22. Open 0..1 0..1 0..1 0..1 Warehouse Supply 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Store 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Matrix model: spot the difference! =1 =1 … <c1 <c2 …

  23. Load 0..m 0..m 0..m 0..m Periods Sched 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Course 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Matrix model: spot the difference! =1 =1 … l<<d l<<d …

  24. Balance academic curriculum problem • Very similar matrix model • Channelling now to weighted sum • Optimization var changes • Exploit these patterns • Provide high level primitives • To state such problems compactly • To reason effectively

  25. Matrix model pattern • Pattern name: MatrixModel • Context An informal problem specification • Problem Decision variables which occur at repeated time periods, locations, … • Forces Similar constraints are posted on these variables Different data applies to the different locations, periods, … • Solution Consider a model with an array of decision variables. Input the data as a separate array • Example Warehouse location problem (prob034 in CSPLib)

  26. Diversity of matrix models • Combinatorial problems • BIBDs, magic squares, projective planes, … • Design • Rack configuration, template and slab design, … • Scheduling • Classroom, social golfer, … • Assignment • Warehouse location, progressive party, …

  27. Why use this pattern? • Ease of problem statement • Side constraints • Variable indexing • Improved constraint propagation • Symmetry breaking • Linear models

  28. Two (new) lines of research? • Matrix operations should become first class objects in CP • MATLAB & EXCEL could be extended into a constraint modelling languages

  29. Common constraints: Row or column sum Weighted row/col sum Single non-zero entry Matrix sum Scalar product Channelling Ordering rows/matrices This pretty much describes all the examples! These constraints should be provided as language primitives? Efficient and powerful propagators developed? Matrix models

  30. Ease of problem statement • Steel mill slab design • Prob038 in CSPLib • Nasty “colour” constraint • Stops it being simple knapsack problem • Channel into matrix model • Colour constraint easily and efficiently stated

  31. Steel mill slab design • 3 possible slab sizes (1, 3 or 4) • 2 colours per slab 3 2 2 1 1 1 1 1 1 a b c d e f g h i

  32. Example solution 2 h 3 1 e 2 1 b f a 1 1 1 1 g c d i (size 4) (size 3) (size 3) (size 1) (size 1) (size 1)

  33. Matrix model 3 2 2 1 1 1 1 1 1 oa ob oc od oe of og oh oi sum(j,Order[i,j])=1, sum(i,Order[i,j]*w[i])<Size[j] sum(i,Colour[i,j])<2

  34. Example solution 2 h 3 1 e 2 1 b f a 1 1 1 1 g c d i

  35. Variable indexing • Use variables to index into arrays • Element constraint • Typically reduces number of constraints needed by the domain size of the variable index • Hooker (and others) argue that such indexing is one of the major advantages CP has over IP

  36. Improved propagation • Matrix models for warehouse location Supply[store]=warehouse or Supply[store,warehouse]=1 • Warehouse capacity constraint • Difficult to state in 1-d Card({j|Supply[j]=i}) < c[i] • Difficult to propagate

  37. Improved propagation • Matrix models for warehouse location Supply[store]=warehouse or Supply[store,warehouse]=1 • Warehouse capacity constraint • Difficult to state in 1-d Card({j|Supply[j]=i}) < c[i] • Difficult to propagate • 2-d model purely linear!

  38. Matrix symmetry pattern • Often rows/cols in a decision matrix are symmetric • All weeks (cols) can be permuted in a timetable • All slabs (rows) of same size can be permuted Why the baby?

  39. Matrix symmetry A B Two identical bins

  40. Matrix symmetry A B 6 items to pack into bins: 1 2 3 4 5 6

  41. Matrix symmetry 5 6 3 4 1 2 A B One packing

  42. Matrix symmetry 6 5 4 3 2 1 A B Another packing

  43. Matrix symmetry • How do we eliminate such symmetry? 5 6 a) 3 4 1 2 A B 6 5 b) 4 3 2 1 A B

  44. Matrix model 5 6 a) 3 4 1 2 A B 6 5 b) 4 3 2 1 A B

  45. If we insist that row A lex row B, we remove a) from the solution set. Matrix model 5 6 a) 3 4 1 2 A B 6 5 b) 4 3 2 1 A B

  46. Row symmetry • Such row symmetry frequently occurs • Add constraint to order rows lexicographically • Total order => eliminates all row symmetry • Efficient & effective global constraints • GAC(X <lex Y) [Frisch, Hnich, Kiziltan, Miguel, Walsh, 02] • GAC(X0 <lex X1 <lex … <lex Xn) [Carlsson & Beldiceanu, 02] • Optimal, linear in number of variables

  47. Matrix symmetry • Symmetry in multiple dimensions • Balanced incomplete block design • v rows. • b columns. • r 1s per row. • k 1s per column. • s is scalar product between every pair of rows. Prob028 in CSPLib <7,7,3,3,1>

  48. Matrix symmetry • Lex order both rows and columns • Lex order must be in same direction • Called “double LEX” • Extends to higher dimensions

  49. Consistent Consistent Inconsistent Inconsistent

  50. Double LEX leaves symmetry 0 1 0 1 0 1 Swap 2 columns Swap row 1 and 3 1 0 1 0 1 0 Surprising as lex ordering rows breaks all row symmetry, & lex ordering cols breaks all col symmetry!

More Related