modelling & solving with constraints prof. toby walsh university college cork/uppsala university
TRANSCRIPT
![Page 1: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/1.jpg)
Modelling & SolvingModelling & Solving with Constraints with Constraints
Modelling & SolvingModelling & Solving with Constraints with Constraints
Prof. Toby WalshProf. Toby Walsh
University College Cork/Uppsala UniversityUniversity College Cork/Uppsala University
![Page 2: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/2.jpg)
Overview• Introduction to constraint programming
– Constraint propagation– Backtracking search
• Modelling case studies– Simple recipe
• Solving with constraints– Global constraints– Set variables– Branching heuristics
![Page 3: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/3.jpg)
Resources• Course links
– www.cs.york.ac.uk/~tw/Links/csps/
• Benchmark problems– www.csplib.org
• Constraints solvers– LP based like ECLIPSE, Java based
solvers like JCL, …
![Page 4: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/4.jpg)
Constraint programming• “Dream” of declarative programming
– State the constraints– Solver finds a solution
• Method of choice for many hard combinatorial problems– Scheduling, assignment, routing, …
![Page 5: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/5.jpg)
Constraints are everywhere!
• No meetings before 10am
• Network traffic < 100 Gbytes/sec
• PCB width < 21cm• Salary > 45k Euros…
![Page 6: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/6.jpg)
Constraint satisfaction• Constraint satisfaction problem (CSP) is a
triple <V,D,C> where:– V is set of variables– Each X in V has set of values, D_X
• Usually assume finite domain• {true,false}, {red,blue,green}, [0,10], …
– C is set of constraints
Goal: find assignment of values to variables to satisfy all the constraints
![Page 7: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/7.jpg)
Example CSP• Course timetabling
– Variable for each courseCS101, OS102 ..
– Domain are possible timeswed9am, fri10am, ..
– Constraints:CS101 \= wed9amCapacity constraints: atmost(3,
[OS102,DB103..],wed9am)Lecturer constraints:
alldifferent([CS101,DB103,…])
![Page 8: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/8.jpg)
Constraint optimization• CSP + objective function
– E.g. objective is Profit = Income - Costs
• Find assignment of vals to vars that:– Satisfies constraints– Maximizes (minimizes) objective
• Often solved as sequence of satisfaction problems
Profit > 0, Profit > Ans1, Profit > Ans2, …
![Page 9: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/9.jpg)
Constraint programming v. Constraint logic programming
• Constraints declaratively specify problem– Logic programming natural approach
Assert constraints, call “labelling” strategy (backtracking search predicate)
• Imperative & functional toolkits• C++, Java, CAML, …
![Page 10: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/10.jpg)
Constraints• Constraints are tuples <S,R> where
– S is the scope, [X1,X2, … Xm]• list of variables to which constraint applies
– R is relation specifying allowed values (goods)
• Subset of D_X1 x D_X2 x … x D_Xm• May be specified intensionally or extensionally
![Page 11: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/11.jpg)
Constraints• Extensional specification
– List of goods (or for tight constraints, nogoods)
• Intensional specification– X1 =/= X2– 5*X1 + 6*X2 < X3– alldifferent([X1,X2,X3,X4]), …
![Page 12: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/12.jpg)
Binary v non-binary• Binary constraint
– Scope covers 2 variables– E.g. not-equals constraint: X1 =/= X2.– E.g. ordering constraint: X1 < X2
• Non-binary constraint– Scope covers 3 or more variables– E.g. alldifferent(X1,X2,X3).– E.g. tour(X1,X2,X3,X4).
“Non-binary constraints” usually do not include unary constraints!
![Page 13: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/13.jpg)
Constraint graph• Nodes = variables• Edge between 2 nodes
iff constraint between 2 associated variables– Few constraints, sparse
constraint graph– Lots of constraints,
dense constraint graph
![Page 14: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/14.jpg)
Some non-binary examples
• Timetabling– Variables: Lecture1, Lecture2, …– Values: time1, time2, …– Constraint that lectures taught by same
lecturer do not conflict:
alldifferent(Lecture1,Lecture5,…).
![Page 15: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/15.jpg)
Some non-binary examples
• Scheduling– Variables: Job1. Job2, …– Values: machine1, machine2, …– Constraint on number of jobs on each
machine:
atmost(2,[Job1,Job2,…],machine1),
atmost(1,[Job1,Job2,…],machine2).
![Page 16: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/16.jpg)
Why use non-binary constraints?
• Binary constraints are NP-complete– Any non-binary constraint can be
represented using binary constraints– E.g. alldifferent(X1,X2,X3) is “equivalent”
to X1 =/= X2, X1 =/= X3, X2 =/= X3
• In theory therefore they’re not needed– But in practice, they are!
![Page 17: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/17.jpg)
Modelling with non-binary constraints
• Benefits include:– Compact, declarative specifications
(discussed next)
– Efficient constraint propagation(discussed second)
![Page 18: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/18.jpg)
Modelling with non-binary constraints
Consider writing your own alldifferent constraint:
alldifferent([]).
alldifferent([Head|Tail]):-
onediff(Head,Tail),
alldifferent(Tail).
onediff(El,[]).
onediff(El,[Head|Tail]):-
El #\= Head,
onediff(El,Tail).
![Page 19: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/19.jpg)
Modelling with non-binary constraints
• It’s possible but it’s not very pleasant!
• Nor is it very compact– alldifferent([X1,…Xn]) expands into n(n-1)/2 binary not-
equals constraints, Xi \= Xj
– one non-binary constraint or O(n^2) binary constraints?
And there exist very efficient algorithms for reasoning efficiently with many specialized non-binary constraints
![Page 20: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/20.jpg)
Constraint solvers• Two main approaches
– Systematic, tree search algorithms– Local search or repair based procedures
• Other more exotic possibilities– Hybrid algorithms– Quantum algorithms
![Page 21: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/21.jpg)
Systematic solvers• Tree search
– Assign value to variable– Deduce values that must be removed from future/unassigned
variables• Propagation to ensure some level of consistency
– If future variable has no values, backtrack else repeat
• Number of choices– Variable to assign next, value to assign
Some important refinements like nogood learning, non-chronological backtracking, …
![Page 22: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/22.jpg)
Local search• Repair based methods
– Generate complete assignment– Change value to some variable in a violated
constraint
• Number of choices– Violated constraint, variable within it, …
Unable to exploit powerful constraint propagation techniques
![Page 23: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/23.jpg)
Constraint propagation• Heart of constraint programming• Most often enforce arc-consistency (AC)
– A binary constraint r(X1,X2) is AC iff for every value for X1, there is a consistent value (often
called support) for X2 and vice versa
– A problem is AC iff every constraint is AC
![Page 24: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/24.jpg)
Enforcing arc-consistency
• X2 \= X3 is AC• X1 \= X2 is not AC
– X2=1 has no support so can this value can be pruned
• X2 \= X3 is now not AC– No support for X3=2 – This value can also be
pruned
Problem is now AC
{1}
{1,2} {2,3}
\=
\=
X1
X3X2
![Page 25: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/25.jpg)
Enforcing arc-consistency• Remove all values that are not AC
(i.e. have no support)
• May remove support from other values (often queue based algorithm)
• Best AC algorithms (AC7, AC-2000) run in O(ed^2)– Optimal if we know nothing else about the
constraints
![Page 26: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/26.jpg)
Properties of AC• Unique maximal AC
subproblem– Or problem is
unsatisfiable
• Enforcing AC can process constraints in any order– But order does affect
(average-case) efficiency
![Page 27: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/27.jpg)
Non-binary constraint propagation
• Most popular is generalized arc-consistency (GAC)– A non-binary constraint is GAC iff for every value
for a variable there are consistent values for all other variables in the constraint
– We can again prune values that are not supported
• GAC = AC on binary constraints
![Page 28: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/28.jpg)
GAC on alldifferent• alldifferent(X1,X2,X3)
– Constraint is not GAC– X1=2 cannot be
extended• X2 would have to be 3• No value left then for
X3
– X1={1} is GAC
{1,2}
{2,3}{2,3}
X1
X2 X3
![Page 29: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/29.jpg)
Enforcing GAC• Enforcing GAC is expensive in general
– GAC schema is O(d^k)On k-ary constraint on vars with domains of size d
• Trick is to exploit semantics of constraints– Regin’s all-different algorithm– Achieves GAC in just O(k^3/2 d)
On k-ary all different constraint with domains of size dBased on finding matching in “value graph”
![Page 30: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/30.jpg)
Other types of constraint propagation
• (i,j)-consistency [due to Freuder, JACM 85]– Non-empty domains– Any consistent instantiation for i variables can be
extended to j others
• Describes many different consistency techniques
![Page 31: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/31.jpg)
(i,j)-consistency • Generalization of arc-consistency
– AC = (1,1)-consistency– Path-consistency = (2,1)-consistency
• Strong path-consistency = AC + PC
– Path inverse consistency = (1,2)-consistency
![Page 32: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/32.jpg)
Enforcing (i,j)-consistency• problem is (1,1)-consistent (AC)• BUT is not (2,1)-consistent (PC)
– X1=2, X2=3 cannot be extended to X3
– Need to add constraints:not(X1=2 & X2=3)
not(X1=2 & X3=3)
• Nor is it (1,2)-consistent (PIC)– X1=2 cannot be extended to X2 &
X3 (so needs to be deleted)
{1,2}
{2,3} {2,3}
\=
\=
X1
X3X2
\=
![Page 33: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/33.jpg)
Other types of constraint propagation
• Singleton arc-consistency (SAC)– Problem resulting from instantiating any variable
can be made AC
• Restricted path-consistency (RPC)– AC + if a value has just one support then any third
variable has a consistent value
• …
![Page 34: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/34.jpg)
Comparing local consistencies
• Formal definition of tightness introduced by Debruyne & Bessiere [IJCAI-97]
• A-consistency is tighter than B-consistency iffIf a problem is A-consistent -> it is B-consistent
We write A >= B
![Page 35: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/35.jpg)
Properties• Partial ordering
– reflexive A A– transitive A B & B C implies A C
• Defined relations– tighter A > B iff A B & not B A– incomparable A @ B iff neither A B nor B A
![Page 36: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/36.jpg)
Comparison of consistency techniques
• Exercise for the reader, prove the following identities!
Strong PC > SAC > RPC > AC
NB gaps can reduce search exponentially!
![Page 37: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/37.jpg)
Which to choose?• For binary constraints,
AC is often chosen– Space efficient
Just prune domains (cf PC)
– Time efficient
• For non-binary constraints GAC is often chosen– If we can exploit the
constraint semantics to keep it cheap!
![Page 38: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/38.jpg)
Why consider these other consistencies?
• Promising experimental results– Useful pruning for their
additional cost
• Theoretical value– E.g. GAC on non-binary
constraints may exceed SAC on equivalent binary model
![Page 39: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/39.jpg)
Maintaining a local consistency property
• Tree search– Assign value to variable– Enforce some level of local consistency
• Remove values/add new constraints
– If any future variable has no values, backtrack else repeat
• Two popular algorithms– Maintaining arc-consistency (MAC)– Forward checking (only enforce AC on instantiated variable)
![Page 40: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/40.jpg)
Modelling case study: Modelling case study: all interval seriesall interval series
Modelling case study: Modelling case study: all interval seriesall interval series
Results due to Simonis, Puget & Results due to Simonis, Puget & ReginRegin
![Page 41: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/41.jpg)
All interval series• Prob007 at www.csplib.org
• Comes from musical composition– Traced back to Alban Berg– Extensively used by Ernst Krenek
Op.170 “Quaestio temporis”
![Page 42: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/42.jpg)
All interval series• Take the 12 standard pitch classes
– c, c#, d, ..– Represent them by numbers 0, .., 11
• Find a sequence so each occurs once– Each difference occurs once
![Page 43: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/43.jpg)
All interval series• Can generalize to any n (not just 12)
Find Sn, a permutation of [0,n) such that |Sn+1-Sn| are all distinct
• Finding one solution is easy
![Page 44: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/44.jpg)
All interval series• Can generalize to any n (not just 12)
Find Sn, a permutation of [0,n) such that |Sn+1-Sn| are all distinct
• Finding one solution is easy[n,1,n-1,2,n-2,.., floor(n/2)+2,floor(n/2)-1,floor(n/2)+1,floor(n/2)]
Giving the differences [n-1,n-2,..,2,1]
Challenge is to find all solutions!
![Page 45: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/45.jpg)
Basic recipe• Devise basic CSP model
– What are the variables? What are the constraints?
• Introduce auxiliary variables if needed• Consider dual or combined models• Break symmetry• Introduce implied constraints
![Page 46: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/46.jpg)
Basic CSP model• What are the variables?
![Page 47: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/47.jpg)
Basic CSP model• What are the variables?
Si = j if the ith note is j
• What are the constraints?
![Page 48: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/48.jpg)
Basic CSP model• What are the variables?
Si = j if the ith note is j
• What are the constraints? Si in [0,n)
All-different([S1,S2,… Sn])
Forall i<i’ |Si+1 - Si| =/= |Si’+1 - Si’|
![Page 49: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/49.jpg)
Basic recipe• Devise basic CSP model
– What are the variables? What are the constraints?
• Introduce auxiliary variables if needed• Consider dual or combined models• Break symmetry• Introduce implied constraints
![Page 50: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/50.jpg)
Improving basic model• Introduce auxiliary variables?
– Are there any loose or messy constraints we could better (more compactly?) express via some auxiliary variables?
![Page 51: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/51.jpg)
Improving basic model• Introduce auxiliary variables?
– Yes, variables for the pairwise differences
Di = |Si+1 - Si|
• Now post single large all-different constraint
Di in [1,n-1]
All-different([D1,D2,…Dn-1])
![Page 52: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/52.jpg)
Basic recipe• Devise basic CSP model
– What are the variables? What are the constraints?
• Introduce auxiliary variables if needed• Consider dual or combined models• Break symmetry• Introduce implied constraints
![Page 53: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/53.jpg)
Break symmetry• Does the problem have any symmetry?
![Page 54: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/54.jpg)
Break symmetry• Does the problem have any symmetry?
– Yes, we can reverse any sequence
S1, S2, … Sn is an all-inverse series
Sn, …, S2, S1 is also
• How do we eliminate this symmetry?
![Page 55: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/55.jpg)
Break symmetry• Does the problem have any symmetry?
– Yes, we can reverse any sequenceS1, S2, …, Sn is an all-inverse seriesSn, …, S2, S1 is also
• How do we eliminate this symmetry?• Order first and last difference
D1 < Dn-1
![Page 56: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/56.jpg)
Break symmetry• Does the problem have any other
symmetry?
![Page 57: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/57.jpg)
Break symmetry• Does the problem have any other
symmetry?– Yes, we can invert the numbers in any
sequence0, n-1, 1, n-2, … map x onto n-1-x
n-1, 0, n-2, 1, …
• How do we eliminate this symmetry?
![Page 58: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/58.jpg)
Break symmetry• Does the problem have any other
symmetry?– Yes, we can invert the numbers in any
sequence0, n-1, 1, n-2, … map x onto n-1-xn-1, 0, n-2, 1, …
• How do we eliminate this symmetry?S1 < S2
![Page 59: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/59.jpg)
Performance• Basic model is poor• Improved model able to compute all
solutions up to n=14 or so– GAC on all-different constraints very
beneficial– As is enforcing GAC on Di = |Si+1-Si|
This becomes too expensive for large nSo use just bounds consistency (BC) for larger n
![Page 60: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/60.jpg)
Modelling case study: Modelling case study: Langford’s problemLangford’s problem
Modelling case study: Modelling case study: Langford’s problemLangford’s problem
Model due to Barbara SmithModel due to Barbara Smith
![Page 61: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/61.jpg)
Outline• Introduction
– Langford’s problem
• Modelling it as a CSP– Basic model– Refined model
• Experimental Results• Conclusions
![Page 62: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/62.jpg)
Recipe• Create a basic model
– Decide on the variables
• Introduce auxiliary variables– For messy/loose constraints
• Consider dual, combined or 0/1 models
• Break symmetry• Add implied constraints• Customize solver
– Variable, value ordering
![Page 63: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/63.jpg)
Langford’s problem• Prob024 @
www.csplib.org• Find a sequence of 8
numbers– Each number [1,4]
occurs twice– Two occurrences of i are
i numbers apart
• Unique solution– 41312432
![Page 64: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/64.jpg)
Langford’s problem• L(k,n) problem
– To find a sequence of k*n numbers [1,n]
– Each of the k successive occrrences of i are i apart
– We just saw L(2,4)
• Due to the mathematician Dudley Langford– Watched his son build a
tower which solved L(2,3)
![Page 65: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/65.jpg)
Langford’s problem• L(2,3) and L(2,4) have unique solutions• L(2,4n) and L(2,4n-1) have solutions
– L(2,4n-2) and L(2,4n-3) do not– Computing all solutions of L(2,19) took 2.5 years!
• L(3,n)– No solutions: 0<n<8, 10<n<17, 20, ..– 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 66: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/66.jpg)
Basic model• What are the variables?
![Page 67: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/67.jpg)
Basic model• What are the variables?
Variable for each occurrence of a numberX11 is 1st occurrence of 1X21 is 1st occurrence of 2..X12 is 2nd occurrence of 1X22 is 2nd occurrence of 2..
• Value is position in the sequence
![Page 68: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/68.jpg)
Basic model• What are the constraints?
– Xij in [1,n*k]– Xij+1 = i+Xij– Alldifferent([X11,..Xn1,X12,..Xn2,..,X1k,..X
nk])
![Page 69: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/69.jpg)
Recipe• Create a basic model
– Decide on the variables
• Introduce auxiliary variables– For messy/loose constraints
• Consider dual, combined or 0/1 models
• Break symmetry• Add implied constraints• Customize solver
– Variable, value ordering
![Page 70: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/70.jpg)
Break symmetry• Does the problem have any symmetry?
![Page 71: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/71.jpg)
Break symmetry• Does the problem have any symmetry?
– Of course, we can invert any sequence!
![Page 72: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/72.jpg)
Break symmetry• How do we break this symmetry?
![Page 73: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/73.jpg)
Break symmetry• How do we break this symmetry?
– Many possible ways– For example, for L(3,9)
• Either X92 < 14 (2nd occurrence of 9 is in 1st half)
• Or X92=14 and X82<14 (2nd occurrence of 8 is in 1st half)
![Page 74: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/74.jpg)
Recipe• Create a basic model
– Decide on the variables
• Introduce auxiliary variables– For messy/loose constraints
• Consider dual, combined or 0/1 models
• Break symmetry• Add implied constraints• Customize solver
– Variable, value ordering
![Page 75: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/75.jpg)
What about dual model?• Can we take a dual view?
![Page 76: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/76.jpg)
What about dual model?• Can we take a dual view?
• Of course we can, it’s a permutation!
![Page 77: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/77.jpg)
Dual model• What are the variables?
– Variable for each position i
• What are the values?
![Page 78: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/78.jpg)
Dual model• What are the variables?
– Variable for each position i
• What are the values?– If use the number at that position, we cannot use
an all-different constraint– Each number occurs not once but k times
![Page 79: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/79.jpg)
Dual model• What are the variables?
– Variable for each position i
• What are the values?– Solution 1: use values from [1,n*k] with the value
i*n+j standing for the ith occurrence of j– Now want to find a permutation of these numbers
subject to the distance constraint
![Page 80: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/80.jpg)
Dual model• What are the variables?
– Variable for each position i
• What are the values?– Solution 2: use as values the numbers [1,n]– Each number occurs exactly k times– Fortunately, there is a generalization of all-different called
the global cardinality constraint (gcc) for this
![Page 81: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/81.jpg)
Global cardinality constraint
• Gcc([X1,..Xn],l,u) enforces values used by Xi to occur between l and u times– All-different([X1,..Xn]) = Gcc([X1,..Xn],1,1)
• Regin’s algorithm enforces GAC on Gcc in O(n^2.d)
![Page 82: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/82.jpg)
Dual model• What are the constraints?
– Gcc([D1,…Dk*n],k,k)– Distance constraints?
![Page 83: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/83.jpg)
Dual model• What are the constraints?
– Gcc([D1,…Dk*n],k,k)– Distance constraints:
• Di=j then Di+j+1=j
![Page 84: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/84.jpg)
Combined model• Primal and dual variables
• Channelling to link them– What do the channelling constraints look
like?
![Page 85: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/85.jpg)
Combined model• Primal and dual variables
• Channelling to link them– Xij=k implies Dk=i
![Page 86: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/86.jpg)
Solving choices?• Which variables to assign?
– Xij or Di
![Page 87: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/87.jpg)
Solving choices?• Which variables to assign?
– Xij or Di, doesn’t seem to matter
• Which variable ordering heuristic?– Fail First or Lex?
![Page 88: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/88.jpg)
Solving choices?• Which variables to assign?
– Xij or Di, doesn’t seem to matter
• Which variable ordering heuristic?– Fail First very marginally better than Lex
• How to deal with the permutation constraint?– GAC on the all-different– AC on the channelling– AC on the decomposition
![Page 89: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/89.jpg)
Solving choices?• Which variables to assign?
– Xij or Di, doesn’t seem to matter
• Which variable ordering heuristic?– Fail First very marginally better than Lex
• How to deal with the permutation constraint?– AC on the channelling is often best for time
![Page 90: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/90.jpg)
Global constraintsGlobal constraintsGlobal constraintsGlobal constraints
![Page 91: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/91.jpg)
Non-exhaustive catalog• Order constraints• Constraints on values• Partitioning constraints• Timetabling constraints• Graph constraints• Scheduling constraints• Bin-packing constraints
![Page 92: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/92.jpg)
Global constraints• It isn’t just all-different!
• Many constraints specialized to application domains– Scheduling– Packing– ..
![Page 93: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/93.jpg)
Order constraints• min(X,[Y1,..,Yn]) and max(X,[Y1,..Yn])
X <= minimum(Y1,..,Yn)
X >= maximum(Y1,..Yn)
![Page 94: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/94.jpg)
Order constraints• min_n(X,n,[Y1,..Ym]) and max_n(X,n,
[Y1,..,Ym)
X is nth smallest value in Y1,..YmX is nth largest value in Y1,..Ym
![Page 95: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/95.jpg)
Value constraints• among(N,[Y1,..,Yn],[val1,..,valm])
N vars in [Y1,..,Yn] take values val1,..valme.g. among(2,[1,2,1,3,1,5],[3,4,5])
![Page 96: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/96.jpg)
Value constraints• among(N,[Y1,..,Yn],[val1,..,valm])
N vars in [Y1,..,Yn] take values val1,..valme.g. among(2,[1,2,1,3,1,5],[3,4,5])
• count(n,[Y1,..,Ym],op,X) where op is =,<,>,=/,<= or >=relation “Yi op X” holds n times
among(n,[Y1,..,Ym],[k])=count(n,[Y1,..,Ym],=,k)
![Page 97: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/97.jpg)
Value constraints• balance(N,[Y1,..,Yn])
N = occurrence of more frequent value - occurrence of least frequent value
E.g balance(2,[1,1,1,3,4,2])
![Page 98: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/98.jpg)
Value constraints• balance(N,[Y1,..,Yn])
N = occurrence of more frequent value - occurrence of least frequent value
E.g balance(2,[1,1,1,3,4,2])
all-different([Y1,..,Yn]) => balance(0,[Y1,..,Yn])
![Page 99: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/99.jpg)
Value constraints• min_nvalue(N,[Y1,..,Yn]) and max_nvalue(N,
[Y1,..,Yn])least (most) common value in Y1,..,Yn occurs N timesE.g. min_nvalue(2,[1,1,2,2,2,3,3,5,5])
Can replace multiple count or among constraints
![Page 100: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/100.jpg)
Value constraints• common(X,Y,[X1,..,Xn],[Y1,..,Ym])
X vars in Xi take a value in Yi
Y vars in Yi take a value in Xi
E.g. common(3,4,[1,9,1,5],[2,1,9,9,6,9])
![Page 101: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/101.jpg)
Value constraints• common(X,Y,[X1,..,Xn],[Y1,..,Ym])
X vars in Xi take a value in YiY vars in Yi take a value in XiE.g. common(3,4,[1,9,1,5],[2,1,9,9,6,9])
among(X,[Y1,..,Yn],[val1,..,valm]) = common(X,Y,[X1,..,Yn],[val1,..,valm])
![Page 102: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/102.jpg)
Value constraints• same([X1,..,Xn],[Y1,..,Yn])
Yi is a permutation of Xi
![Page 103: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/103.jpg)
Value constraints• same([X1,..,Xn],[Y1,..,Yn])
Yi is a permutation of Xi
• used_by([X1,..,Xn],[Y1,..,Ym])all values in Yi are used by vars in Xim>=m
![Page 104: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/104.jpg)
Value constraints• same([X1,..,Xn],[Y1,..,Yn])
Yi is a permutation of Xi
• used_by([X1,..,Xn],[Y1,..,Ym])all values in Yi are used by vars in Xim>=m
• on n values:alldifferent([X1,..,Xn])=same([X1,..,Xn],[1,..,n])
=used_by([X1,..,Xn],[1,..,n])
![Page 105: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/105.jpg)
Partitioning constraints• all-different([X1,..,Xn])
![Page 106: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/106.jpg)
Partitioning constraints• all-different([X1,..,Xn])
• Other flavoursall-different_except_0([X1,..,Xn])Xi=/Xj unless Xi=Xj=0
• 0 is often used for modelling purposes as “dummy” value
– Don’t use this slab– Don’t open this bin ..
![Page 107: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/107.jpg)
Partitioning constraints• all-different([X1,..,Xn])
• Other flavourssymmetric-all-different([X1,..,Xn])Xi=/Xj and Xi=j iff Xj=i
• Very common in practice– Team i plays j iff Team j plays i..
![Page 108: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/108.jpg)
Partitioning constraints• nvalue(N,[X1,..,Xn])
Xi takes N different valuesall-different([X1,..,Xn]) = nvalue(n,[X1,..,Xn)
![Page 109: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/109.jpg)
Partitioning constraints• nvalue(N,[X1,..,Xn])
Xi takes N different valuesall-different([X1,..,Xn]) = nvalue(n,[X1,..,Xn)
• gcc([X1,..,Xn],Lo,Hi)values in Xi occur between Lo and Hi timesall-different([X1,..,Xn])=gcc([X1,..,Xn],1,1)
![Page 110: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/110.jpg)
Timetabling constraints• change(N,[X1,..,Xn]),op) where op is
{=,<,>,<=,>=,/=}“Xi op Xi+1” holds N timesE.g. change(3,[4,4,3,4,1],/=)
• You may wish to limit the number of changes of classroom, shifts, …
![Page 111: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/111.jpg)
Timetabling constraints• longest_changes(N,[X1,..,Xn]),op) where op
is {=,<,>,<=,>=,/=}longest sequence “Xi op Xi+1” is of length NE.g. longest_changes(2,[4,4,4,3,3,2,4,1,1,1],=)
• You may wish to limit the length of a shift without break, …
![Page 112: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/112.jpg)
Graph constraints• Tours in graph a often represented by
the successors:
• [X1,..,Xn] means from node i we go to node Xi
![Page 113: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/113.jpg)
Graph constraints• Tours in graph a often represented by
the successors:• [X1,..,Xn] means from node i we go to
node Xi• E.g. [2,1,5,3,4] represents the 2 cycles
(1)->(2)->(1) and (3)->(5)->(4)->(3)
![Page 114: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/114.jpg)
Graph constraints• cycle(N,[X1,..,Xn])
there are N cycles in Xi
e.g. cycle(2,[2,1,5,3,4]) as we have the 2 cycles(1)->(2)->(1) and (3)->(5)->(4)->(3)
Useful for TSP like problems (e.g. sending engineers out to repair phones)
![Page 115: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/115.jpg)
Scheduling constraints• cummulative([S1,..,Sn],[D1,..,Dn],[E1,..,En],
[H1,..,Hn],L)• schedules n (concurrent) jobs, each with a
height Hi• ith job starts at Si, runs for Di and ends at Ei
– Ei=Si+Di
• at any time, accumulated height of running jobs is less than L
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
![Page 116: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/116.jpg)
Scheduling constraints• coloured_cummulative([S1,..,Sn],[D1,..,Dn],
[E1,..,En],[C1,..,Cn],L)• schedules n (concurrent) each with a colour
Ci• no more than L colours running at any one
time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
![Page 117: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/117.jpg)
Scheduling constraints• cycle_cummulative(m,[S1,..,Sn],
[D1,..,Dn],[E1,..,En],[H1,..,Hn],L)• schedules n (concurrent) jobs, each
with a height Hi onto a cyclic schedule of length m
![Page 118: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/118.jpg)
Scheduling constraints• cummulatives([M1,,,Mn],[S1,..,Sn],[D1,..,Dn],
[E1,..,En],[H1,..,Hn],[L1,..,Lm])• schedules n (concurrent) jobs, each with a
height Hi onto one of m machines• ith runs on Mi• accumulated height of running jobs on
machine i <= Li
![Page 119: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/119.jpg)
Scheduling constraints• cummulatives([M1,..Mn],[S1,..,Sn],
[D1,..,Dn],[E1,..,En],[H1,..,Hn],[L1,..,Lm])
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Machine 1
Machine 2
![Page 120: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/120.jpg)
Scheduling constraints• coloured_cummulatives([M1,,,Mn],[S1,..,Sn],
[D1,..,Dn],[E1,..,En],[C1,..,Cn],[L1,..,Lm])• schedules n (concurrent) jobs, each with a
colour i onto one of m machines• ith runs on Mi• number of colours of running jobs on
machine i <= Li
![Page 121: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/121.jpg)
Bin-packing constraints• bin_packing(capacity,[B1,..,Bn],
[w1,..,wn])
for each bin j, sum_Bi=j wi <= capacity
![Page 122: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/122.jpg)
Bin-packing constraints• bin_packing(capacity,[B1,..,Bn],
[w1,..,wn])
for each bin j, sum_Bi=j wi <= capacity
special case of cummulative with task durations=1
![Page 123: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/123.jpg)
Misc constraints• element(Index,[a1,..,an],Var)
Var=a_Index
constraint programming’s answer to arrays!
e.g. element(Item,[10,23,12,15],Cost)
![Page 124: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/124.jpg)
Modelling: set variablesModelling: set variablesModelling: set variablesModelling: set variables
![Page 125: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/125.jpg)
Motivation• Sets are useful when
– We don’t know how many objects we will have • e.g. set of items go in a bin
– We have symmetrical objects• e.g. items are symmetric and we don’t want to consider
all their permutations
And in many other situations!
![Page 126: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/126.jpg)
Outline• Representing set variables
– Bounds– Characteristic functions
• Constraining set variables– Primitive constraints– Global constraints
![Page 127: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/127.jpg)
Set variables• Representing sets
– Domain of values = powerset – Exponential space would be needed to represent this
extensional
![Page 128: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/128.jpg)
Set variables• Representing sets
– Domain of values = powerset – Exponential space would be needed to represent this
extensional– Compromise: just represent upper and lower bound
• E.g. {} subseteq X subseteq {1,2}
• X in {{},{1},{2},{1,2}}
![Page 129: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/129.jpg)
Set variables• Representing sets
– Domain of values = powerset
– Exponential space would be needed to represent this extensional
– Compromise: just represent upper and lower bound• E.g. {} subseteq X subseteq {1,2}• X in {{},{1},{2},{1,2}}
– Tradeoff• Cannot represent disjunction• E.g. X is {1} or {2} but not {1,2}
![Page 130: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/130.jpg)
Alternative representation• Characteristic function
– i in X iff Xi=1
![Page 131: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/131.jpg)
Alternative representation• Characteristic function
– i in X iff Xi=1– E.g. {1} subseteq X subseteq {1,2,3}
![Page 132: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/132.jpg)
Alternative representation• Characteristic function
– i in X iff Xi=1– E.g. {1} subseteq X subseteq {1,2,3}
• X1=1• X2 in {0,1}, X3 in {0,1} • X4=X5=..=0
![Page 133: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/133.jpg)
Primitive constraints• X subset Y• X subseteq Y• a in X• X = Y intersect Z• X = Y union Z• X = Y - Z• X = {}
![Page 134: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/134.jpg)
Bounds consistency• Analogous to bounds consistency on
ordered finite domains
• Given constraint, C over X1,..,Xn
• C is BC if for each Xi, – a in glb(Xi) iff a is in some solution – a in lub(Xi) iff a is in all solutions
![Page 135: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/135.jpg)
Bounds consistency• Lub(A union B) => Lub(A) union Lub(B)
• Glb(A union B) => Glb(A) union Glb(B)
![Page 136: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/136.jpg)
Bounds consistency• Lub(A union B) => Lub(A) union Lub(B)
• Glb(A union B) => Glb(A) union Glb(B)– This last rule is a safe approximation– Glb(A union B) superseteq Glb(A) union Glb(B)
![Page 137: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/137.jpg)
Bounds consistency• Lub(A union B) => Lub(A) union Lub(B)
• Glb(A union B) => Glb(A) union Glb(B)
• Lub(A intersect B) => Lub(A) intersect Lub(B)
• Glb(A intersect B) => Glb(A) intersect Glb(B)
![Page 138: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/138.jpg)
Bounds consistency• Lub(A union B) => Lub(A) union Lub(B)
• Glb(A union B) => Glb(A) union Glb(B)
• Lub(A intersect B) => Lub(A) intersect Lub(B)
• Glb(A intersect B) => Glb(A) intersect Glb(B)– The third rule is a safe approximation– Lub(A intersect B) subseteq
Lub(A) intersect Lub(B)
![Page 139: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/139.jpg)
Bounds consistency• Lub(A union B) => Lub(A) union Lub(B)
• Glb(A union B) => Glb(A) union Glb(B)
• Lub(A intersect B) => Lub(A) intersect Lub(B)
• Glb(A intersect B) => Glb(A) intersect Glb(B)
• A subseteq B => Lub(A) subseteq Lub(B),
Glb(A) subseteq Glb(B)
![Page 140: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/140.jpg)
Bounds consistency• Lub(A union B) => Lub(A) union Lub(B)
• Glb(A union B) => Glb(A) union Glb(B)
• Lub(A intersect B) => Lub(A) intersect Lub(B)
• Glb(A intersect B) => Glb(A) intersect Glb(B)
• A subseteq B => Lub(A) subseteq Lub(B),
Glb(A) subseteq Glb(B)
• A = B => A subseteq B, B subseteq A
…
![Page 141: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/141.jpg)
Bounds consistency• Apply these rules exhaustively
• This computes safe approximations– Lub’s are correct or too large– Glb’s are correct or too small
• If a set of constraints have a solution– Exists unique lub and glb for the set variables– That satisfy these rules
![Page 142: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/142.jpg)
Intervals v Characteristic functions
• It doesn’t really matter!
• TheoremA set of constraints in normal form is BC iff
the characteristic function representation is AC
![Page 143: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/143.jpg)
Intervals v Characteristic functions
• It doesn’t really matter!
• TheoremA set of constraints in normal form is BC iff the
characteristic function representation is AC
NB characteristic function is 0/1 model so AC is the same as bounds consistency!
![Page 144: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/144.jpg)
Global constraints• All-different constraint
– No two vars take same value
• Permutation constraint– Special case of all-different– All values are used
![Page 145: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/145.jpg)
Global constraints• All-different constraint
– No two vars take same value
• Disjoint constraint– No two set variables intersect
![Page 146: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/146.jpg)
Global constraints• All-different constraint
– No two vars take same value
• Disjoint constraint– No two set variables intersect
• Permutation constraint– All-different, & all values are used
![Page 147: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/147.jpg)
Global constraints• All-different constraint
– No two vars take same value
• Disjoint constraint– No two set variables intersect
• Permutation constraint– All-different, & all values are used
• Partition constraint– Disjoint, & all values are used
![Page 148: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/148.jpg)
Global constraints• Disjoint([X1,..,Xn]) decomposes into
Xi intersect Xj = {}
Just like the all-different constraint!
![Page 149: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/149.jpg)
Global constraints• Disjoint([X1,..,Xn]) decomposes into
Xi intersect Xj = {}
Just like the all-different constraint!
But decomposition does not hurt!
![Page 150: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/150.jpg)
Global constraints• Disjoint([X1,..,Xn]) decomposes into
Xi intersect Xj = {}
Just like the all-different constraint!
But decomposition does not hurt!
Theorem
BC on disjoint([X1,..,Xn]) =
BC on decomposed model
![Page 151: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/151.jpg)
Global constraints• Partition([X1,..,Xn],S) decomposes into
Xi intesect Xj = {}
X1 union X2=Y1
X3 union Y1 = Y2
…
Xn union Yn-2 = S
![Page 152: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/152.jpg)
Global constraints• Partition([X1,..,Xn],S) decomposes into
Xi intesect Xj = {}
X1 union X2=Y1
X3 union Y1 = Y2
…
Xn union Yn-2 = S
Decomposition does not hurt!
![Page 153: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/153.jpg)
Global constraints• Partition([X1,..,Xn],S) decomposes
Decomposition again does not hurt!
TheoremBC on partition([X1,..,Xn],S) =BC on the decomposed model
![Page 154: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/154.jpg)
Global constraints• Non-empty-partition([X1,..,Xn],S)
• Decomposes as before
• With additional constraint:– |Xi| > 0
![Page 155: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/155.jpg)
Global constraints• Non-empty-partition([X1,..,Xn],S)
Decomposition now hurts!
![Page 156: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/156.jpg)
Global constraints• Non-empty-partition([X1,..,Xn],S)
Decomposition now hurts!TheoremBC on non-empty-partition([X1,..,Xn],S) is strictly stronger than BC on decompostion
![Page 157: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/157.jpg)
Modelling with set constraints
• Ternary Steiner problem– n(n-1)/6 sets, Si – Each a subset of {1,..,n}– |Si| = 3
Nb n(n-1)/6 = nC2 / 3
![Page 158: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/158.jpg)
Modelling with set constraints
• Ternary Steiner problem– n(n-1)/6 sets, Si – Each a subset of {1,..,n}– |Si| = 3– |Si intersect Sj| <=1
![Page 159: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/159.jpg)
Ternary Steiner problem• Only soluble if n mod 6 = 1 or 3 [Kirkman 1847]
– S3 = {{1,2,3}}– S7 = {{1,2,4},{2,3,5},{3,4,6},{4,5,7},{5,6,1},{6,7,2},{7,1,3}}
• Number of non-isomorphic triples– 1,1,2,80,>1.1*10^9 [Colbourn & Dinitz 1996]– AO30139
![Page 160: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/160.jpg)
Ternary Steiner problem• Simple and elegant set variable model
Let t=n(n-1)/6For all j in [1,t] . Sj subset {1,..,n} and |Sj|=3Atmost1([S1,..,St])
![Page 161: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/161.jpg)
Ternary Steiner problem• Simple and elegant set variable model
Let t=n(n-1)/6For all j in [1,t] . Sj subset {1,..,n} and |Sj|=3Atmost1([S1,..,St])
For all j<k in [1,t] . |Sj intersect Sk| <=1
What’s wrong with this model?
![Page 162: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/162.jpg)
Ternary Steiner problem• Simple and elegant set variable model
Let t=n(n-1)/6For all j in [1,t] . Sj subset {1,..,n} and |Sj|=3Atmost1([S1,..,St])
What’s wrong with this model?Numbers and Si are still symmetric.How do we deal with this?
![Page 163: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/163.jpg)
Ternary Steiner problem– Breaking symmetry
• Make some initial assignments• S1={1,2,3}, S2={2,4,5}, …• Until all numbers named once
![Page 164: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/164.jpg)
Ternary Steiner problem– Breaking symmetry
• Order sets S1<S2<..<St • e.g. multiset ordering
![Page 165: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/165.jpg)
Conclusions• Set variables are useful for modelling
– But they still can leave symmetry!
• Constraints on set variables– Primitive constraints– Global constraints
• Decomposition hurts in general as soon as we add cardinality conditions
![Page 166: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/166.jpg)
Recipe• Create a basic model
– Decide on the variables
• Introduce auxiliary variables– For messy/loose constraints
• Consider dual, combined or 0/1 models
• Break symmetry• Add implied constraints• Customize solver
– Level of consistency
– Variable, value ordering
![Page 167: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/167.jpg)
Solving choices• Level of consistency
– Binary v non-binary constraints– GAC, BC …
![Page 168: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/168.jpg)
Solving choices• Branching heuristics
– Variable ordering (fail first)• Smallest domain, max degree, …
– Value ordering (succed first)• Max promise, …
![Page 169: Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University](https://reader036.vdocuments.site/reader036/viewer/2022081602/551ad6a6550346856e8b61ec/html5/thumbnails/169.jpg)
Recipe• Create a basic model
– Decide on the variables
• Introduce auxiliary variables– For messy/loose constraints
• Consider dual, combined or 0/1 models
• Break symmetry• Add implied constraints• Customize solver
– Level of consistency– Variable, value ordering