Modelling for Constraint Programming Barbara Smith CP 2010 Doctoral Programme.

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) Logic & AR Summer School, 2002.
Case study 3: orthogonal Latin squares Modelled by Barbara Smith.
Solve Your Problem Faster - by changing the model
Non-Binary Constraint Satisfaction Toby Walsh Cork Constraint Computation Center.
ISN Workshop September 2003 Constraint Programming in Practice: Scheduling a Rehearsal Barbara Smith.
Constraint Networks (cont.) Emma Rollón Postdoctoral researcher at UCI April 1st, 2009.
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
This lecture topic (two lectures) Chapter 6.1 – 6.4, except 6.3.3
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
Exploiting Symmetry in Planning Maria Fox Durham Planning Group University of Durham, UK.
1 Chapter 8: Modelling with Finite Domain Constraints Where we examine how modelling and controlling search interact with finite domain constraints.
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
Optimal Rectangle Packing: A Meta-CSP Approach Chris Reeson Advanced Constraint Processing Fall 2009 By Michael D. Moffitt and Martha E. Pollack, AAAI.
Review: Constraint Satisfaction Problems How is a CSP defined? How do we solve CSPs?
EE 553 Integer Programming
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Maths of Constraint Satisfaction, Oxford, March 2006 Constraint Programming Models for Graceful Graphs Barbara Smith.
Symmetry as a Prelude to Implied Constraints Alan Frisch, Ian Miguel, Toby Walsh University of York.
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Ryan Kinworthy 2/26/20031 Chapter 7- Local Search part 1 Ryan Kinworthy CSCE Advanced Constraint Processing.
Computational Methods for Management and Economics Carla Gomes
Constraint Satisfaction Problems
Constraint Systems Laboratory March 26, 2007Reeson–Undergraduate Thesis1 Using Constraint Processing to Model, Solve, and Support Interactive Solving of.
A game of logic where the player must assign the numbers 1..9 to cells on a 9x9 grid. The placement of the numbers must be such that every number must.
Modeling the Covering Test Problem Brahim Hnich, Steven Prestwich, and Evgeny Selensky Cork Constraint Computation Center UCC Supported by SFI.
CGRASS A System for Transforming Constraint Satisfaction Problems Alan Frisch, Ian Miguel (York) Toby Walsh (Cork)
Chapter 5 Outline Formal definition of CSP CSP Examples
Distributed Scheduling. What is Distributed Scheduling? Scheduling: –A resource allocation problem –Often very complex set of constraints –Tied directly.
Constraint Satisfaction Not all problems are solved by a sequential series of steps. How do we solve other types of problems?
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding ILPs with Branch & Bound ILP References: ‘Integer Programming’
Constraint Satisfaction Problems
Decision Procedures An Algorithmic Point of View
Tractable Symmetry Breaking Using Restricted Search Trees Colva M. Roney-Dougal, Ian P. Gent, Tom Kelsey, Steve Linton Presented by: Shant Karakashian.
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
Constraint Satisfaction Problems Chapter 6. Review Agent, Environment, State Agent as search problem Uninformed search strategies Informed (heuristic.
Chapter 5 Section 1 – 3 1.  Constraint Satisfaction Problems (CSP)  Backtracking search for CSPs  Local search for CSPs 2.
CP Summer School Modelling for Constraint Programming Barbara Smith 2. Implied Constraints, Optimization, Dominance Rules.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
1 CS B551: Elements of Artificial Intelligence Instructor: Kris Hauser
Chapter 5: Constraint Satisfaction ICS 171 Fall 2006.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
CP Summer School Modelling for Constraint Programming Barbara Smith 4. Combining Viewpoints, Modelling Advice.
15.053Tuesday, April 9 Branch and Bound Handouts: Lecture Notes.
1 Constraint Symmetry and Solution Symmetry Presented by Beau M. Christ Symmetry in CSP’s Spring 2010 Presented by Beau M. Christ Symmetry in CSP’s Spring.
Chapter 5 Constraint Satisfaction Problems
Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) Logic & AR Summer School, 2002.
Chapter 2) CSP solving-An overview Overview of CSP solving techniques: problem reduction, search and solution synthesis Analyses of the characteristics.
CP Summer School Modelling for Constraint Programming Barbara Smith 3. Symmetry, Viewpoints.
Maximum Density Still Life Symmetries and Lazy Clause Generation Geoffrey Chu, Maria Garcia de la Banda, Chris Mears, Peter J. Stuckey.
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
1. 2 Outline of Ch 4 Best-first search Greedy best-first search A * search Heuristics Functions Local search algorithms Hill-climbing search Simulated.
Fahiem Bacchus, University of Toronto CSC384: Intro to Artificial Intelligence  Backtracking Search (CSPs)  Chapter 5  5.3 talks about local search.
Chapter 5 Team Teaching AI (created by Dewi Liliana) PTIIK Constraint Satisfaction Problems.
1 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart CSC384: Lecture 16  Last time Searching a Graphplan for a plan, and relaxed plan heuristics.
10.3 Reformulation The Lex-Leader Method Shant Karakashian 1.
An Analysis of the n- Queens problem Saleem Karamali.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
Constraint Satisfaction Problems
Discrete Optimization MA2827 Fondements de l’optimisation discrète Constraint programming Material based on the lectures.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Computer Science cpsc322, Lecture 14
Artificial Intelligence
Constraints and Search
Constraint satisfaction problems
Major Design Strategies
Constraint satisfaction problems
Presentation transcript:

Modelling for Constraint Programming Barbara Smith CP 2010 Doctoral Programme

Context I will assume – A well-defined problem that can be represented as a finite domain constraint satisfaction or optimization problem no uncertainty, preferences, etc. – A constraint solver providing: a systematic search algorithm combined with constraint propagation a set of pre-defined constraints I am not going to discuss – Automated modelling – Choice of search strategy – Global constraints – etc. There won’t be enough examples! CP 2010 Doctoral Programme

Solving CSPs Systematic search: given a CSP M = – choose a variable x i that is not yet assigned – create a choice point, i.e. a set of mutually exclusive & exhaustive choices, e.g. x i = a v. x i ≠ a – try the first & backtrack to try the other if this fails Constraint propagation: – add x i = a or x i ≠ a to the set of constraints – re-establish local consistency on each constraint  remove values from the domains of future variables that can no longer be used because of this choice – fail if any future variable has no values left CP 2010 Doctoral Programme

Representing a Problem If a CSP M = represents a problem P, then every solution of M corresponds to a solution of P and every solution of P can be derived from at least one solution of M More than one solution of M can represent the same solution of P, if modelling introduces symmetry The variables and values of M represent entities in P The constraints of M ensure the correspondence between solutions of M and solutions of P The aim is (usually) to find a model M that can be solved as quickly as possible – NB shortest run-time might not mean least search CP 2010 Doctoral Programme

Interactions with Search Strategy Whether M1 is better than M2 can depend on the search algorithm and search strategy I will assume the search algorithm is fixed and choice points are always x i = a v. x i ≠ a But the search strategy is still important – choice of search variables – variable and value ordering heuristics E.g. Stable marriage, Graceful labelling of a graph Is designing the search strategy part of modelling? – I think it is, in practice – but I will not discuss it in this talk CP 2010 Doctoral Programme

Viewpoints A viewpoint is a pair, i.e. a set of variables and their domains Given a viewpoint, the constraints have to restrict the solutions of M to solutions of P – So the constraints are (largely) decided by the viewpoint – Different viewpoints give very different models We can combine viewpoints - more later Good rule of thumb: choose a viewpoint that allows the constraints to be expressed easily and concisely – will propagate well, so problem can be solved efficiently CP 2010 Doctoral Programme

Example: Magic Square Arrange the numbers 1 to 9 in a 3 x 3 square so that each row, column and diagonal has the same sum V1 : a variable for each cell, domain is the numbers that can go in the cell V2 : a variable for each number, domain is the cells where that number can go Constraints on row, column & diagonal sums are easy to express in V1: – x 1 + x 2 + x 3 = x 4 + x 5 + x 6 = x 1 + x 4 + x 7 = … but not in V x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 x9x9 CP 2010 Doctoral Programme

Constraints Given a viewpoint, the role of the constraints is: –To ensure that the solutions of the CSP match the solutions of the problem –To guide the search, i.e. to ensure that as far as possible, partial solutions that will not lead to a solution fail immediately CP 2010 Doctoral Programme

Expressing the Constraints For efficient solving, we need to know: – the constraints provided by the constraint solver – the level of consistency enforced on each – the complexity of the constraint propagation algorithms – Not very declarative! There is often a trade-off between time spent on propagation and time saved on search – which choice is best often depends on the problem – E.g. sometimes it is not worthwhile to enforce GAC on an allDifferent constraint If the constraint is loose, i.e. there are many more values than variables CP 2010 Doctoral Programme

Auxiliary Variables Often, the constraints can be expressed more easily/propagate better if more variables are introduced E.g. in the magic square problem, introduce a variable s representing the sum of the rows & columns – x 1 + x 2 + x 3 = x 4 + x 5 + x 6 becomes x 1 + x 2 + x 3 = s, x 4 + x 5 + x 6 = s – Better still, add s = 15 (in the 3 × 3 case) CP 2010 Doctoral Programme

Auxiliary Variables (II) Example: car sequencing (Dincbas, Simonis and van Hentenryck, ECAI 1988) CP 2010 Doctoral Programme 10 cars to be made on a production line, each requires some options Stations installing options have lower capacity than rest of line e.g. at most 1 car out of 2 for option 1 Find a feasible production sequence classes123456Capacity Option /2 Option /3 Option /3 Option /5 Option /5 No. of cars112222

Car Sequencing - Model Variables : s 1, s 2, …, s 10 Value of s i is the class of car in position i in the sequence Constraints: – Each class occurs the correct number of times – Option capacities are respected - ? Introduce variables o ij : – o ij = 1 iff the car in the i th slot in the sequence requires option j Option 1 capacity is one car in every two: – o i,1 + o i+1,1 ≤ 1 for 1 ≤ i < 10 Relate the auxiliary variables to the s i variables : – λ jk = 1 if car class k requires option j – o ij = λ jsi, 1 ≤ i ≤ 10, 1 ≤ j ≤ 5 CP 2010 Doctoral Programme

One Constraint is Better than Several (maybe) If there are several constraints all with the same scope, rewriting them as a single constraint will lead to more propagation… – if the same level of consistency is maintained on the new constraint … more propagation means shorter run-time – if enforcing consistency on the new constraint can be done efficiently NB conjoining all the constraints in the problem into a single constraint is not usually a good idea! CP 2010 Doctoral Programme

Example: n-queens A variable for each row, x 1, x 2, …, x n Values represent the columns, 1 to n The assignment (x i,c) means that the queen in row i is in column c Constraints for each pair of rows i, j: – x i ≠x i – x i − x i ≠ i − j – x i − x i ≠ j − i CP 2010 Doctoral Programme

Propagating the Constraints A queen in row 5, column 3 conflicts with both remaining values for x 3 But the constraints are consistent – x i ≠x i thinks that (x 3,1) can support (x 5,3) – x i − x i ≠ i − j thinks that (x 3,3) can support (x 5,3) CP 2010 Doctoral Programme × Enforcing AC on the conjunction (x i ≠x i ) ٨ (x i − x i ≠ i − j ) ٨ (x i − x i ≠ j − i ) would remove 3 from the domain of x 5 If you can enforce GAC on the constraint

CP 2010 Doctoral Programme Implied Constraints Implied constraints are logical consequences of the set of existing constraints – So are logically redundant (sometimes called redundant constraints) They do not change the set of solutions Adding implied constraints can reduce the search effort and run-time

CP 2010 Doctoral Programme Example: Car Sequencing Existing constraints only say that the option capacities cannot be exceeded Suppose there are 30 cars and 12 require option 1 (capacity 1/2) At least one car in slots 1 to 8 of the production sequence must require option 1; otherwise 12 of cars 9 to 30 will require option 1, i.e. too many Cars 1 to 10 must include at least two option 1 cars,..., and cars 1 to 28 must include at least 11 option 1 cars These are implied constraints

CP 2010 Doctoral Programme Useful Implied Constraints An implied constraint reduces search if: – at some point during search, a partial assignment will fail because of the implied constraint – without the implied constraint, the search would continue – the partial assignment cannot lead to a solution the implied constraint forbids it, but does not change the set of solutions In car sequencing, partial assignments with option 1 under- used could be explored during search, without the implied constraints

CP 2010 Doctoral Programme Useless Implied Constraints The assignments forbidden by an implied constraint may never actually arise – depends on the search order e.g. in car sequencing, – at least one of cars 1 to 8 must require option 1 – any 8 consecutive cars must have one option 1 car – but if the sequence is built up from slot 1, only the implied constraints on slots 1 to k can cause the search to backtrack If we find a class of implied constraints, maybe only some are useful – adding a lot of constraints that don’t reduce search will increase the run-time

CP 2010 Doctoral Programme Implied Constraints v. Global Constraints Régin and Puget (CP97) developed a global constraint for sequence problems, including the car sequencing problem – “our filtering algorithm subsumes all the implied constraints” used by Dincbas et al. Implied constraints may only be useful because a suitable global constraint does not (yet) exist But many implied constraints are simple and quick to propagate Use a global constraint if there is one available and it is cost-effective – but look for useful implied constraints as well

CP 2010 Doctoral Programme Symmetry in CSPs A symmetry transforms any solution into another – Sometimes symmetry is inherent in the problem (e.g. chessboard symmetry in n-queens) – Sometimes it’s introduced in modelling Symmetry causes wasted search effort: after exploring choices that don’t lead to a solution, symmetrically equivalent choices may be explored

CP 2010 Doctoral Programme Symmetry between Values: Car sequencing cars option option option option option classes option option option option option no. of cars A natural model has individual cars as the values introduces symmetry between cars requiring the same option The model instead has classes of car needs constraints to ensure the right number of cars in each class Using set variables is a similar and common technique to remove symmetry

CP 2010 Doctoral Programme Symmetry Breaking Often, not all the symmetry can be eliminated by remodelling Remaining symmetry should be reduced or eliminated: – dynamic symmetry breaking methods (SBDS, SBDD, etc.) – symmetry-breaking constraints unlike implied constraints, they change the set of solutions can lead to further implied constraints

CP 2010 Doctoral Programme Changing Viewpoint We can improve a CSP model of a problem – express the constraints better – break the symmetry – add implied constraints But sometimes it’s better just to use a different model – i.e. a different viewpoint

CP 2010 Doctoral Programme Different Viewpoints Reformulate in a standard way, e.g. – non-binary to binary translations – dual viewpoint for permutation problems – Boolean to integer or set viewpoints – Reformulations are being developed for automated modelling Or find a new viewpoint by viewing the problem from a different angle – the constraints may express different insights into the problem

CP 2010 Doctoral Programme Permutation Problems A CSP is a permutation problem if: – it has the same number of values as variables – all variables have the same domain – each variable must be assigned a different value Any solution assigns a permutation of the values to the variables Other constraints determine which permutations are solutions There is a dual viewpoint in which the variables and values are swapped

CP 2010 Doctoral Programme Example: n-queens Standard model – a variable for each row, x 1, x 2, …, x n – values represent the columns, 1 to n – x i = j means that the queen in row i is in column j – n variables, n values, allDifferent(x 1, x 2, …, x n ) Dual viewpoint – a variable for each column, d 1, d 2, …, d n ; values represent the rows In this problem, both viewpoints give the same CSP

CP 2010 Doctoral Programme Example: Magic Square First viewpoint: – variables x 1, x 2, …, x 9 – values represent the numbers 1 to 9 – The assignment (x i,j) means that the number in square i is j Dual viewpoint – a variable for each number, d 1, d 2, …, d 9 – values represent the squares Constraints are much easier to express in the first viewpoint (& there are far fewer of them) x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 x9x9

CP 2010 Doctoral Programme Different Perspectives: Example Constraint Modelling Challenge, IJCAI 05 “Minimizing the maximum number of open stacks” There were almost as many models of the problem as participants in the Challenge

CP 2010 Doctoral Programme Which Viewpoint to Choose? Sometimes one viewpoint is clearly better, e.g. if we can’t express the constraints easily in one But different perspectives often allow different expression of the constraints and different implied constraints – can be hard to decide which is better We don’t need to choose one viewpoint – we can use two (or more) at once We need channelling constraints to link the variables

CP 2010 Doctoral Programme Combining Viewpoints: Permutation Problems Dual viewpoints of a permutation problem with variables x 1, x 2, …, x n and d 1, d 2, …, d n Combine them using the channelling constraints (x i = j) ≡ (d j = i ) Also allows both sets of variables to be search variables – e.g. use a dynamic variable order e.g. variable with smallest domain in either viewpoint – combines variable and value ordering: dual variable with smallest domain corresponds to the value occurring in fewest domains (in the other viewpoint)

CP 2010 Doctoral Programme Combining Viewpoints: Integer & Set Variables In a nurse rostering problem, we can allocate shifts to nurses or nurses to shifts First viewpoint: – an integer variable n ij for each nurse i and day j – its value is the shift that nurse i works on day j Second viewpoint: – a set variable S kj for each shift k and day j – its value is the set of nurses that work shift k on day j Channelling constraints: (n ij = k) ≡ (i  S kj ) Constraints on nurse availability are stated in the first viewpoint; constraints on work requirements in the 2 nd (e.g. no. of nurses required for each shift)

CP 2010 Doctoral Programme Search Variables – Permutation Problems We can use both sets of variables as search variables – e.g. use a dynamic variable order e.g. variable with smallest domain in either viewpoint combines variable and value ordering: dual variable with smallest domain corresponds to the value occurring in fewest domains (in the other viewpoint)

Summary Choose a viewpoint that allows the constraints to be expressed easily and concisely Use auxiliary variables if they help to express the constraints Implied constraints can detect infeasible subproblems earlier – Make sure they are useful Look out for symmetry in the CSP – avoid it if possible by changing the model – eliminate it e.g. by adding constraints Consider alternative viewpoints – think of standard reformulations – think about the problem in different ways – consider combining viewpoints CP 2010 Doctoral Programme

Conclusion Aim for a rich model – multiple viewpoints – auxiliary variables – add constraints to improve propagation (implied constraints, global constraints) & symmetry breaking constraints But check that your additions do reduce run-time with your chosen search strategy Understand the problem as well as you can – build that insight into the model – the better you can understand a problem, the better you can solve it THE END