Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "The AllDifferent Constraint: Efficiency Measures Ian P. Gent, Ian Miguel, Peter Nightingale."— Presentation transcript:

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

2 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 17 Régin's Algorithm Find strongly- connected components Find strongly- connected components

18 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 19 Régin's Algorithm Find strongly- connected components Find strongly- connected components

20 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 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 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 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 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 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 26 Priority Queue

27 27 Incremental Matching

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

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

30 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 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 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 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 34 Partitioning the constraint

35 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 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 37 Comparing to Pairwise 2.3 4

38 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 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 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 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 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 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)‏ 1324... Week 1: Stadium 1Stadium 2

44 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: 3679...

45 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 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 47 Thank You Any Questions? Any Questions?


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

Similar presentations


Ads by Google