Title: Modelling
1Modelling Solving with Constraints
- Prof. Toby Walsh
- University College Cork/Uppsala University
2Overview
- Introduction to constraint programming
- Constraint propagation
- Backtracking search
- Modelling case studies
- Simple recipe
- Solving with constraints
- Global constraints
- Set variables
- Branching heuristics
3Resources
- 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,
4Constraint programming
- Dream of declarative programming
- State the constraints
- Solver finds a solution
- Method of choice for many hard combinatorial
problems - Scheduling, assignment, routing,
5Constraints are everywhere!
- No meetings before 10am
- Network traffic lt 100 Gbytes/sec
- PCB width lt 21cm
- Salary gt 45k Euros
6Constraint satisfaction
- Constraint satisfaction problem (CSP) is a triple
ltV,D,Cgt 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
7Example CSP
- Course timetabling
- Variable for each course
- CS101, OS102 ..
- Domain are possible times
- wed9am, fri10am, ..
- Constraints
- CS101 \ wed9am
- Capacity constraints atmost(3,OS102,DB103..,wed
9am) - Lecturer constraints alldifferent(CS101,DB103,
)
8Constraint 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 gt 0, Profit gt Ans1, Profit gt Ans2,
9Constraint 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,
10Constraints
- Constraints are tuples ltS,Rgt 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
11Constraints
- Extensional specification
- List of goods (or for tight constraints, nogoods)
- Intensional specification
- X1 / X2
- 5X1 6X2 lt X3
- alldifferent(X1,X2,X3,X4),
12Binary v non-binary
- Binary constraint
- Scope covers 2 variables
- E.g. not-equals constraint X1 / X2.
- E.g. ordering constraint X1 lt 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!
13Constraint graph
- Nodes variables
- Edge between 2 nodes iff constraint between 2
associated variables - Few constraints, sparse constraint graph
- Lots of constraints, dense constraint graph
14Some non-binary examples
- Timetabling
- Variables Lecture1, Lecture2,
- Values time1, time2,
- Constraint that lectures taught by same lecturer
do not conflict - alldifferent(Lecture1,Lecture5,).
15Some 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).
16Why 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 theyre not needed
- But in practice, they are!
17Modelling with non-binary constraints
- Benefits include
- Compact, declarative specifications
- (discussed next)
- Efficient constraint propagation
- (discussed second)
18Modelling with non-binary constraints
- Consider writing your own alldifferent
constraint - alldifferent().
- alldifferent(HeadTail)-
- onediff(Head,Tail),
- alldifferent(Tail).
-
- onediff(El,).
- onediff(El,HeadTail)-
- El \ Head,
- onediff(El,Tail).
19Modelling with non-binary constraints
- Its possible but its 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(n2) binary
constraints? - And there exist very efficient algorithms
for reasoning efficiently with many specialized
non-binary constraints
20Constraint solvers
- Two main approaches
- Systematic, tree search algorithms
- Local search or repair based procedures
- Other more exotic possibilities
- Hybrid algorithms
- Quantum algorithms
21Systematic 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,
22Local 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
23Constraint 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
24Enforcing arc-consistency
- X2 \ X3 is AC
- X1 \ X2 is not AC
- X21 has no support so can this value can be
pruned - X2 \ X3 is now not AC
- No support for X32
- This value can also be pruned
- Problem is now AC
1
X1
\
1,2
2,3
\
X3
X2
25Enforcing 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(ed2)
- Optimal if we know nothing else about the
constraints
26Properties 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
27Non-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
28GAC on alldifferent
- alldifferent(X1,X2,X3)
- Constraint is not GAC
- X12 cannot be extended
- X2 would have to be 3
- No value left then for X3
- X11 is GAC
X1
2,3
2,3
X2
X3
29Enforcing GAC
- Enforcing GAC is expensive in general
- GAC schema is O(dk)
- On k-ary constraint on vars with domains of size
d - Trick is to exploit semantics of constraints
- Regins all-different algorithm
- Achieves GAC in just O(k3/2 d)
- On k-ary all different constraint with domains of
size d - Based on finding matching in value graph
30Other 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
31(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
32Enforcing (i,j)-consistency
- problem is (1,1)-consistent (AC)
- BUT is not (2,1)-consistent (PC)
- X12, X23 cannot be extended to X3
- Need to add constraints
- not(X12 X23)
- not(X12 X33)
- Nor is it (1,2)-consistent (PIC)
- X12 cannot be extended to X2 X3 (so needs to
be deleted)
1,2
X1
\
\
2,3
2,3
\
X3
X2
33Other 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 -
34Comparing local consistencies
- Formal definition of tightness introduced by
Debruyne Bessiere IJCAI-97 - A-consistency is tighter than B-consistency iff
- If a problem is A-consistent -gt it is
B-consistent -
- We write A gt B
35Properties
- Partial ordering
- reflexive A ? A
- transitive A ? B B ? C implies A ? C
- Defined relations
- tighter A gt B iff A ? B not B
? A - incomparable A _at_ B iff neither A ? B
-
nor B ? A
36Comparison of consistency techniques
- Exercise for the reader, prove the following
identities! - Strong PC gt SAC gt RPC gt AC
- NB gaps can reduce search exponentially!
37Which 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!
38Why 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
39Maintaining 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)
40Modelling case study all interval series
- Results due to Simonis, Puget Regin
41All 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
42All 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
43All interval series
- Can generalize to any n (not just 12)
- Find Sn, a permutation of 0,n)
- such that Sn1-Sn are all distinct
- Finding one solution is easy
44All interval series
- Can generalize to any n (not just 12)
- Find Sn, a permutation of 0,n) such that
Sn1-Sn are all distinct - Finding one solution is easy
- n,1,n-1,2,n-2,.., floor(n/2)2,floor(n/2)-1,flo
or(n/2)1,floor(n/2) - Giving the differences n-1,n-2,..,2,1
- Challenge is to find all solutions!
45Basic 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
46Basic CSP model
47Basic CSP model
- What are the variables?
- Si j if the ith note is j
- What are the constraints?
48Basic 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 ilti Si1 - Si / Si1 - Si
49Basic 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
50Improving basic model
- Introduce auxiliary variables?
- Are there any loose or messy constraints we could
better (more compactly?) express via some
auxiliary variables?
51Improving basic model
- Introduce auxiliary variables?
- Yes, variables for the pairwise differences
- Di Si1 - Si
- Now post single large all-different constraint
- Di in 1,n-1
- All-different(D1,D2,Dn-1)
52Basic 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
53Break symmetry
- Does the problem have any symmetry?
54Break 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?
55Break 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?
- Order first and last difference
- D1 lt Dn-1
56Break symmetry
- Does the problem have any other symmetry?
57Break symmetry
- Does the problem have any other symmetry?
- Yes, we can invert the numbers in any sequence
- 0, n-1, 1, n-2, map x onto n-1-x
- n-1, 0, n-2, 1,
- How do we eliminate this symmetry?
58Break symmetry
- Does the problem have any other symmetry?
- Yes, we can invert the numbers in any sequence
- 0, n-1, 1, n-2, map x onto n-1-x
- n-1, 0, n-2, 1,
- How do we eliminate this symmetry?
- S1 lt S2
59Performance
- Basic model is poor
- Improved model able to compute all solutions up
to n14 or so - GAC on all-different constraints very beneficial
- As is enforcing GAC on Di Si1-Si
- This becomes too expensive for large n
- So use just bounds consistency (BC) for larger n
60Modelling case study Langfords problem
- Model due to Barbara Smith
61Outline
- Introduction
- Langfords problem
- Modelling it as a CSP
- Basic model
- Refined model
- Experimental Results
- Conclusions
62Recipe
- 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
63Langfords problem
- Prob024 _at_ 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
64Langfords problem
- L(k,n) problem
- To find a sequence of kn 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)
65Langfords 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 0ltnlt8, 10ltnlt17, 20, ..
- Solutions 9,10,17,18,19, ..
- A014552
- Sequence 0,0,1,1,0,0,26,150,0,0,17792,108144,0,
0,39809640,326721800, - 0,0,256814891280,2636337861200
66Basic model
67Basic model
- What are the variables?
- Variable for each occurrence of a number
- X11 is 1st occurrence of 1
- X21 is 1st occurrence of 2
- ..
- X12 is 2nd occurrence of 1
- X22 is 2nd occurrence of 2
- ..
- Value is position in the sequence
68Basic model
- What are the constraints?
- Xij in 1,nk
- Xij1 iXij
- Alldifferent(X11,..Xn1,X12,..Xn2,..,X1k,..Xnk)
69Recipe
- 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
70Break symmetry
- Does the problem have any symmetry?
71Break symmetry
- Does the problem have any symmetry?
- Of course, we can invert any sequence!
72Break symmetry
- How do we break this symmetry?
73Break symmetry
- How do we break this symmetry?
- Many possible ways
- For example, for L(3,9)
- Either X92 lt 14 (2nd occurrence of 9 is in 1st
half) - Or X9214 and X82lt14 (2nd occurrence of 8 is in
1st half)
74Recipe
- 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
75What about dual model?
76What about dual model?
- Can we take a dual view?
- Of course we can, its a permutation!
77Dual model
- What are the variables?
- Variable for each position i
- What are the values?
78Dual 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
79Dual model
- What are the variables?
- Variable for each position i
- What are the values?
- Solution 1 use values from 1,nk with the
value inj standing for the ith occurrence of j - Now want to find a permutation of these numbers
subject to the distance constraint
80Dual 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
81Global 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)
- Regins algorithm enforces GAC on Gcc in O(n2.d)
82Dual model
- What are the constraints?
- Gcc(D1,Dkn,k,k)
- Distance constraints?
83Dual model
- What are the constraints?
- Gcc(D1,Dkn,k,k)
- Distance constraints
- Dij then Dij1j
84Combined model
- Primal and dual variables
- Channelling to link them
- What do the channelling constraints look like?
85Combined model
- Primal and dual variables
- Channelling to link them
- Xijk implies Dki
86Solving choices?
- Which variables to assign?
- Xij or Di
87Solving choices?
- Which variables to assign?
- Xij or Di, doesnt seem to matter
- Which variable ordering heuristic?
- Fail First or Lex?
88Solving choices?
- Which variables to assign?
- Xij or Di, doesnt 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
89Solving choices?
- Which variables to assign?
- Xij or Di, doesnt 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
90Global constraints
91Non-exhaustive catalog
- Order constraints
- Constraints on values
- Partitioning constraints
- Timetabling constraints
- Graph constraints
- Scheduling constraints
- Bin-packing constraints
92Global constraints
- It isnt just all-different!
- Many constraints specialized to application
domains - Scheduling
- Packing
- ..
93Order constraints
- min(X,Y1,..,Yn) and max(X,Y1,..Yn)
- X lt minimum(Y1,..,Yn)
- X gt maximum(Y1,..Yn)
-
94Order constraints
- min_n(X,n,Y1,..Ym) and max_n(X,n,Y1,..,Ym)
- X is nth smallest value in Y1,..Ym
- X is nth largest value in Y1,..Ym
-
95Value constraints
- among(N,Y1,..,Yn,val1,..,valm)
- N vars in Y1,..,Yn take values val1,..valm
- e.g. among(2,1,2,1,3,1,5,3,4,5)
96Value constraints
- among(N,Y1,..,Yn,val1,..,valm)
- N vars in Y1,..,Yn take values val1,..valm
- e.g. among(2,1,2,1,3,1,5,3,4,5)
- count(n,Y1,..,Ym,op,X) where op is ,lt,gt,/,lt
or gt - relation Yi op X holds n times
- among(n,Y1,..,Ym,k)
- count(n,Y1,..,Ym,,k)
97Value 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)
-
98Value 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) gt balance(0,Y1,..,Yn
)
99Value constraints
- min_nvalue(N,Y1,..,Yn) and max_nvalue(N,Y1,..,Y
n) - least (most) common value in Y1,..,Yn occurs N
times - E.g. min_nvalue(2,1,1,2,2,2,3,3,5,5)
- Can replace multiple count or among constraints
100Value 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)
-
-
101Value 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)
-
- among(X,Y1,..,Yn,val1,..,valm)
common(X,Y,X1,..,Yn,val1,..,valm)
102Value constraints
- same(X1,..,Xn,Y1,..,Yn)
- Yi is a permutation of Xi
103Value 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 Xi
- mgtm
104Value 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 Xi
- mgtm
- on n values
- alldifferent(X1,..,Xn)same(X1,..,Xn,1,..,n
) -
used_by(X1,..,Xn,1,..,n)
105Partitioning constraints
106Partitioning constraints
- all-different(X1,..,Xn)
- Other flavours
- all-different_except_0(X1,..,Xn)
- Xi/Xj unless XiXj0
- 0 is often used for modelling purposes as dummy
value - Dont use this slab
- Dont open this bin ..
107Partitioning constraints
- all-different(X1,..,Xn)
- Other flavours
- symmetric-all-different(X1,..,Xn)
- Xi/Xj and Xij iff Xji
- Very common in practice
- Team i plays j iff Team j plays i..
108Partitioning constraints
- nvalue(N,X1,..,Xn)
- Xi takes N different values
- all-different(X1,..,Xn) nvalue(n,X1,..,Xn)
109Partitioning constraints
- nvalue(N,X1,..,Xn)
- Xi takes N different values
- all-different(X1,..,Xn) nvalue(n,X1,..,Xn)
- gcc(X1,..,Xn,Lo,Hi)
- values in Xi occur between Lo and Hi times
- all-different(X1,..,Xn)gcc(X1,..,Xn,1,1)
110Timetabling constraints
- change(N,X1,..,Xn),op) where op is
,lt,gt,lt,gt,/ - Xi op Xi1 holds N times
- E.g. change(3,4,4,3,4,1,/)
- You may wish to limit the number of changes of
classroom, shifts,
111Timetabling constraints
- longest_changes(N,X1,..,Xn),op) where op is
,lt,gt,lt,gt,/ - longest sequence Xi op Xi1 is of length N
- E.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,
112Graph constraints
- Tours in graph a often represented by the
successors - X1,..,Xn means from node i we go to node Xi
113Graph 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)-gt(2)-gt(1) and (3)-gt(5)-gt(4)-gt(3)
114Graph 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)-gt(2)-gt(1) and (3)-gt(5)-gt(4)-gt(3)
- Useful for TSP like problems (e.g. sending
engineers out to repair phones)
115Scheduling 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
- EiSiDi
- 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
116Scheduling 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
117Scheduling constraints
- cycle_cummulative(m,S1,..,Sn,D1,..,Dn,E1,..,E
n,H1,..,Hn,L) - schedules n (concurrent) jobs, each with a height
Hi onto a cyclic schedule of length m
118Scheduling 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
lt Li
119Scheduling constraints
- cummulatives(M1,..Mn,S1,..,Sn,D1,..,Dn,E1,.
.,En,H1,..,Hn,L1,..,Lm)
Machine 1
Machine 2
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
120Scheduling 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
lt Li
121Bin-packing constraints
- bin_packing(capacity,B1,..,Bn,w1,..,wn)
- for each bin j, sum_Bij wi lt capacity
-
122Bin-packing constraints
- bin_packing(capacity,B1,..,Bn,w1,..,wn)
- for each bin j, sum_Bij wi lt capacity
- special case of cummulative with task durations1
123Misc constraints
- element(Index,a1,..,an,Var)
- Vara_Index
- constraint programmings answer to arrays!
- e.g. element(Item,10,23,12,15,Cost)
124Modelling set variables
125Motivation
- Sets are useful when
- We dont 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 dont want to
consider all their permutations - And in many other situations!
126Outline
- Representing set variables
- Bounds
- Characteristic functions
- Constraining set variables
- Primitive constraints
- Global constraints
127Set variables
- Representing sets
- Domain of values powerset
- Exponential space would be needed to represent
this extensional
128Set 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
129Set 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
130Alternative representation
- Characteristic function
- i in X iff Xi1
131Alternative representation
- Characteristic function
- i in X iff Xi1
- E.g. 1 subseteq X subseteq 1,2,3
132Alternative representation
- Characteristic function
- i in X iff Xi1
- E.g. 1 subseteq X subseteq 1,2,3
- X11
- X2 in 0,1, X3 in 0,1
- X4X5..0
133Primitive constraints
- X subset Y
- X subseteq Y
- a in X
- X Y intersect Z
- X Y union Z
- X Y - Z
- X
134Bounds 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
135Bounds consistency
- Lub(A union B) gt Lub(A) union Lub(B)
- Glb(A union B) gt Glb(A) union Glb(B)
136Bounds consistency
- Lub(A union B) gt Lub(A) union Lub(B)
- Glb(A union B) gt Glb(A) union Glb(B)
- This last rule is a safe approximation
- Glb(A union B) superseteq Glb(A) union Glb(B)
137Bounds consistency
- Lub(A union B) gt Lub(A) union Lub(B)
- Glb(A union B) gt Glb(A) union Glb(B)
- Lub(A intersect B) gt Lub(A) intersect Lub(B)
- Glb(A intersect B) gt Glb(A) intersect Glb(B)
138Bounds consistency
- Lub(A union B) gt Lub(A) union Lub(B)
- Glb(A union B) gt Glb(A) union Glb(B)
- Lub(A intersect B) gt Lub(A) intersect Lub(B)
- Glb(A intersect B) gt Glb(A) intersect Glb(B)
- The third rule is a safe approximation
- Lub(A intersect B) subseteq
- Lub(A)
intersect Lub(B)
139Bounds consistency
- Lub(A union B) gt Lub(A) union Lub(B)
- Glb(A union B) gt Glb(A) union Glb(B)
- Lub(A intersect B) gt Lub(A) intersect Lub(B)
- Glb(A intersect B) gt Glb(A) intersect Glb(B)
- A subseteq B gt Lub(A) subseteq Lub(B),
- Glb(A) subseteq
Glb(B)
140Bounds consistency
- Lub(A union B) gt Lub(A) union Lub(B)
- Glb(A union B) gt Glb(A) union Glb(B)
- Lub(A intersect B) gt Lub(A) intersect Lub(B)
- Glb(A intersect B) gt Glb(A) intersect Glb(B)
- A subseteq B gt Lub(A) subseteq Lub(B),
- Glb(A) subseteq
Glb(B) - A B gt A subseteq B, B subseteq A
-
141Bounds consistency
- Apply these rules exhaustively
- This computes safe approximations
- Lubs are correct or too large
- Glbs 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
142Intervals v Characteristic functions
- It doesnt really matter!
- Theorem
- A set of constraints in normal form is BC iff the
characteristic function representation is AC
143Intervals v Characteristic functions
- It doesnt really matter!
- Theorem
- A 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!
144Global constraints
- All-different constraint
- No two vars take same value
- Permutation constraint
- Special case of all-different
- All values are used
145Global constraints
- All-different constraint
- No two vars take same value
- Disjoint constraint
- No two set variables intersect
146Global 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
147Global 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
148Global constraints
- Disjoint(X1,..,Xn) decomposes into
- Xi intersect Xj
- Just like the all-different constraint!
149Global constraints
- Disjoint(X1,..,Xn) decomposes into
- Xi intersect Xj
- Just like the all-different constraint!
- But decomposition does not hurt!
150Global 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
151Global constraints
- Partition(X1,..,Xn,S) decomposes into
- Xi intesect Xj
- X1 union X2Y1
- X3 union Y1 Y2
-
- Xn union Yn-2 S
152Global constraints
- Partition(X1,..,Xn,S) decomposes into
- Xi intesect Xj
- X1 union X2Y1
- X3 union Y1 Y2
-
- Xn union Yn-2 S
- Decomposition does not hurt!
153Global constraints
- Partition(X1,..,Xn,S) decomposes
- Decomposition again does not hurt!
- Theorem
- BC on partition(X1,..,Xn,S)
- BC on the decomposed model
154Global constraints
- Non-empty-partition(X1,..,Xn,S)
- Decomposes as before
- With additional constraint
- Xi gt 0
155Global constraints
- Non-empty-partition(X1,..,Xn,S)
- Decomposition now hurts!
156Global constraints
- Non-empty-partition(X1,..,Xn,S)
- Decomposition now hurts!
- Theorem
- BC on non-empty-partition(X1,..,Xn,S) is
strictly stronger than BC on decompostion
157Modelling 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
158Modelling with set constraints
- Ternary Steiner problem
- n(n-1)/6 sets, Si
- Each a subset of 1,..,n
- Si 3
- Si intersect Sj lt1
159Ternary 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,gt1.1109 Colbourn Dinitz 1996
- AO30139
160Ternary Steiner problem
- Simple and elegant set variable model
- Let tn(n-1)/6
- For all j in 1,t . Sj subset 1,..,n and
Sj3 - Atmost1(S1,..,St)
161Ternary Steiner problem
- Simple and elegant set variable model
- Let tn(n-1)/6
- For all j in 1,t . Sj subset 1,..,n and
Sj3 - Atmost1(S1,..,St)
- For all jltk in 1,t . Sj intersect Sk lt1
- Whats wrong with this model?
162Ternary Steiner problem
- Simple and elegant set variable model
- Let tn(n-1)/6
- For all j in 1,t . Sj subset 1,..,n and
Sj3 - Atmost1(S1,..,St)
- Whats wrong with this model?
- Numbers and Si are still symmetric.
- How do we deal with this?
163Ternary Steiner problem
- Breaking symmetry
- Make some initial assignments
- S11,2,3, S22,4,5,
- Until all numbers named once
164Ternary Steiner problem
- Breaking symmetry
- Order sets S1ltS2lt..ltSt
- e.g. multiset ordering
165Conclusions
- 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
166Recipe
- 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
167Solving choices
- Level of consistency
- Binary v non-binary constraints
- GAC, BC
168Solving choices
- Branching heuristics
- Variable ordering (fail first)
- Smallest domain, max degree,
- Value ordering (succed first)
- Max promise,
169Recipe
- 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