Global Constraints Toby Walsh NICTA and University of New South Wales www.cse.unsw.edu.au/~tw.

Slides:



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

Non-binary Constraints Toby Walsh
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh NICTA and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh NICTA and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Constraint Satisfaction Problems
Constraint Satisfaction Problems Russell and Norvig: Parts of Chapter 5 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2004/home.htm Prof: Dekang.
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
ICS-271:Notes 5: 1 Lecture 5: Constraint Satisfaction Problems ICS 271 Fall 2008.
G53CLP Constraint Logic Programming Modeling CSPs – Case Study I Dr Rong Qu.
Reducing Symmetry in Matrix Models Alan Frisch, Ian Miguel, Toby Walsh (York) Pierre Flener, Brahim Hnich, Zeynep Kiziltan, Justin Pearson (Uppsala)
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.
Leeds: 6 June 02Constraint Technology for the Masses Alan M. Frisch Artificial Intelligence Group Department of Computer Science University of York Collaborators:
Non-binary constraints Toby Walsh Dept of CS University of York England.
Search with Constraints COMP8620, S Advanced Topics in A.I. Jason Li The Australian National University.
Constraint Programming: modelling Toby Walsh NICTA and UNSW.
Totally Unimodular Matrices Lecture 11: Feb 23 Simplex Algorithm Elliposid Algorithm.
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.
Constraint Satisfaction Problems
Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)
Jean-Charles REGIN Michel RUEHER ILOG Sophia Antipolis Université de Nice – Sophia Antipolis A global constraint combining.
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)
26 April 2013Lecture 5: Constraint Propagation and Consistency Enforcement1 Constraint Propagation and Consistency Enforcement Jorge Cruz DI/FCT/UNL April.
Chapter 5 Outline Formal definition of CSP CSP Examples
Global Constraints for Lexicographic Orderings Alan Frisch, Ian Miguel (University of York) Brahim Hnich, Toby Walsh (4C) Zeynep Kiziltan (Uppsala University)
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding ILPs with Branch & Bound ILP References: ‘Integer Programming’
Decision Procedures An Algorithmic Point of View
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
Symmetry Breaking Ordering Constraints Zeynep Kiziltan Department of Information Science Uppsala University, Sweden A progress.
Design Techniques for Approximation Algorithms and Approximation Classes.
Lecture 2: General Problem-Solving Methods. Greedy Method Divide-and-Conquer Backtracking Dynamic Programming Graph Traversal Linear Programming Reduction.
Modelling for Constraint Programming Barbara Smith CP 2010 Doctoral Programme.
CP Summer School Modelling for Constraint Programming Barbara Smith 2. Implied Constraints, Optimization, Dominance Rules.
The AllDifferent Constraint: Efficiency Measures Ian P. Gent, Ian Miguel, Peter Nightingale.
Chapter 5: Constraint Satisfaction ICS 171 Fall 2006.
CP Summer School Modelling for Constraint Programming Barbara Smith 4. Combining Viewpoints, Modelling Advice.
CSC 423 ARTIFICIAL INTELLIGENCE Constraint Satisfaction Problems.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) Logic & AR Summer School, 2002.
Proximity Inversion Functions on the Non-Negative Integers Presented By Brendan Lucier June 5, 2005 CMS Summer 2005 Meeting Automatic Sequences and Related.
CP Summer School Modelling for Constraint Programming Barbara Smith 3. Symmetry, Viewpoints.
Eliminating non- binary constraints Toby Walsh Cork Constraint Computation Center.
10.3 Reformulation The Lex-Leader Method Shant Karakashian 1.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
Lap Chi Lau we will only use slides 4 to 19
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Topics in Algorithms Lap Chi Lau.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraints and Search
Graphing systems of linear equations and inequalities
Constraint Satisfaction Problems
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Applied Combinatorics, 4th Ed. Alan Tucker
Constraints and Search
Advanced consistency methods Chapter 8
Directional consistency Chapter 4
Presentation transcript:

Global Constraints Toby Walsh NICTA and University of New South Wales

Quick advert ZUNSW is in Sydney ZRegularly voted in top 10 cities in World ZUNSW is one of top universities in Australia ZIn top 100 universities in world ZTalk to me about our PhD programme! ZAlso happy to have PhDs/PostDocs visit for weeks/months/years …

Quick advert ZUNSW is in Sydney ZRegularly voted in top 10 cities in World ZUNSW is one of top universities in Australia ZIn top 100 universities in world ZTalk to me about our PhD programme! ZAlso happy to have PhDs/PostDocs visit for weeks/months/years … ZAttend CP/KR/ICAPS in Sept

Constraint programming Z“Constraint programming represents one of the closest approaches computer science has yet made to the Holy Grail of programming: the user states the problem, the computer solves it”. ZGene Freuder, Constraints, April 1997

Suduko Puzzle = [X11,X12,X13, …X19, X21,X22, ………X29,.. X91,X92, ……….X99] Puzzle :: 1..9 alldifferent([X11,..X19]) alldifferent([X21,..X29]).. alldifferent([X11,..X91]).. alldifferent([X11,..X33])..

Comparison with OR ZCP Zrich modelling language Zmany different global constraints Zfast local inference on these global constraints Zgood for finding feasible and tightly constrained solutions Z(I)LP Zeverything has to be a linear inequality Zlimited range of solution methods (simplex,...) Zgood at proving optimality

Global constraints ZAny non-binary constraint ZAllDifferent ZNvalues ZElement ZLex ordering ZStretch constraint ZSequence constraint Z... ZEach comes with an efficient propagator...

All Different

Golomb rulers ZMark ticks on a rule ZDistance between any two ticks (not just neighbouring) is distinct ZSpecial type of graceful graph ZApplications ZRadio-astronomy, crystallorgraphy,... ZProb006 in CSPLib

Golomb rulers ZSimple solution ZExponentially long ruler ZTicks at 0, 1, 3, 7, 15, 31,... ZGoal is to find minimal length ruler ZSequence of optimization problems ZIs there a ruler of length m? ZIs there a ruler of length m-1? Z...

Optimal Golomb rulers ZKnown for up to 23 ticks ZDistributed internet project to find larger Z0,1 Z0,1,3 Z0,1,4,6 Z0,1,4,9,11 Z0,1,4,10,12,17 ZSolutions grow as approximately O(n^2)

Golomb rulers as CSP ZVariable Xi for each tick ZValue is position ZAuxiliary variable Dij for each inter-tick distance ZDij=|Xi-Xj| ZTwo (global) constraints ZX1<X2<..Xn ZAllDifferent(D11,D12,D13,...)

Golomb ruler as CSP ZNot yet achieved “dream” of declarative programming ZNeed to break symmetry of inverting ruler ZD12< Dn-1n ZAdd implied constraints ZD12<D13... ZPure declarative specifications not quite enough!

AllDifferent ZAllDifferent([X1,..Xn]) iff Xi=/=Xj for i<j ZUseful in wide range of applications ZTimetabling (exams with common student must occur at different times) ZProduction (each product must be produced at a different time) Z... ZCan propagate just using binary inequalities ZBut this decomposition hurts propagation

AllDifferent ZAllDifferent([X1,..Xn]) iff Xi=/=Xj for i<j ZCan propagate just using binary inequalities ZBut this decomposition hurts propagation ZX1 in {1,2}, X2 in {1,2}, X3 in {1,2,3} ZX3 cannot be 1 or 2 ZHow can we automate such reasoning? ZHow can we do this efficiently (less than O(n^2) time)

AllDifferent ZOne of the oldest global constraints ZIn ALICE language [Lauriere 78] ZFound in every constraint solver today ZGAC algorithm based on matching theory due to Regin [AAAI 94], runs in O(dn^3/2) ZBC algorithm using combinatorics due to Puget [AAAI98], runs in O(nlogn)

BC on AllDifferent ZApplication of Hall's Theorem ZSometimes called the “marriage” theorem ZGiven k sets ZThen there is an unique and distinct element in each set iff any union of j of the sets has at least j elements for 0<j<=k ZE.g. S1={1,2}, S2={1,2} but not S1={1,2},S2={1,2} and S3={1,2}

Hall's theorem ZYou wish to marry n men and women ZEach woman declares who they are willing to marry (some set of men) ZEach man will be “happy” with whoever is willing to marry them ZGiven any subset of j women, the number of men they are willing to marry must be j or more (thus this condition is necessary) ZWhat is surprising is that it is also sufficient!

BC on AllDifferent ZHall Interval ZInterval of values in which as many variables as domain values ZE.g. X1 in {1,2,3}, X2 in {1,2}, X3 in {1,2,3} Z3 variables in the interval [1..3] ZAllDifferent([X1,..Xn]) is BC iff ZEach interval, the number of vars it covers is less than or equal to the width of the interval ZNo variable outside a Hall Interval has a value within it

BC on AllDifferent ZConsider X1 in {1,2}, X2 in {1,2}, X3 in {1,2,3}

BC on AllDifferent ZConsider X1 in {1,2}, X2 in {1,2}, X3 in {1,2,3} ZThen [1..2] is a Hall Interval covered by X1 and X2 ZX3 has values inside this Hall Interval ZWe can prune these and make AllDifferent BC

BC on AllDifferent ZNaïve algorithm considers O(n^2) intervals ZPuget orders intervals ZOrdering has O(nlogn) cost ZThen can go through them in order

Beyond AllDifferent ZNValues([X1,...,Xn],M) iff |{j | Xi=j}|=M ZAllDifferent is special case when M=n ZUseful when values represent a resource ZMinimize the number of resources used

Beyond AllDifferent ZGlobal cardinality constraint ZGCC([X1,..Xn],[a1,..am],[b1,...bm]) iff aj <= |{i | Xi=j }| <= bj for all j ZIn other words, j occurs between aj and bj times ZAgain useful when values represent a resource ZYou have at least one night shift but no more than four each week

Conclusions ZAllDifferent is one of the oldest (and most useful) global constraints ZEfficient propagators exist for achieving GAC and BC ZWhen to choose BC over GAC? ZHeuristic choice: BC often best when many more values than variables, GAC when we are close to a permutation (number of vars=number of values)

Lex ordering ZWidely useful ZEspecially for symmetry breaking ZBreaking row and column symmetry in matrix models ZAvailable in most (all?) solvers ZGood example of pointer based global constraint ZPointers save re-doing work ZGood incremental behaviour ZO(n) in general, but amortised O(n) cost down a branch

Motivation ZMany problems can be modelled by matrices of decision variables.

Motivation ZMany problems can be modelled by matrices of decision variables. ZE.g. Combinatorial Problems ZBalanced Incomplete Block Design. ZX[i,j]=0 or Parameters = (7,7,3,3,1)

Motivation ZMany problems can be modelled by matrices of decision variables ZFrequently these matrices exhibit row and/or column symmetry

Motivation ZMany problems can be modelled by matrices of decision variables ZFrequently these matrices exhibit row and/or column symmetry ZWe can permute the rows/columns in any (non)solution to obtain another (non)solution

Motivation ZWhen rows and columns can be permuted ZAn n by m matrix model with row and column symmetry has Zn! m! symmetries Zgrows super-exponentially ZToo many symmetric search states ZIt can be very expensive to visit all the symmetric branches of a search tree

Motivation ZBreaking symmetry is very important! ZBreaking all row and column symmetries is difficult ZNo one has an effective way of dealing with all row and column symmetries. ZSymmetry breaking methods have to deal with very large number of symmetries. ZThe effort required could easily be exponential.

Symmetry in CP ZAdd symmetry breaking constraints ZLeave at least one solution ZEliminate some/all symmetric solutions ZModify search algorithm ZIgnore symmetric parts of the search space ZAdapt branching heuristic ZTo explore branches which are most likely not to be symmetric

Example ZConsider 2 identical bins: BA

Example ZConsider 2 identical bins: We must pack 6 items: BA

Example ZHere is one solution: BA

Example ZHere is another: BA

Example ZIs there any fundamental difference? a) b) AB BA

Example ZConsider a matrix model: a) b) AB BA A B A B

Example ZConsider a matrix model: If we insist that row A  lex row B, we remove a) from the solution set. b) BA A B A B

Example ZNotice that items 3 and 4 are identical. b) BA c) A B A B

Example ZNotice that items 3 and 4 are identical. b) BA If we insist that col 3  lex col 4, we remove c) from the solution set A B A B

Lexicographic Ordering ZUsed to order dictionaries [A,B,C] ≤ lex [D,E,F] ZA<D or Z(A=D and B<E ) or Z(A=D and B=E and C<F) or Z(A=D and B=E and C=F)

ZLexicographic ordering is total ZForcing the rows to be lexicographically ordered breaks all row symmetry Breaking Row (Column) Symmetry ABC DEF GHI [A B C]  lex [D E F]  lex [G H I] [G H I] lexicographic ordering anti-lexicographic ordering

Breaking Row and Column Symmetries ZBreaking both row and column symmetries is difficult ZRows and columns intersect ZAfter constraining the rows to be lexicographically ordered Zwe distinguish the columns Zthe columns are not symmetric anymore!

Good News ZEach symmetry class of assignments has at least one element where both the rows and the columns are lexicographically ordered ZBut there may be no element with rows lex ordered and columns anti-lex ordered ZTo break row and column symmetries, we can insist that the rows and columns are both lexicographically ordered (double-lex) ZExtends to higher dimensions

Bad News  ZA symmetry class of assignments may have more than one element where both the rows and the columns are lexicographically ordered ZDouble-lex does not break all row and column symmetries swap the columns swap row 1 and row 3

GACLex ZA new family of global constraints.

GACLex ZA new family of global constraints. Non-binary constraint. Specialised propagator.

GACLex ZA new family of global constraints ZLinear time complexity

GACLex ZA new family of global constraints ZLinear time complexity ZEnsures that a pair of vectors of variables are lexicographically ordered  lex

How GACLex Works ZConsider the following example x{2}{1,3,4}{2,3,4}{1}{3,4,5} y{0,1,2}{1}{1,2,3}{0}{0,1,2} We want to enforce GAC on: x  lex y.

A Tale of Two Pointers ZWe use two pointers, alpha and beta, to avoid repeatedly traversing the vectors

A Tale of Two Pointers x{2}{1,3,4}{2,3,4}{1}{3,4,5} y{0,1,2}{1}{1,2,3}{0}{0,1,2} Most significant index Alpha: all variables at more significant indices are ground and equal

A Tale of Two Pointers beta: most significant index from which the two vectors’ tails necessarily violate the constraint. x{2}{1,3,4}{2,3,4}{1}{3,4,5} y{0,1,2}{1}{1,2,3}{0}{0,1,2}

Pointer initialization Zalpha ZScan through vector from start ZAt most O(n) time Zbeta ZScan through vector from end ZAt most O(n) time

Failure Inconsistent if beta < alpha. alpha: index such that all variables at more significant indices are ground and equal. beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

How GACLex Works We maintain alpha and beta as assignments made. alpha: index such that all variables at more significant indices are ground and equal. beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

How GACLex Wroks We maintain alpha and beta as assignments made. When beta = alpha + 1 we enforce bounds consistency on: x alpha < y alpha alpha: index such that all variables at more significant indices are ground and equal. beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

How GACLex Works We maintain alpha and beta as assignments made. When beta = alpha + 1 we enforce bounds consistency on: x alpha < y alpha When beta > alpha + 1 we enforce bounds consistency on: x alpha <= y alpha alpha: index such that all variables at more significant indices are ground and equal. beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

Complexity ZInitialisation: O(n) ZPropagation: We enforce bounds consistency between at most n pairs of variables: x alpha < y alpha or x alpha  y alpha. Cost: b. Overall cost: O(nb). Complexity can be amortized down branch of search tree alpha and beta move at most O(n) steps

Conclusions ZGlobal constraints ZOne of the special features of constraint programming ZInteresting meeting point for algorithms, combinatorics, computational complexity, formal languages, …