Constraint Patterns Toby Walsh 4C, UCC & Uppsala.

Slides:



Advertisements
Similar presentations
Non-Binary Constraint Satisfaction Toby Walsh Cork Constraint Computation Center.
Advertisements

Modelling a Steel Mill Slab Design Problem Alan Frisch, Ian Miguel, Toby Walsh AI Group University of York.
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Optimizing Compilers for Modern Architectures Allen and Kennedy, Chapter 13 Compiling Array Assignments.
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
Architecture-dependent optimizations Functional units, delay slots and dependency analysis.
Exploiting Symmetry in Planning Maria Fox Durham Planning Group University of Durham, UK.
Reducing Symmetry in Matrix Models Alan Frisch, Ian Miguel, Toby Walsh (York) Pierre Flener, Brahim Hnich, Zeynep Kiziltan, Justin Pearson (Uppsala)
Case study 5: balanced academic curriculum problem Joint work with Brahim Hnich and Zeynep Kiziltan (CPAIOR 2002)
Non-binary constraints: modelling Toby Walsh Cork Constraint Computation Center.
Generating Implied Constraints via Proof Planning Alan Frisch, Ian Miguel, Toby Walsh Dept of CS University of York EPSRC funded project GR/N16129.
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
Leeds: 6 June 02Constraint Technology for the Masses Alan M. Frisch Artificial Intelligence Group Department of Computer Science University of York Collaborators:
ANU COMP2110 Software Design in 2003 Lecture 16Slide 1 Lecture 16: Introduction to design patterns 1What are they? 2Where do they come from? 3Why study.
Consistency & Propagation with Multiset Constraints Toby Walsh 4C, UCC & Uppsala.
Transforming and Refining Abstract Constraint Specifications Alan Frisch, Brahim Hnich*, Ian Miguel, Barbara Smith, and Toby Walsh *Cork Constraint Computation.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall Process Specifications and Structured Decisions Systems Analysis and Design, 8e Kendall.
Symmetry as a Prelude to Implied Constraints Alan Frisch, Ian Miguel, Toby Walsh University of York.
Alan M. Frisch Artificial Intelligence Group Department of Computer Science University of York Extending the Reach of Constraint Technology through Reformulation.
CGRASS A System for Transforming Constraint Satisfaction Problems Alan Frisch, Ian Miguel AI Group University of York Toby Walsh 4C.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Design Patterns CS is not simply about programming
Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)
Matrix Modelling Pierre Flener (Uppsala) Alan M. Frisch (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Ian Miguel, and Toby Walsh (York)
Modelling and Solving English Peg Solitaire Chris Jefferson, Angela Miguel, Ian Miguel, Armagan Tarim. AI Group Department of Computer Science University.
CISC 879 : Software Support for Multicore Architectures John Cavazos Dept of Computer & Information Sciences University of Delaware
Kendall & KendallCopyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall 9 Kendall & Kendall Systems Analysis and Design, 9e Process Specifications.
Reducing Symmetry in Matrix Models Alan Frisch, Ian Miguel, Toby Walsh (York) Pierre Flener, Brahim Hnich, Zeynep Kiziltan, Justin Pearson (Uppsala)
Modeling the Covering Test Problem Brahim Hnich, Steven Prestwich, and Evgeny Selensky Cork Constraint Computation Center UCC Supported by SFI.
Alan M. Frisch Artificial Intelligence Group Department of Computer Science University of York Co-authors Ian Miguel, Toby Walsh, Pierre Flener, Brahim.
CGRASS A System for Transforming Constraint Satisfaction Problems Alan Frisch, Ian Miguel (York) Toby Walsh (Cork)
MOHAMMAD IMRAN DEPARTMENT OF APPLIED SCIENCES JAHANGIRABAD EDUCATIONAL GROUP OF INSTITUTES.
CGRASS A System for Transforming Constraint Satisfaction Problems Alan Frisch, Ian Miguel AI Group University of York Toby Walsh 4C.
Constraint Systems Laboratory 11/22/2005Zheng – Comprehensive1 Survey of Techniques for Detecting and Exploiting Symmetry in Constraint Satisfaction Problems.
Matrix Modelling: Déjà Vu Pierre Flener (Uppsala) Alan M. Frisch (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Ian Miguel, and Toby Walsh (York)
Backtracking.
Global Constraints for Lexicographic Orderings Alan Frisch, Ian Miguel (University of York) Brahim Hnich, Toby Walsh (4C) Zeynep Kiziltan (Uppsala University)
Modelling a Steel Mill Slab Design Problem Alan Frisch, Ian Miguel, Toby Walsh AI Group University of York.
Kendall & KendallCopyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall 9 Kendall & Kendall Systems Analysis and Design, 9e Process Specifications.
Design Patterns Trends and Case Study John Hurst June 2005.
Tractable Symmetry Breaking Using Restricted Search Trees Colva M. Roney-Dougal, Ian P. Gent, Tom Kelsey, Steve Linton Presented by: Shant Karakashian.
Linear Codes.
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
An efficient distributed protocol for collective decision- making in combinatorial domains CMSS Feb , 2012 Minyi Li Intelligent Agent Technology.
Symmetry Breaking Ordering Constraints Zeynep Kiziltan Department of Information Science Uppsala University, Sweden A progress.
101 User Interface Patterns and its applications Tonya Groover Department of Computer Science.
ANU COMP2110 Software Design in 2004 Lecture 15Slide 1 COMP2110 in 2004 Software Design Lecture 15: Software design patterns (2) 1What are design patterns?
Chapter 7 Transportation, Assignment & Transshipment Problems
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
Modelling for Constraint Programming Barbara Smith CP 2010 Doctoral Programme.
Notes 5IE 3121 Knapsack Model Intuitive idea: what is the most valuable collection of items that can be fit into a backpack?
CP Summer School Modelling for Constraint Programming Barbara Smith 2. Implied Constraints, Optimization, Dominance Rules.
Sports Scheduling Written by Kelly Easton, George Nemhauser, Michael Trick Presented by Matthew Lai.
CP Summer School Modelling for Constraint Programming Barbara Smith 4. Combining Viewpoints, Modelling Advice.
Design Patterns Introduction General and reusable solutions to common problems in software design SoftUni Team Software University
Branch-and-Cut Valid inequality: an inequality satisfied by all feasible solutions Cut: a valid inequality that is not part of the current formulation.
Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) Logic & AR Summer School, 2002.
Design Reuse Earlier we have covered the re-usable Architectural Styles as design patterns for High-Level Design. At mid-level and low-level, design patterns.
CP Summer School Modelling for Constraint Programming Barbara Smith 3. Symmetry, Viewpoints.
Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers.
Eliminating non- binary constraints Toby Walsh Cork Constraint Computation Center.
10.3 Reformulation The Lex-Leader Method Shant Karakashian 1.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
ELEC692 VLSI Signal Processing Architecture Lecture 12 Numerical Strength Reduction.
Copyright © 2011 Pearson Education Process Specifications and Structured Decisions Systems Analysis and Design, 8e Kendall & Kendall Global Edition 9.
Parallel Programming By J. H. Wang May 2, 2017.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Generic SBDD using Computational Group Theory
Presentation transcript:

Constraint Patterns Toby Walsh 4C, UCC & Uppsala

Thanks 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 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

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

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

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

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

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

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

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, …

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

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

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

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

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

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

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

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

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

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

Warehouse location  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]) 0..1 Open Warehouse 0..1 Store Warehouse Supply

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

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

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

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)

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, …

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

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

Matrix models 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?

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

abcdefghi Steel mill slab design 3 possible slab sizes (1, 3 or 4) 2 colours per slab

f gi e cd b h a (size 4)(size 3)(size 1) (size 3)(size 1) 2 Example solution

Matrix model oaoa obob ococ odod oeoe ofof ogog ohoh oioi oaoa obob ococ odod oeoe ofof ogog ohoh oioi s1s1 1 s2s2 1 … RedGreenBlueOrangeBrown s1s1 1 s2s2 1 … sum(j,Order[i,j])=1, sum(i,Order[i,j]*w[i])<Size[j] sum(i,Colour[i,j])<2

Example solution oaoa obob ococ odod oeoe ofof ogog ohoh oioi s1s s2s s3s s4s … RedGreenBlueOrangeBrown s1s s2s s3s s4s … f gi e cd b h a 2

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

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

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!

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?

BA Matrix symmetry Two identical bins

Matrix symmetry 6 items to pack into bins: BA

Matrix symmetry BA One packing

Matrix symmetry BA Another packing

Matrix symmetry How do we eliminate such symmetry? a) b) AB BA

Matrix model A B A B a) b) AB BA

Matrix model A B A B a) b) AB BA If we insist that row A  lex row B, we remove a) from the solution set.

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

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

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

ABC DEF GHI ABC DEF GHI ABC DEF GHI ABC DEF GHI Consistent Inconsistent

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

Matrix symmetry All symmetry can be broken When variables take distinct values Simply push largest value to a particular corner Order 1st row and 1st col 0/1 variables, 1 occurs once in each row/col Double LEX then leaves an unique solution

Matrix symmetry pattern Pattern name: MatrixSymmetry Context A matrix model with partial row and/or column symmetry. Problem Symmetry increases the size of the search space. Forces Eliminating all symmetry can be too expensive. Elimination no symmetry can leave too much search. Solution Consider posting lex ordering constraints on symmetric rows/cols Alternatively post lex ordering in one dimension, and multiset in other Example Balanced incomplete block design (prob028 in CSPLib)

Dealing with matrix symmetry Active research area Breaking Row and Column Symmetries in Matrix Models, CP02 Global Constraints for Lexicographic Orderings, CP02 Multiset Ordering Constraints, IJCAI-03 Constraints for Breaking more Row and Column Symmetries, CP03 Generic SBDD using GAP and ECLIPSE, CP03 Symmetry Breaking for Matrix Models using Stabilizers, CP03 ….

Dual model pattern Often choice for the decision variables? Consider scheduling the World Cup. Are Vars=games, vals=times or Vars=times, vals=games ?

TSP problem = find permutation of cities which makes a tour of minimum length Permutation problems |vars|=|vals| each var has unique val Many examples scheduling timetabling routing assignment problems Permute vars for vals which do we choose?

Dual model pattern Pattern name: DualModel Context An informal problem specification. Problem Choosing between a primal & an alternative dual viewpoint. Forces Certain constraints can be easier to post on primal or dual. Certain constraint can propagate better on primal or dual. Solution Consider combined model with channelling between primal & dual variables. Example Balanced academic curriculum problem (prob030 in CSPLib)

Implied constraints pattern Pattern name: ImpliedConstraints Context A basic constraint model. Problem Search going down obviously futile branches. Forces Overhead of introducing additional constraints. Applicability of the new implied constraints. Solution Introduce implied constraints that prune such branches. Example Golomb ruler problem (prob006 in CSPLib)

Model transformation Can greatly reduce the effort of solving a problem Experts work hard to identify useful transformations, e.g. Adding implied constraints. Breaking symmetry. Removing redundant constraints. Replacing constraints with their logical equivalents.

CGRASS Constraint GeneRation And Symmetry-breaking. Designed to automate the task of finding useful model transformations. Based on, and extends, Bundy’s proof planning. Modelling expertise captured by methods. Methods selectively applied to transform the problem. [Frisch, Miguel, Walsh, 02]

Golomb ruler problem Place n ticks at integer points on a ruler of length m All inter-tick distances unique Astronomy, crystallography Previously, implied constraints added by hand [Smith et al ‘00]

Input to CGRASS x1  x2x1  x2 x1  x3x1  x3 x2  x3x2  x3 x 1 - x 2  x 2 – x 1 x 1 - x 2  x 2 – x 3 x 1 - x 2  x 3 – x 1 x 1 - x 3  x 2 – x 1 x 1 - x 3  x 3 – x 1 x 1 - x 3  x 3 – x 2 x 2 - x 1  x 3 – x 2 x 2 - x 3  x 3 – x 1 x 2 - x 3  x 3 – x 2

Output of CGRASS x 1 < x 2 x 2 < x 3 x1  x3x1  x3 z 0 = x 1 – x 2 z 1 = x 2 – x 3 z 2 = x 3 – x 1 Alldiff(z 0, z 1, z 2 )

Constraint patterns repository 4c.ucc.ie/patterns Catalog of patterns Mailing list Links … How you can help Submit your patterns now!

Conclusions Constraint patterns Useful way to describe modelling expertise MatrixModel, MatrixSymmetry, DualModel, ImpliedConstraints, … How you can help Send me your patterns!