Case study 3: orthogonal Latin squares Modelled by Barbara Smith.
-
Upload
charles-roche -
Category
Documents
-
view
221 -
download
1
Transcript of Case study 3: orthogonal Latin squares Modelled by Barbara Smith.
Case study 3: orthogonal Case study 3: orthogonal Latin squaresLatin squares
Modelled by Barbara SmithModelled by Barbara Smith
Modelling decisionsModelling decisions
Many different ways to model even simple Many different ways to model even simple problemsproblems
Combining models can be effectiveCombining models can be effective Channel between modelsChannel between models
Need additional constraintsNeed additional constraints Symmetry breakingSymmetry breaking Implied (but logically) redundantImplied (but logically) redundant
Orthogonal Latin squaresOrthogonal Latin squares
Find a pair of Latin Find a pair of Latin squaressquares Every cell has a different Every cell has a different
pair of elementspair of elements
Generalized form:Generalized form: Find a set of m Latin Find a set of m Latin
squaressquares Each possible pair is Each possible pair is
orthogonalorthogonal
Orthogonal Latin squaresOrthogonal Latin squares
1 2 3 4 1 2 3 41 2 3 4 1 2 3 42 1 4 3 3 4 1 22 1 4 3 3 4 1 23 4 1 2 4 3 2 13 4 1 2 4 3 2 14 3 2 1 2 1 4 34 3 2 1 2 1 4 3 11 22 33 4411 22 33 44 23 14 41 3223 14 41 32 34 43 12 2134 43 12 21 42 31 24 1342 31 24 13
Two 4 by 4 Latin Two 4 by 4 Latin squaressquares
No pair is repeatedNo pair is repeated
History of (orthogonal) Latin History of (orthogonal) Latin squaressquares
Introduced by Euler in 1783Introduced by Euler in 1783 Also called Graeco-Latin or Euler squaresAlso called Graeco-Latin or Euler squares
No orthogonal Latin square of order 2No orthogonal Latin square of order 2 There are only 2 (non)-isomorphic Latin squares of There are only 2 (non)-isomorphic Latin squares of
order 2 and they are not orthogonalorder 2 and they are not orthogonal
History of (orthogonal) Latin History of (orthogonal) Latin squaressquares
Euler conjectured in 1783 that there are no orthogonal Euler conjectured in 1783 that there are no orthogonal Latin squares of order 4n+2Latin squares of order 4n+2 Constructions exist for 4n and for 2n+1Constructions exist for 4n and for 2n+1 Took till 1900 to show conjecture for n=1Took till 1900 to show conjecture for n=1 Took till 1960 to show false for all n>1Took till 1960 to show false for all n>1
6 by 6 problem also known as the 36 officer problem6 by 6 problem also known as the 36 officer problem“… Can a delegation of six regiments, each of which sends a
colonel, a lieutenant-colonel, a major, a captain, a lieutenant, and a sub-lieutenant be arranged in a regular 6 by 6 array such that no row or column duplicates a rank or a regiment?”
More backgroundMore background
Lam’s problemLam’s problem Existence of finite projective plane of order 10Existence of finite projective plane of order 10 Equivalent to set of 9 mutually orthogonal Latin squares of Equivalent to set of 9 mutually orthogonal Latin squares of
order 10order 10 In 1989, this was shown not to be possible after 2000 hours In 1989, this was shown not to be possible after 2000 hours
on a Cray (and some major maths)on a Cray (and some major maths) Orthogonal Latin squares are used in experimental Orthogonal Latin squares are used in experimental
designdesign To ensure no dependency between independent variablesTo ensure no dependency between independent variables
A simple 0/1 modelA simple 0/1 model
Suitable for integer programmingSuitable for integer programming Xijkl = 1 if pair (i,j) is in row k column l, 0 Xijkl = 1 if pair (i,j) is in row k column l, 0
otherwiseotherwise Avoiding advice never to use more than 3 Avoiding advice never to use more than 3
subscripts!subscripts! ConstraintsConstraints
Each row contains one number in each squareEach row contains one number in each squareSum_jl Xijkl = 1 Sum_il Xijkl = 1Sum_jl Xijkl = 1 Sum_il Xijkl = 1
Each col contains one number in each squareEach col contains one number in each squareSum_jk Xijkl = 1 Sum_ik Xijkl = 1Sum_jk Xijkl = 1 Sum_ik Xijkl = 1
A simple 0/1 modelA simple 0/1 model
Additional constraintsAdditional constraints Every pair of numbers occurs exactly onceEvery pair of numbers occurs exactly once
Sum_kl Xijkl = 1Sum_kl Xijkl = 1 Every cell contains exactly one pair of numbersEvery cell contains exactly one pair of numbers
Sum_ij Xijkl = 1Sum_ij Xijkl = 1
Is there any symmetry?Is there any symmetry?
Symmetry removalSymmetry removal
Important for solving CSPsImportant for solving CSPs Especially for proofs of optimality?Especially for proofs of optimality?
Orthogonal Latin square has lots of symmetryOrthogonal Latin square has lots of symmetry Permute the rowsPermute the rows Permute the colsPermute the cols Permute the numbers 1 to n in each squarePermute the numbers 1 to n in each square
How can we eliminate such symmetry?How can we eliminate such symmetry?
Symmetry removalSymmetry removal
Fix first row Fix first row 11 22 33 …11 22 33 …
Fix first columnFix first column111123233232....
Eliminates all this symmetry?Eliminates all this symmetry?
What about a CSP model?What about a CSP model?
Exploit large finite domains possible in CSPsExploit large finite domains possible in CSPs Reduce number of variablesReduce number of variables O(n^4) -> ?O(n^4) -> ?
Exploit non-binary constraintsExploit non-binary constraints Problem states that squares contain pairs that are Problem states that squares contain pairs that are
all differentall different All-different is a non-binary constraint our solvers All-different is a non-binary constraint our solvers
can reason with efficientlycan reason with efficiently
CSP modelCSP model
2 sets of variables2 sets of variables Skl = i if the 1st element in row k col l is iSkl = i if the 1st element in row k col l is i Tkl = j if the 2nd element in row k col l is jTkl = j if the 2nd element in row k col l is j
How do we specify all pairs are different?How do we specify all pairs are different? All distinct (k,l), (k’,l’)All distinct (k,l), (k’,l’) if Skl = i and Tkl = j then Sk’l’=/ i or Tk’l’ =/ jif Skl = i and Tkl = j then Sk’l’=/ i or Tk’l’ =/ j
O(n^4) loose constraints, little constraint propagation!O(n^4) loose constraints, little constraint propagation!
What can we do?What can we do?
CSP modelCSP model
Introduce auxiliary variablesIntroduce auxiliary variables Fewer constraints, O(n^2)Fewer constraints, O(n^2) Tightens constraint graph => more propagationTightens constraint graph => more propagation Pkl = i*n + j if row k col l contains the pair i,jPkl = i*n + j if row k col l contains the pair i,j
ConstraintsConstraints 2n all-different constraints on Skl, and on Tkl2n all-different constraints on Skl, and on Tkl All-different constraint on PklAll-different constraint on Pkl Channelling constraint to link Pkl to Skl and TklChannelling constraint to link Pkl to Skl and Tkl
CSP model v O/1 modelCSP model v O/1 model
CSP modelCSP model 3n^2 variables3n^2 variables Domains of size n, n and Domains of size n, n and
n^2+nn^2+n O(n^2) constraintsO(n^2) constraints Large and tight non-Large and tight non-
binary constraintsbinary constraints
0/1 model0/1 model n^4 variablesn^4 variables Domains of size 2Domains of size 2 O(n^4) constraintsO(n^4) constraints Loose but linear Loose but linear
constraintsconstraints Use IP solver!Use IP solver!
Solving choices for CSP modelSolving choices for CSP model
Variables to assignVariables to assign Skl and Tkl, or Pkl?Skl and Tkl, or Pkl?
Variable and value orderingVariable and value ordering How to treat all-different constraintHow to treat all-different constraint
GAC using Regin’s algorithm O(n^4)GAC using Regin’s algorithm O(n^4) AC using the binary decompositionAC using the binary decomposition
Good choices for the CSP modelGood choices for the CSP model
Experience and small instances suggest:Experience and small instances suggest: Assign the Skl and Tkl variablesAssign the Skl and Tkl variables Choose variable to assign with Fail First (smallest Choose variable to assign with Fail First (smallest
domain) heuristicdomain) heuristic Break ties by alternating between Skl and TklBreak ties by alternating between Skl and Tkl
Use GAC on all-different constraints for Skl and Use GAC on all-different constraints for Skl and TklTkl
Use AC on binary decomposition of large all-Use AC on binary decomposition of large all-different constraint on Pkldifferent constraint on Pkl
PerformancePerformance
nn 0-1 model0-1 model
Fails t/secFails t/sec
CSP model CSP model ACAC
Fails t/secFails t/sec
CSP model CSP model GACGAC
Fails t/secFails t/sec
44 4 0.114 0.11 2 0.182 0.18 2 0.382 0.38
55 1950 4.051950 4.05 295 1.39295 1.39 190 1.55190 1.55
66 ? ?? ? 640235 657640235 657 442059 773442059 773
7* 7* 20083 59.820083 59.8 91687 51.191687 51.1 57495 66.157495 66.1
Dual CSP modelDual CSP model
4 subscripts in 0/1 model are interchangeable4 subscripts in 0/1 model are interchangeable Suggests a dual modelSuggests a dual model DSij = k if the pair (i,j) occurs in row kDSij = k if the pair (i,j) occurs in row k DTij = l if the pair (i,j) occurs in the row lDTij = l if the pair (i,j) occurs in the row l DPij = k*n + l if the pair (i,j) occurs in row i col jDPij = k*n + l if the pair (i,j) occurs in row i col j
Dual constraints to the primal modelDual constraints to the primal model
Combined modelCombined model
Primal and dual model togetherPrimal and dual model together Channelling constraints to link themChannelling constraints to link them
But new search decisionsBut new search decisions Do we assign both primal and dual variables?Do we assign both primal and dual variables? How do handle dual constraints (AC, GAC …)?How do handle dual constraints (AC, GAC …)? ……
Other dualities Other dualities Any choice of 2 subscripts from 4Any choice of 2 subscripts from 4 Diminishing returnsDiminishing returns
Dual performanceDual performance
NN PrimalPrimal
Fails t/secFails t/sec
Dual Dual all varsall vars
Fails t/secFails t/sec
Dual Dual primal varsprimal vars
Fails t/secFails t/sec
44 2 0.382 0.38 0 0.290 0.29 0 0.0460 0.046
55 190 1.55190 1.55 94 0.3794 0.37 67 0.3467 0.34
66 442059 773442059 773 33868 14633868 146 26936 78.526936 78.5
7*7* 57495 66.157495 66.1 978 3.8978 3.8 1529 5.51529 5.5
ConclusionsConclusions
Many ways to model even simple problemsMany ways to model even simple problems Introduce auxiliary variablesIntroduce auxiliary variables
Reduce number of constraints, improve Reduce number of constraints, improve propagationpropagation
Combining models often beneficialCombining models often beneficial Channelling constraints link modelsChannelling constraints link models
Need to deal with symmetryNeed to deal with symmetry Don’t always use GAC on all-different Don’t always use GAC on all-different
constraintsconstraints
General methodology?General methodology?
Choose a basic modelChoose a basic model Consider auxiliary variablesConsider auxiliary variables
To reduce number of To reduce number of constraints, improve constraints, improve propagationpropagation
Consider combined modelsConsider combined models Channel between viewsChannel between views
Break symmetriesBreak symmetries Add implied constraintsAdd implied constraints
To improve propagationTo improve propagation
Case study 4: template Case study 4: template design design
Again model due to Barbara SmithAgain model due to Barbara Smith
IntroductionIntroduction
Prob002 at Prob002 at www.csplib.orgwww.csplib.org Problem comes from a printing firmProblem comes from a printing firm
Cat food labels that need to be printed using Cat food labels that need to be printed using templatestemplates
Several designs (tuna, chicken, …) go on each Several designs (tuna, chicken, …) go on each templatetemplate
Different demand for each flavourDifferent demand for each flavour Aside: where did cats get the taste for tuna?Aside: where did cats get the taste for tuna?
Template design problemTemplate design problem
For Francesca’s benefitFor Francesca’s benefit
How else can I get a cat How else can I get a cat picture into my talk?picture into my talk?
Basic CSP modelBasic CSP model
Assume number of templates is fixedAssume number of templates is fixed VariablesVariables
Pij = number of slots on template i for design jPij = number of slots on template i for design j Ri = run length for template iRi = run length for template i
ConstraintsConstraints Sum_j Pij = s, number of slots on each templateSum_j Pij = s, number of slots on each template Sum_i Pij * Ri >= dj, total production equals Sum_i Pij * Ri >= dj, total production equals
demanddemand
Basic CSP modelBasic CSP model
Optimization problemOptimization problem Introduce variable to minimizeIntroduce variable to minimize Production = Sum_i RiProduction = Sum_i Ri Solved as sequence of decision problemsSolved as sequence of decision problems
Production < l1, Production < l2 …Production < l1, Production < l2 …
l1 set to minimum number of printings with 1 templatel1 set to minimum number of printings with 1 template
SymmetrySymmetry
Does the model have any symmetry?Does the model have any symmetry?
If so, how can we eliminate it?If so, how can we eliminate it?
SymmetrySymmetry
The templates are indistinguishable and can be The templates are indistinguishable and can be permutedpermuted Swap all designs on one template with all those on Swap all designs on one template with all those on
a second templatea second template Break this symmetry by distinguishing the Break this symmetry by distinguishing the
templatestemplates R1 <= R2 <= R3 …R1 <= R2 <= R3 …
SymmetrySymmetry
Designs j, k with the same demand are Designs j, k with the same demand are indistinguishableindistinguishable
We can break this symmetryWe can break this symmetry [P1j,P2j,P3j,…] <lex [P1k,P2k,P3k,…][P1j,P2j,P3j,…] <lex [P1k,P2k,P3k,…] Efficient GAC algorithm for lex ordering Efficient GAC algorithm for lex ordering
constraintconstraint
Sort of symmetry?Sort of symmetry?
Symmetries can be subtle to spot!Symmetries can be subtle to spot! Consider designs j and j’ with demand for j Consider designs j and j’ with demand for j
less than for j’less than for j’ Suppose we produce more of j than j’Suppose we produce more of j than j’ We could swap j and j’ and still have solutionWe could swap j and j’ and still have solution Prevent this with constraint on productionPrevent this with constraint on production
Sum_i Pij Ri <= Sum_i Pij’ RiSum_i Pij Ri <= Sum_i Pij’ Ri
Implied constraintsImplied constraints
We should always look for implied constraints We should always look for implied constraints we can add to modelwe can add to model Encourage constraint propagationEncourage constraint propagation
Implied constraintsImplied constraints
2 templates2 templates R1+R2 = ProductionR1+R2 = Production R1 <= R2R1 <= R2 Hence Hence
R1 <= Production/2R1 <= Production/2
R2 >= Production/2R2 >= Production/2
Implied constraintsImplied constraints
3 templates3 templates R1 + R2 + R3 = ProductionR1 + R2 + R3 = Production R1 <= R2 <= R3R1 <= R2 <= R3 Hence Hence
R1 <= Production/3R1 <= Production/3
R2 <= Production/2R2 <= Production/2
R3 >= Production/3R3 >= Production/3
……
Solving choicesSolving choices
Variable orderingVariable ordering As with Golomb ruler, assign variables to As with Golomb ruler, assign variables to
construct solution systematicallyconstruct solution systematically Assign all designs on one template before moving Assign all designs on one template before moving
on to a second templateon to a second template Encourages constraint propagation on runlength Encourages constraint propagation on runlength
constraintsconstraints
PerformancePerformance
Basic modelBasic model Difficult to solve 2 or 3 template problemsDifficult to solve 2 or 3 template problems
Full modelFull model Problem solved quicklyProblem solved quickly Can solve much larger problems than feasible with Can solve much larger problems than feasible with
the basic modelthe basic model Optimality can still be tough!Optimality can still be tough!
ConclusionsConclusions
Basic model often obviousBasic model often obvious To refine such a model we need:To refine such a model we need:
Consider dual/combined modelsConsider dual/combined models Symmetries eliminatedSymmetries eliminated Implied constraintsImplied constraints Variable ordering heuristicsVariable ordering heuristics
Hopefully you can start to see patterns in what Hopefully you can start to see patterns in what we do!we do!