The AllDifferent Constraint: Efficiency Measures Ian P. Gent, Ian Miguel, Peter Nightingale.

Slides:



Advertisements
Similar presentations
Non-binary Constraints Toby Walsh
Advertisements

Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
University of Toronto Mechanical & Industrial Engineering An Introduction to Constraint Programming J. Christopher Beck Dept. of Mechanical & Industrial.
Local Search Jim Little UBC CS 322 – CSP October 3, 2014 Textbook §4.8
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.
Bipartite Matching, Extremal Problems, Matrix Tree Theorem.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Review Binary Search Trees Operations on Binary Search Tree
Non-binary constraints: modelling Toby Walsh Cork Constraint Computation Center.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
Great Theoretical Ideas in Computer Science for Some.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
CPSC 322, Lecture 14Slide 1 Local Search Computer Science cpsc322, Lecture 14 (Textbook Chpt 4.8) February, 3, 2010.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Alan M. Frisch Artificial Intelligence Group Department of Computer Science University of York Extending the Reach of Constraint Technology through Reformulation.
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CPSC 322, Lecture 12Slide 1 CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12 (Textbook Chpt ) January, 29, 2010.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
CSE 830: Design and Theory of Algorithms
1 Data Structures and Algorithms Graphs I: Representation and Search Gal A. Kaminka Computer Science Department.
Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)
1 Bipartite Matching Lecture 3: Jan Bipartite Matching A graph is bipartite if its vertex set can be partitioned into two subsets A and B so that.
Backtracking.
Global Constraints for Lexicographic Orderings Alan Frisch, Ian Miguel (University of York) Brahim Hnich, Toby Walsh (4C) Zeynep Kiziltan (Uppsala University)
CS 290H Lecture 17 Dulmage-Mendelsohn Theory
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Busby, Dodge, Fleming, and Negrusa. Backtracking Algorithm Is used to solve problems for which a sequence of objects is to be selected from a set such.
Physical Mapping of DNA Shanna Terry March 2, 2004.
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.
On Algorithms for Decomposable Constraints Kostas Stergiou Ian Gent, Patrick Prosser, Toby Walsh A.P.E.S. Research Group.
CP Summer School Modelling for Constraint Programming Barbara Smith 2. Implied Constraints, Optimization, Dominance Rules.
Techniques for Proving NP-Completeness Show that a special case of the problem you are interested in is NP- complete. For example: The problem of finding.
CP Summer School Modelling for Constraint Programming Barbara Smith 4. Combining Viewpoints, Modelling Advice.
Data Structures & Algorithms Graphs
MAX FLOW APPLICATIONS CS302, Spring 2012 David Kauchak.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Billy Timlen Mentor: Imran Saleemi.  Goal: Have an optimal matching  Given: List of key-points in each image/frame, Matrix of weights between nodes.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness and course wrap up.
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.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
Eliminating non- binary constraints Toby Walsh Cork Constraint Computation Center.
Search in State Spaces Problem solving as search Search consists of –state space –operators –start state –goal states A Search Tree is an efficient way.
10.3 Reformulation The Lex-Leader Method Shant Karakashian 1.
Graph Representations And Traversals. Graphs Graph : – Set of Vertices (Nodes) – Set of Edges connecting vertices (u, v) : edge connecting Origin: u Destination:
Maximum Flow - Anil Kishore Graph Theory Basics. Prerequisites What is a Graph Directed, Weighted graphs How to traverse a graph using – Depth First Search.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
School of Computing Clemson University Fall, 2012
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Algorithms and Networks
Lectures on Network Flows
Computer Science cpsc322, Lecture 14
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Instructor: Shengyu Zhang
Edmonds-Karp Algorithm
Constraints and Search
Algorithms (2IL15) – Lecture 7
Text Book: Introduction to algorithms By C L R S
Presentation transcript:

The AllDifferent Constraint: Efficiency Measures Ian P. Gent, Ian Miguel, Peter Nightingale

2 AllDifferent A vector of variables must take distinct values A vector of variables must take distinct values Very widely used – very important Very widely used – very important Examples: Examples:  A class of students must have lectures at distinct times  In a sports schedule, the teams playing on a particular week are all distinct  No pair of golfers play together more than once  Sudoku

3 AllDifferent Van Hoeve surveys various strengths of inference Van Hoeve surveys various strengths of inference In order of increasing strength: In order of increasing strength:  Weak and fast pairwise decomposition (AC) -- O(r)‏  Bound consistency – find Hall intervals (as described by Toby) and prune bounds – O(r log r)‏  Range consistency – find Hall intervals and prune  Generalised arc consistency (GAC) – O(k 0.5 r d)‏ We focus on GAC algorithm by Régin We focus on GAC algorithm by Régin

4 GAC AllDifferent One expensive pass achieves consistency One expensive pass achieves consistency Traditionally has large incremental, backtracked data structure Traditionally has large incremental, backtracked data structure Traditionally low priority Traditionally low priority Triggered on any domain change Triggered on any domain change  But many changes are processed together No paper that we are aware of comprehensively investigates implementation decisions No paper that we are aware of comprehensively investigates implementation decisions

5 Our approach Investigate optimizations in literature (tried to find everything!)‏ Investigate optimizations in literature (tried to find everything!)‏ Trigger only on relevant values Trigger only on relevant values  It is not necessary to trigger on all domain removals  Identify O(2r+d) trigger values Partition the constraint dynamically Partition the constraint dynamically  Algorithm already identifies independent sub- constraints  Store and re-use this partition  Run expensive algorithm only on sub-constraint

6 Régin's Algorithm Find a maximum matching M from variables to values. Find a maximum matching M from variables to values.  Corresponds to a satisfying tuple of the constraint If |M|<r, the constraint is unsatisfiable If |M|<r, the constraint is unsatisfiable Construct residual graph R (as described later)‏ Construct residual graph R (as described later)‏ Edges not in M, and in no cycle in R, correspond to values to prune Edges not in M, and in no cycle in R, correspond to values to prune

7 Régin's Algorithm Described in terms of flow, Ford-Fulkerson BFS algorithm Described in terms of flow, Ford-Fulkerson BFS algorithm Alternative is bipartite graph matching, Hopcroft-Karp or other algorithm Alternative is bipartite graph matching, Hopcroft-Karp or other algorithm

8 Régin's Algorithm Find maximum flow from s to t Find maximum flow from s to t Ford- Fulkerson algorithm Ford- Fulkerson algorithm

9 Régin's Algorithm Find maximum flow from s to t Find maximum flow from s to t Ford- Fulkerson algorithm Ford- Fulkerson algorithm

10 Régin's Algorithm Find maximum flow from s to t Find maximum flow from s to t Ford- Fulkerson algorithm Ford- Fulkerson algorithm

11 Régin's Algorithm Find maximum flow from s to t Find maximum flow from s to t Ford- Fulkerson algorithm Ford- Fulkerson algorithm

12 Régin's Algorithm Find maximum flow from s to t Find maximum flow from s to t Ford- Fulkerson algorithm Ford- Fulkerson algorithm

13 Régin's Algorithm Find maximum flow from s to t Find maximum flow from s to t Ford- Fulkerson algorithm Ford- Fulkerson algorithm

14 Régin's Algorithm Find maximum flow from s to t Find maximum flow from s to t Ford- Fulkerson algorithm Ford- Fulkerson algorithm

15 Régin's Algorithm Find maximum flow from s to t Find maximum flow from s to t Ford- Fulkerson algorithm Ford- Fulkerson algorithm

16 Régin's Algorithm Completed maximum flow from s to t Completed maximum flow from s to t Covers all variables (constraint is satisfiable)‏ Covers all variables (constraint is satisfiable)‏ One of 24 One of 24

17 Régin's Algorithm Find strongly- connected components Find strongly- connected components

18 Régin's Algorithm Strongly-connected components (SCCs)‏ Strongly-connected components (SCCs)‏  Vertices i and j in same SCC iff: Path from i to j and from j to i in digraph Path from i to j and from j to i in digraph  Found by Tarjan's algorithm DFS DFS  SCC='Maximal set of cycles'

19 Régin's Algorithm Find strongly- connected components Find strongly- connected components

20 Régin's Algorithm Cycle within SCC Cycle within SCC Apply cycle to find different maximum flow Apply cycle to find different maximum flow No cycles between SCCs No cycles between SCCs

21 Régin's Algorithm Cycle within SCC Cycle within SCC Apply cycle to find different maximum flow Apply cycle to find different maximum flow No cycles between SCCs No cycles between SCCs

22 Régin's Algorithm No cycles between SCCs No cycles between SCCs No maximum flows involving x3=2 or x4=2 No maximum flows involving x3=2 or x4=2

23 Régin's Algorithm Remove edges which are: Remove edges which are:  Between SCCs  Not in flow Corresponds to theorem by Berge, 1973 Corresponds to theorem by Berge, 1973

24 Implementation Key assumption: don't maintain the graph, discover it as you traverse Key assumption: don't maintain the graph, discover it as you traverse  Domain queries cheap in Minion  Alternative: maintain and BT adjacency lists, size O(rd)‏  We claim this is better without experiment  If Patrick reads the paper, I'm in trouble!  If the assumption is not true, our experiments are somewhat less reliable, but the big results should still hold

25 Optimizations in Literature Incremental matching (Régin)‏ Incremental matching (Régin)‏ Priority Queue Priority Queue  Execute at low priority and with no duplicate events Staged propagation (Schulte & Stuckey)‏ Staged propagation (Schulte & Stuckey)‏  Do simple propagation at high priority, GAC at low priority Domain counting (Quimper & Walsh)‏ Domain counting (Quimper & Walsh)‏ Fixpoint reasoning (Schulte & Stuckey)‏ Fixpoint reasoning (Schulte & Stuckey)‏  Solves the 'Double Call Problem' Advisors (Lagerkvist & Schulte)‏ Advisors (Lagerkvist & Schulte)‏

26 Priority Queue

27 Incremental Matching

28 FF-BFS vs HK FF is also much easier to implement! FF is also much easier to implement!

29 Staged propagation Very simple, deals with assigned vars at high priority Very simple, deals with assigned vars at high priority

30 Triggering Trigger only on relevant values (Dynamic Triggers)‏ Trigger only on relevant values (Dynamic Triggers)‏  It is not necessary to trigger on all domain removals  Identify t≤2r+d trigger values from rd  Doesn't work on our instances!  Ratio not low enough

31 Triggering Domain counting (Lagerkvist & Schulte, variant of Quimper & Walsh)‏ Domain counting (Lagerkvist & Schulte, variant of Quimper & Walsh)‏  Only trigger when domain size less than r  Very cheap but has almost no effect Fixpoint reasoning and advisors Fixpoint reasoning and advisors  No claim in original papers that these are useful for AllDifferent  DT results suggest fixpoint reasoning is useless  We have something like advisors (although more general) – the variable event queue!

32 Partitioning the constraint Partition by SCCs Partition by SCCs  Each SCC corresponds to an independent sub- constraint  Store and re-use this partition (of the variables)‏  Run expensive algorithm only on sub-constraint

33 Partitioning the constraint setElements: splitPoint: Partition this set into {1,3,5},{2,4,6} setElements: splitPoint: Backtrack setElements: splitPoint: Representation of {1,2,3,4,5,6}setElementIndex: splitPoint[3]=true indicates that adjacent elements 5 and 2 are in different subsets in the partition. Small incremental data structure which backtracks efficiently Small incremental data structure which backtracks efficiently

34 Partitioning the constraint

35 Partitioning the constraint Worth considering for other large constraints Worth considering for other large constraints  GAC GCC partitions in the same way  Graph connectivity partitions when you find a 'bridge'  Sequence constraint?  Regular/Slide partition when variables are assigned in middle

36 Pairwise AllDifferent Trigger only on assignment of a variable Trigger only on assignment of a variable Remove assigned value from all other variables Remove assigned value from all other variables Extremely cheap Extremely cheap Equivalent to AC on pairwise not-equal constraints Equivalent to AC on pairwise not-equal constraints This is no straw man! This is no straw man!

37 Comparing to Pairwise 2.3 4

38 Comparing to Pairwise GAC AllDifferent never slows down search by more than 2.34 times GAC AllDifferent never slows down search by more than 2.34 times Can be 100,000 times faster Can be 100,000 times faster Most AllDifferent constraints here are tight Most AllDifferent constraints here are tight

39 Modelling with AllDifferent Golomb Ruler Golomb Ruler  Triangular table representing all pairs  One AllDifferent constraint  Optimization tightens AllDiff  Implied constraints Ruler: 0 A B C D... (monotonic)‏ Diffs: A B C D... B-A C-A D-A... C-B D-B... D-C AllDifferent

40 Modelling with AllDifferent Langford's problem with 2 instances of each number Langford's problem with 2 instances of each number  Model due to Rendl  Permutation  Represent the indices rather than the actual Langford sequence For Langford sequence of length n with n/2 numbers. Pos[1..n] -- AllDifferent Pos[1]+2=Pos[11] // first instance of number 1 is distance // 1 from the second instance of 1...

41 Modelling with AllDifferent Quasigroup and QWH Quasigroup and QWH  Similar to Sudoku (without the sub squares)‏  n x n matrix of variables with domain 1..n  AllDifferent on each row and each column  QWH has some values filled in already Well known to show off GAC AllDifferent Well known to show off GAC AllDifferent  Quasigroup has various properties (e.g. associativity, idempotence)‏ Colton & Miguel's model and implied constraints Colton & Miguel's model and implied constraints

42 Modelling with AllDifferent N Queens problem N Queens problem  Model 1 Three vectors representing queen position in row, the number of the leading diagonal, and the number of the secondary diagonal Three vectors representing queen position in row, the number of the leading diagonal, and the number of the secondary diagonal These vectors are all different These vectors are all different  Model 2 One vector representing queen position in row (all different)‏ One vector representing queen position in row (all different)‏ Constraints to forbid diagonals Constraints to forbid diagonals Tailor creates 30 auxiliary variables for n=16 Tailor creates 30 auxiliary variables for n=16

43 Modelling with AllDifferent Sports scheduling Sports scheduling  Two viewpoints For each week, a vector of the teams (all different)‏ For each week, a vector of the teams (all different)‏ Vector of games (all different)‏ Vector of games (all different)‏ Channelling constraints between the two (table)‏ Channelling constraints between the two (table)‏ Symmetry breaking constraints (< for each game, lex on weeks, lex on stadiums)‏ Symmetry breaking constraints (< for each game, lex on weeks, lex on stadiums)‏ Stadium constraints (each team plays no more than twice in one stadium)‏ Stadium constraints (each team plays no more than twice in one stadium)‏ Week 1: Stadium 1Stadium 2

44 Modelling with AllDifferent Social Golfers Social Golfers  Very similar to sports scheduling  Two viewpoints For each week, a vector of the golfers (all different)‏ For each week, a vector of the golfers (all different)‏ Vector of pairs who played together (all different but not necessarily a permutation)‏ Vector of pairs who played together (all different but not necessarily a permutation)‏ Channelling constraints between the two (table)‏ Channelling constraints between the two (table)‏ Symmetry breaking constraints (< within the groups, lex on weeks, lex between groups)‏ Symmetry breaking constraints (< within the groups, lex on weeks, lex between groups)‏ 1245 Week 1:

45 Modelling with AllDifferent As you can see, AllDifferent is widely used! 7 example problems. As you can see, AllDifferent is widely used! 7 example problems. The AllDifferent is tight in all examples The AllDifferent is tight in all examples  In a lot of cases it is worth doing GAC, but not all  I think it does depend on tightness, but also on other constraints surrounding the AllDifferent  I refuse to offer any advice!

46 Conclusions A bag of useful tricks from the literature A bag of useful tricks from the literature One new trick which worked: partitioning the constraint One new trick which worked: partitioning the constraint  Perhaps this is general! One new trick which didn't: dynamic triggers from SCC algorithm One new trick which didn't: dynamic triggers from SCC algorithm The only modelling advice is to try a couple of different propagators! The only modelling advice is to try a couple of different propagators!

47 Thank You Any Questions? Any Questions?