Case study 7: Langfords problem Model due to Barbara Smith.

79
Case study 7: Case study 7: Langford’s problem Langford’s problem Model due to Barbara Model due to Barbara Smith Smith

Transcript of Case study 7: Langfords problem Model due to Barbara Smith.

Page 1: Case study 7: Langfords problem Model due to Barbara Smith.

Case study 7: Case study 7: Langford’s problemLangford’s problem

Model due to Barbara SmithModel due to Barbara Smith

Page 2: Case study 7: Langfords problem Model due to Barbara Smith.

OutlineOutline

IntroductionIntroduction Langford’s problemLangford’s problem

Modelling it as a CSPModelling it as a CSP Basic modelBasic model Refined modelRefined model

Experimental ResultsExperimental Results ConclusionsConclusions

Page 3: Case study 7: Langfords problem Model due to Barbara Smith.

RecipeRecipe

Create a basic modelCreate a basic model Decide on the variablesDecide on the variables

Introduce auxiliary variablesIntroduce auxiliary variables For messy/loose constraintsFor messy/loose constraints

Consider dual, combined or Consider dual, combined or 0/1 models0/1 models

Break symmetryBreak symmetry Add implied constraintsAdd implied constraints Customize solverCustomize solver

Variable, value orderingVariable, value ordering

Page 4: Case study 7: Langfords problem Model due to Barbara Smith.

Langford’s problemLangford’s problem

Prob024 @ Prob024 @ www.csplib.orgwww.csplib.org

Find a sequence of 8 Find a sequence of 8 numbersnumbers Each number [1,4] Each number [1,4]

occurs twiceoccurs twice Two occurrences of i Two occurrences of i

are i numbers apartare i numbers apart

Unique solutionUnique solution 4131243241312432

Page 5: Case study 7: Langfords problem Model due to Barbara Smith.

Langford’s problemLangford’s problem

L(k,n) problemL(k,n) problem To find a sequence of k*n To find a sequence of k*n

numbers [1,n]numbers [1,n] Each of the k successive Each of the k successive

occrrences of i are i apartoccrrences of i are i apart We just saw L(2,4)We just saw L(2,4)

Due to the mathematician Due to the mathematician Dudley LangfordDudley Langford

Watched his son build a Watched his son build a tower which solved L(2,3)tower which solved L(2,3)

Page 6: Case study 7: Langfords problem Model due to Barbara Smith.

Langford’s problemLangford’s problem

L(2,3) and L(2,4) have unique solutionsL(2,3) and L(2,4) have unique solutions L(2,4n) and L(2,4n-1) have solutionsL(2,4n) and L(2,4n-1) have solutions

L(2,4n-2) and L(2,4n-3) do notL(2,4n-2) and L(2,4n-3) do not Computing all solutions of L(2,19) took 2.5 years!Computing all solutions of L(2,19) took 2.5 years!

L(3,n)L(3,n) No solutions: 0<n<8, 10<n<17, 20, ..No solutions: 0<n<8, 10<n<17, 20, .. Solutions: 9,10,17,18,19, ..Solutions: 9,10,17,18,19, ..

A014552Sequence: 0,0,1,1,0,0,26,150,0,0,17792,108144,0,0,39809640,326721800,

0,0,256814891280,2636337861200

Page 7: Case study 7: Langfords problem Model due to Barbara Smith.

Basic modelBasic model

What are the variables?What are the variables?

Page 8: Case study 7: Langfords problem Model due to Barbara Smith.

Basic modelBasic model

What are the variables?What are the variables?Variable for each occurrence of a numberVariable for each occurrence of a number

X11 is 1st occurrence of 1X11 is 1st occurrence of 1

X21 is 1st occurrence of 2X21 is 1st occurrence of 2

....

X12 is 2nd occurrence of 1X12 is 2nd occurrence of 1

X22 is 2nd occurrence of 2X22 is 2nd occurrence of 2

....

Value is position in the sequenceValue is position in the sequence

Page 9: Case study 7: Langfords problem Model due to Barbara Smith.

Basic modelBasic model

What are the constraints?What are the constraints? Xij in [1,n*k]Xij in [1,n*k] Xij+1 = i+XijXij+1 = i+Xij Alldifferent([X11,..Xn1,X12,..Xn2,..,X1k,..Xnk])Alldifferent([X11,..Xn1,X12,..Xn2,..,X1k,..Xnk])

Page 10: Case study 7: Langfords problem Model due to Barbara Smith.

RecipeRecipe

Create a basic modelCreate a basic model Decide on the variablesDecide on the variables

Introduce auxiliary variablesIntroduce auxiliary variables For messy/loose constraintsFor messy/loose constraints

Consider dual, combined or Consider dual, combined or 0/1 models0/1 models

Break symmetryBreak symmetry Add implied constraintsAdd implied constraints Customize solverCustomize solver

Variable, value orderingVariable, value ordering

Page 11: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

Does the problem have any symmetry?Does the problem have any symmetry?

Page 12: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

Does the problem have any symmetry?Does the problem have any symmetry? Of course, we can invert any sequence!Of course, we can invert any sequence!

Page 13: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

How do we break this symmetry?How do we break this symmetry?

Page 14: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

How do we break this symmetry?How do we break this symmetry? Many possible waysMany possible ways For example, for L(3,9)For example, for L(3,9)

• Either X92 < 14 (2nd occurrence of 9 is in 1st half)Either X92 < 14 (2nd occurrence of 9 is in 1st half)• Or X92=14 and X82<14 (2nd occurrence of 8 is in Or X92=14 and X82<14 (2nd occurrence of 8 is in

1st half)1st half)

Page 15: Case study 7: Langfords problem Model due to Barbara Smith.

RecipeRecipe

Create a basic modelCreate a basic model Decide on the variablesDecide on the variables

Introduce auxiliary variablesIntroduce auxiliary variables For messy/loose constraintsFor messy/loose constraints

Consider dual, combined or Consider dual, combined or 0/1 models0/1 models

Break symmetryBreak symmetry Add implied constraintsAdd implied constraints Customize solverCustomize solver

Variable, value orderingVariable, value ordering

Page 16: Case study 7: Langfords problem Model due to Barbara Smith.

What about dual model?What about dual model?

Can we take a dual view?Can we take a dual view?

Page 17: Case study 7: Langfords problem Model due to Barbara Smith.

What about dual model?What about dual model?

Can we take a dual view?Can we take a dual view? Of course we can, it’s a permutation!Of course we can, it’s a permutation!

Page 18: Case study 7: Langfords problem Model due to Barbara Smith.

Dual modelDual model

What are the variables?What are the variables? Variable for each position iVariable for each position i

What are the values?What are the values?

Page 19: Case study 7: Langfords problem Model due to Barbara Smith.

Dual modelDual model

What are the variables?What are the variables? Variable for each position iVariable for each position i

What are the values?What are the values? If use the number at that position, we cannot If use the number at that position, we cannot

use an all-different constraintuse an all-different constraint Each number occurs not once but k timesEach number occurs not once but k times

Page 20: Case study 7: Langfords problem Model due to Barbara Smith.

Dual modelDual model

What are the variables?What are the variables? Variable for each position iVariable for each position i

What are the values?What are the values? Solution 1: use values from [1,n*k] with the Solution 1: use values from [1,n*k] with the

value i*n+j standing for the ith occurrence of jvalue i*n+j standing for the ith occurrence of j Now want to find a permutation of these Now want to find a permutation of these

numbers subject to the distance constraintnumbers subject to the distance constraint

Page 21: Case study 7: Langfords problem Model due to Barbara Smith.

Dual modelDual model

What are the variables?What are the variables? Variable for each position iVariable for each position i

What are the values?What are the values? Solution 2: use as values the numbers [1,n]Solution 2: use as values the numbers [1,n] Each number occurs exactly k timesEach number occurs exactly k times Fortunately, there is a generalization of all-different Fortunately, there is a generalization of all-different

called the global cardinality constraint (gcc) for thiscalled the global cardinality constraint (gcc) for this

Page 22: Case study 7: Langfords problem Model due to Barbara Smith.

Global cardinality constraintGlobal cardinality constraint

Gcc([X1,..Xn],l,u) enforces values used by Gcc([X1,..Xn],l,u) enforces values used by Xi to occur between l and u timesXi to occur between l and u times All-different([X1,..Xn]) = Gcc([X1,..Xn],1,1)All-different([X1,..Xn]) = Gcc([X1,..Xn],1,1)

Regin’s algorithm enforces GAC on Gcc in Regin’s algorithm enforces GAC on Gcc in O(n^2.d)O(n^2.d) Regin’s papers are tough to follow but this Regin’s papers are tough to follow but this

seems to beat his algorithm for all-different!?seems to beat his algorithm for all-different!?

Page 23: Case study 7: Langfords problem Model due to Barbara Smith.

Dual modelDual model

What are the constraints?What are the constraints? Gcc([D1,…Dk*n],k,k)Gcc([D1,…Dk*n],k,k) Distance constraints?Distance constraints?

Page 24: Case study 7: Langfords problem Model due to Barbara Smith.

Dual modelDual model

What are the constraints?What are the constraints? Gcc([D1,…Dk*n],k,k)Gcc([D1,…Dk*n],k,k) Distance constraints:Distance constraints:

• Di=j then Di+j+1=jDi=j then Di+j+1=j

Page 25: Case study 7: Langfords problem Model due to Barbara Smith.

Combined modelCombined model

Primal and dual variablesPrimal and dual variables Channelling to link themChannelling to link them

What do the channelling constraints look like?What do the channelling constraints look like?

Page 26: Case study 7: Langfords problem Model due to Barbara Smith.

Combined modelCombined model

Primal and dual variablesPrimal and dual variables Channelling to link themChannelling to link them

Xij=k implies Dk=iXij=k implies Dk=i

Page 27: Case study 7: Langfords problem Model due to Barbara Smith.

Solving choices?Solving choices?

Which variables to assign?Which variables to assign? Xij or DiXij or Di

Page 28: Case study 7: Langfords problem Model due to Barbara Smith.

Solving choices?Solving choices?

Which variables to assign?Which variables to assign? Xij or Di, doesn’t seem to matterXij or Di, doesn’t seem to matter

Which variable ordering heuristic?Which variable ordering heuristic? Fail First or Lex?Fail First or Lex?

Page 29: Case study 7: Langfords problem Model due to Barbara Smith.

Solving choices?Solving choices?

Which variables to assign?Which variables to assign? Xij or Di, doesn’t seem to matterXij or Di, doesn’t seem to matter

Which variable ordering heuristic?Which variable ordering heuristic? Fail First very marginally better than LexFail First very marginally better than Lex

How to deal with the permutation How to deal with the permutation constraint?constraint? GAC on the all-differentGAC on the all-different AC on the channellingAC on the channelling AC on the decompositionAC on the decomposition

Page 30: Case study 7: Langfords problem Model due to Barbara Smith.

Solving choices?Solving choices?

Which variables to assign?Which variables to assign? Xij or Di, doesn’t seem to matterXij or Di, doesn’t seem to matter

Which variable ordering heuristic?Which variable ordering heuristic? Fail First very marginally better than LexFail First very marginally better than Lex

How to deal with the permutation How to deal with the permutation constraint?constraint? AC on the channelling is often best for timeAC on the channelling is often best for time

Page 31: Case study 7: Langfords problem Model due to Barbara Smith.

ConclusionsConclusions

Modelling is an art but there are patternsModelling is an art but there are patterns Develop basic modelDevelop basic model

• Decide on the variables and their valuesDecide on the variables and their values Use auxiliary variables to represent constraints Use auxiliary variables to represent constraints

compactly/efficientlycompactly/efficiently Consider dual, combined and 0/1 modelsConsider dual, combined and 0/1 models Break symmetryBreak symmetry Add implied constraintsAdd implied constraints Customize solver for your modelCustomize solver for your model

Page 32: Case study 7: Langfords problem Model due to Barbara Smith.

Case study 8: social Case study 8: social golfers problemgolfers problem

Model again due to Barbara SmithModel again due to Barbara Smith

Page 33: Case study 7: Langfords problem Model due to Barbara Smith.

OutlineOutline

IntroductionIntroduction Social golfers problemSocial golfers problem

Modelling it as a CSPModelling it as a CSP Basic modelBasic model Refined modelRefined model

Experimental ResultsExperimental Results ConclusionsConclusions

Page 34: Case study 7: Langfords problem Model due to Barbara Smith.

Social golfers problemSocial golfers problem

Prob013 @ Prob013 @ www.csplib.orgwww.csplib.org

32 golfers wish to 32 golfers wish to play in 8 groups of 4 play in 8 groups of 4 each weekeach week No two play in the No two play in the

same group more than same group more than onceonce

How many weeks can How many weeks can they play?they play?

Page 35: Case study 7: Langfords problem Model due to Barbara Smith.

Social golfers problemSocial golfers problem

Prob013 @ Prob013 @ www.csplib.orgwww.csplib.org

32 golfers wish to 32 golfers wish to play in 8 groups of 4 play in 8 groups of 4 each weekeach week No two play in the No two play in the

same group more than same group more than onceonce

How many weeks can How many weeks can they play?they play? 9 weeks and this is 9 weeks and this is

optimaloptimal

Page 36: Case study 7: Langfords problem Model due to Barbara Smith.

Social golfers problemSocial golfers problem

Of course, generalize problem to g groups of s Of course, generalize problem to g groups of s players over w weeksplayers over w weeks

Kirkman’s schoolgirls’ problem Kirkman’s schoolgirls’ problem [Lady’s & [Lady’s & Gentleman’s Diary 1850]Gentleman’s Diary 1850]“… “… a schoolmistress was in the habit of taking her girls a schoolmistress was in the habit of taking her girls

for a daily walk. The girls were 15 in number, and were for a daily walk. The girls were 15 in number, and were arranged in 5 rows of 3 each, so that each girl might arranged in 5 rows of 3 each, so that each girl might have 2 companions. The problem is to so dispose have 2 companions. The problem is to so dispose them so that for 7 consecutive days no girl will walk them so that for 7 consecutive days no girl will walk with any of her school-fellows in a triplet twice …”with any of her school-fellows in a triplet twice …”

This is equivalent to social golfers problem of 5 groups This is equivalent to social golfers problem of 5 groups of 3 players over 7 weeksof 3 players over 7 weeks

Page 37: Case study 7: Langfords problem Model due to Barbara Smith.

RecipeRecipe

Create a basic modelCreate a basic model Decide on the variablesDecide on the variables

Introduce auxiliary variablesIntroduce auxiliary variables For messy/loose constraintsFor messy/loose constraints

Consider dual, combined or 0/1 Consider dual, combined or 0/1 modelsmodels

Break symmetryBreak symmetry Add implied constraintsAdd implied constraints Customize solverCustomize solver

Variable, value orderingVariable, value ordering

Page 38: Case study 7: Langfords problem Model due to Barbara Smith.

Basic modelBasic model

What are the variables?What are the variables?

Page 39: Case study 7: Langfords problem Model due to Barbara Smith.

Basic modelBasic model

What are the variables?What are the variables? Group_ij is the set of s golfers assigned to Group_ij is the set of s golfers assigned to

group i in period jgroup i in period j But I haven’t shown you set variables before!But I haven’t shown you set variables before!

Page 40: Case study 7: Langfords problem Model due to Barbara Smith.

Set variablesSet variables

CSP variables can range over (finite) CSP variables can range over (finite) domains like integersdomains like integers X1 is 1, 2, 3 or 4X1 is 1, 2, 3 or 4

Or over sets of (finite) domainsOr over sets of (finite) domains Y1 is {}, {1}, {2}, or {1,2}Y1 is {}, {1}, {2}, or {1,2}

Page 41: Case study 7: Langfords problem Model due to Barbara Smith.

Set variablesSet variables

CSP variables can range over (finite) CSP variables can range over (finite) domains like integersdomains like integers X1 is 1, 2, 3 or 4X1 is 1, 2, 3 or 4

Or over sets of (finite) domainsOr over sets of (finite) domains Y1 is {}, {1}, {2}, or {1,2}Y1 is {}, {1}, {2}, or {1,2}

Usually set operations can be posted as Usually set operations can be posted as constraints on these set variablesconstraints on these set variables Y1 subset Z1, Y1 intersect Z1 = {}, 1 in Y1, …Y1 subset Z1, Y1 intersect Z1 = {}, 1 in Y1, …

Page 42: Case study 7: Langfords problem Model due to Barbara Smith.

Set variablesSet variables

Set variables are potentially expensive to Set variables are potentially expensive to reason aboutreason about If X1 is a subset of Y1, then X1 has If X1 is a subset of Y1, then X1 has

exponentially many possible valuesexponentially many possible values CompromiseCompromise

CSP solvers just maintain upper and lower CSP solvers just maintain upper and lower bounds on set variablebounds on set variable

{} subseteq X1 subseteq {1,2} {} subseteq X1 subseteq {1,2}

Page 43: Case study 7: Langfords problem Model due to Barbara Smith.

Set variablesSet variables

Set variables are potentially expensive to Set variables are potentially expensive to reason aboutreason about If X1 is a subset of Y1, then X1 has If X1 is a subset of Y1, then X1 has

exponentially many possible valuesexponentially many possible values CompromiseCompromise

CSP solvers just maintain upper and lower CSP solvers just maintain upper and lower bounds on set variablebounds on set variable

{} subseteq X1 subseteq {1,2}{} subseteq X1 subseteq {1,2} We loose the ability to represent disjunctionWe loose the ability to represent disjunction

E.g. X1= {1} or X1={2} but X1=/ {1,2} E.g. X1= {1} or X1={2} but X1=/ {1,2}

Page 44: Case study 7: Langfords problem Model due to Barbara Smith.

Basic modelBasic model

What are the variables?What are the variables? Group_ij is the set of s golfers assigned to Group_ij is the set of s golfers assigned to

group i in period jgroup i in period j What are constraints?What are constraints?

Page 45: Case study 7: Langfords problem Model due to Barbara Smith.

Basic modelBasic model

What are the variables?What are the variables? Group_ij is the set of s golfers assigned to Group_ij is the set of s golfers assigned to

group i in period jgroup i in period j What are constraints?What are constraints?

Size of group, |Group_ij|=sSize of group, |Group_ij|=s Groups do not overlap, Group_ij intersect Groups do not overlap, Group_ij intersect

Group_i’j={}Group_i’j={} Never meet twice,Never meet twice,

for j<l . | Group_ij intersect Group_kl | <= 1for j<l . | Group_ij intersect Group_kl | <= 1

Page 46: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

What symmetry does the problem have?What symmetry does the problem have?

Page 47: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

What symmetry does the problem have?What symmetry does the problem have? Lots!Lots!

Players are symmetricalPlayers are symmetrical Groups are symmetricalGroups are symmetrical Weeks are symmetricalWeeks are symmetrical

Page 48: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

What symmetry does the problem have?What symmetry does the problem have? Lots!Lots!

Players are symmetricalPlayers are symmetrical Groups are symmetricalGroups are symmetrical Weeks are symmetricalWeeks are symmetrical

Set variables saved us worrying about Set variables saved us worrying about order within grouporder within group

Page 49: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

We can assign some values and break We can assign some values and break some of this symmetrysome of this symmetry

Page 50: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

We can assign some values and break We can assign some values and break some of this symmetrysome of this symmetry Make first week: {1,2,..s}, {s+1,s+2,..2s},…Make first week: {1,2,..s}, {s+1,s+2,..2s},…

Page 51: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

We can assign some values and break We can assign some values and break some of this symmetrysome of this symmetry Make first week: {1,2,..s}, {s+1,s+2,..2s},…Make first week: {1,2,..s}, {s+1,s+2,..2s},… In second week: player j is in jth groupIn second week: player j is in jth group

Page 52: Case study 7: Langfords problem Model due to Barbara Smith.

Break symmetryBreak symmetry

Symmetry is still leftSymmetry is still left Weeks 2 and onwards remain symmetricWeeks 2 and onwards remain symmetric Hard to post constraints to break thisHard to post constraints to break this

• E.g. smallest player in week k who plays in the E.g. smallest player in week k who plays in the same group as player n is smaller than smallest same group as player n is smaller than smallest player in week k+1 who plays in the same group as player in week k+1 who plays in the same group as player nplayer n

Page 53: Case study 7: Langfords problem Model due to Barbara Smith.

RecipeRecipe

Create a basic modelCreate a basic model Decide on the variablesDecide on the variables

Introduce auxiliary variablesIntroduce auxiliary variables For messy/loose constraintsFor messy/loose constraints

Consider dual, combined or 0/1 Consider dual, combined or 0/1 modelsmodels

Break symmetryBreak symmetry Add implied constraintsAdd implied constraints Customize solverCustomize solver

Variable, value orderingVariable, value ordering

Page 54: Case study 7: Langfords problem Model due to Barbara Smith.

Alternative modelAlternative model

Focus on pairs of players that play Focus on pairs of players that play togethertogether

Less intrinsic symmetryLess intrinsic symmetry

Page 55: Case study 7: Langfords problem Model due to Barbara Smith.

Alternative modelAlternative model

What are the variables?What are the variables?

Page 56: Case study 7: Langfords problem Model due to Barbara Smith.

Alternative modelAlternative model

What are the variables?What are the variables? Number the pairsNumber the pairs

<1,2> is 0<1,2> is 0

<1,3> is 1<1,3> is 1

....

<1,n> is n-2<1,n> is n-2

<2,3> is n-1<2,3> is n-1

....

Page 57: Case study 7: Langfords problem Model due to Barbara Smith.

Alternative modelAlternative model

What are the variables?What are the variables? Number the pairsNumber the pairs Variable Week_k is the week that pair number Variable Week_k is the week that pair number

k meetk meet

Page 58: Case study 7: Langfords problem Model due to Barbara Smith.

Alternative modelAlternative model

What are the variables?What are the variables? Number the pairsNumber the pairs Variable Week_k is the week that pair number Variable Week_k is the week that pair number

k meetk meet• If they never meet, it is 0If they never meet, it is 0

Page 59: Case study 7: Langfords problem Model due to Barbara Smith.

Symmetry in alternative Symmetry in alternative modelmodel

Less symmetryLess symmetry Again, no symmetry in order of players within Again, no symmetry in order of players within

groupgroup Now, no symmetry between groups in weekNow, no symmetry between groups in week Indeed, groups are not explicitly named!Indeed, groups are not explicitly named!

Page 60: Case study 7: Langfords problem Model due to Barbara Smith.

Constraints in alternative Constraints in alternative modelmodel

No pair meets twiceNo pair meets twice Implicit in assigning single value to Week_kImplicit in assigning single value to Week_k

Groups are closedGroups are closed If i and j play together in week t, and j and k If i and j play together in week t, and j and k

play together in week t then i and k play play together in week t then i and k play togethertogether

Lots of messy constraintsLots of messy constraints

Page 61: Case study 7: Langfords problem Model due to Barbara Smith.

RecipeRecipe

Create a basic modelCreate a basic model Decide on the variablesDecide on the variables

Introduce auxiliary variablesIntroduce auxiliary variables For messy/loose constraintsFor messy/loose constraints

Consider dual, combined or 0/1 Consider dual, combined or 0/1 modelsmodels

Break symmetryBreak symmetry Add implied constraintsAdd implied constraints Customize solverCustomize solver

Variable, value orderingVariable, value ordering

Page 62: Case study 7: Langfords problem Model due to Barbara Smith.

Introduce auxiliary variablesIntroduce auxiliary variables

Players_ik = set of players playing with i in Players_ik = set of players playing with i in week kweek k

Page 63: Case study 7: Langfords problem Model due to Barbara Smith.

Introduce auxiliary variablesIntroduce auxiliary variables

Players_ik = set of players playing with i in Players_ik = set of players playing with i in week kweek k i belongs to Players_iki belongs to Players_ik NB still haven’t named groupsNB still haven’t named groups

Page 64: Case study 7: Langfords problem Model due to Barbara Smith.

Introduce auxiliary variablesIntroduce auxiliary variables

Players_ik = set of players playing with i in Players_ik = set of players playing with i in week kweek k i belongs to Players_ki belongs to Players_k

Combine with initial modelCombine with initial model

Page 65: Case study 7: Langfords problem Model due to Barbara Smith.

Combined modelCombined model

Express constraints in model where they Express constraints in model where they are easiest!are easiest!

Channelling constraints to link modelsChannelling constraints to link models Week_k=t with k=<i,j> implies Week_k=t with k=<i,j> implies

Players_it=Players_jtPlayers_it=Players_jt Week_k/=t with k=<i,j> implies Players_it Week_k/=t with k=<i,j> implies Players_it

intersect Players_jt = {}intersect Players_jt = {}

Page 66: Case study 7: Langfords problem Model due to Barbara Smith.

Combined modelCombined model

Express constraints in model where they Express constraints in model where they are easiest!are easiest!

Channelling constraints to link modelsChannelling constraints to link models Week_k=t with k=<i,j> implies Week_k=t with k=<i,j> implies

Players_it=Players_jtPlayers_it=Players_jt Week_k/=t with k=<i,j> implies Players_it Week_k/=t with k=<i,j> implies Players_it

intersect Players_jt = {}intersect Players_jt = {} NB build in knowledge about transitivityNB build in knowledge about transitivity

Page 67: Case study 7: Langfords problem Model due to Barbara Smith.

RecipeRecipe

Create a basic modelCreate a basic model Decide on the variablesDecide on the variables

Introduce auxiliary variablesIntroduce auxiliary variables For messy/loose constraintsFor messy/loose constraints

Consider dual, combined or 0/1 Consider dual, combined or 0/1 modelsmodels

Break symmetryBreak symmetry Add implied constraintsAdd implied constraints Customize solverCustomize solver

Variable, value orderingVariable, value ordering

Page 68: Case study 7: Langfords problem Model due to Barbara Smith.

Implied constraintsImplied constraints

Take a group from any week, {g1,..gs}Take a group from any week, {g1,..gs} In any other week, these players must be In any other week, these players must be

spread over exactly s groupsspread over exactly s groups Adds significant overhead but can be useful Adds significant overhead but can be useful

on certain problemson certain problems

Page 69: Case study 7: Langfords problem Model due to Barbara Smith.

Week symmetryWeek symmetry

Excuse the pun (week/weak)Excuse the pun (week/weak) We devised a model without groupsWe devised a model without groups

Eliminating group symmetryEliminating group symmetry We still have lots of week symmetryWe still have lots of week symmetry

Can we model without weeks?Can we model without weeks?

Page 70: Case study 7: Langfords problem Model due to Barbara Smith.

Week symmetryWeek symmetry

Excuse the pun (week/weak)Excuse the pun (week/weak) We devised a model without groupsWe devised a model without groups

Eliminating group symmetryEliminating group symmetry We still have lots of week symmetryWe still have lots of week symmetry

Can we model without weeks?Can we model without weeks? Surprisingly, yesSurprisingly, yes Model is convoluted but gives good resultsModel is convoluted but gives good results First model to solve Kirkman’s schoolgirls First model to solve Kirkman’s schoolgirls

problelproblel

Page 71: Case study 7: Langfords problem Model due to Barbara Smith.

3rd Model3rd Model

What are the variables?What are the variables? AllPairs_k is the set of all pairs playing with AllPairs_k is the set of all pairs playing with

pair k (k=<i,j>)pair k (k=<i,j>)

Page 72: Case study 7: Langfords problem Model due to Barbara Smith.

3rd Model3rd Model

What are the variables?What are the variables? AllPairs_k is the set of all pairs playing with AllPairs_k is the set of all pairs playing with

pair k (k=<i,j>)pair k (k=<i,j>)• k belongs to AllPairs_kk belongs to AllPairs_k

Page 73: Case study 7: Langfords problem Model due to Barbara Smith.

3rd Model3rd Model

What are the variables?What are the variables? AllPairs_k is the set of all pairs playing with AllPairs_k is the set of all pairs playing with

pair k (k=<i,j>)pair k (k=<i,j>) SameWeek_k is the set of all pairs playing in SameWeek_k is the set of all pairs playing in

the same week as kthe same week as k

Page 74: Case study 7: Langfords problem Model due to Barbara Smith.

3rd Model3rd Model

What are the variables?What are the variables? AllPairs_k is the set of all pairs playing with AllPairs_k is the set of all pairs playing with

pair k (k=<i,j>)pair k (k=<i,j>) SameWeek_k is the set of all pairs playing in SameWeek_k is the set of all pairs playing in

the same week as kthe same week as k PlayersWithPair_k is the set of individual PlayersWithPair_k is the set of individual

players playing with kplayers playing with k

Page 75: Case study 7: Langfords problem Model due to Barbara Smith.

3rd Model3rd Model

What are the variables?What are the variables? AllPairs_k is the set of all pairs playing with AllPairs_k is the set of all pairs playing with

pair k (k=<i,j>)pair k (k=<i,j>) SameWeek_k is the set of all pairs playing in SameWeek_k is the set of all pairs playing in

the same week as kthe same week as k PlayersWithPair_k is the set of individual PlayersWithPair_k is the set of individual

players playing with kplayers playing with k• If k=<i,j> then i and j belong to PlayersWithPair_kIf k=<i,j> then i and j belong to PlayersWithPair_k

Page 76: Case study 7: Langfords problem Model due to Barbara Smith.

3rd Model3rd Model

What are the variables?What are the variables? AllPairs_k is the set of all pairs playing with AllPairs_k is the set of all pairs playing with

pair k (k=<i,j>)pair k (k=<i,j>) PairsSameWeek_k is the set of all pairs PairsSameWeek_k is the set of all pairs

playing in the same week as kplaying in the same week as k PlayersWithPair_k is the set of individual PlayersWithPair_k is the set of individual

players playing with kplayers playing with k PlaySameWeek_kk’ is 1 iff k and k’ play in PlaySameWeek_kk’ is 1 iff k and k’ play in

same week and 0 otherwisesame week and 0 otherwise

Page 77: Case study 7: Langfords problem Model due to Barbara Smith.

ChannellingChannelling

We can channel back to the 2nd modelWe can channel back to the 2nd model if Week_k=Week_k’ thenif Week_k=Week_k’ then

• PairsSameWeek_k = PairsSameWeek_k’PairsSameWeek_k = PairsSameWeek_k’ If Week_k/=Week_k’ then If Week_k/=Week_k’ then

• PairsSameWeek_k intersect PairsSameWeek_k’ = PairsSameWeek_k intersect PairsSameWeek_k’ = {}{}

……

Page 78: Case study 7: Langfords problem Model due to Barbara Smith.

Symmetry remainingSymmetry remaining

Players are still symmetricalPlayers are still symmetrical Can assign first weekCan assign first week {1,2,..s},{s+1,..,2s},…{1,2,..s},{s+1,..,2s},…

Page 79: Case study 7: Langfords problem Model due to Barbara Smith.

ConclusionsConclusions

Constraints can improve your golf!Constraints can improve your golf! Set variables are useful for modellingSet variables are useful for modelling

Eliminate symmetryEliminate symmetry Alternatively, we can channel into a model Alternatively, we can channel into a model

with less symmetrywith less symmetry Even if it is cumbersome, it can helpEven if it is cumbersome, it can help

More about set variables and global (non-More about set variables and global (non-binary) constraints on set variables next binary) constraints on set variables next weekweek