Constraints Based Local Search - Department of...
Transcript of Constraints Based Local Search - Department of...
![Page 1: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/1.jpg)
Constraints-Based Local Search
Pascal Van Hentenryck Laurent MichelBrown University University of Connecticut
![Page 2: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/2.jpg)
2
OverviewIntroduction
Perspectives Basic example & Computation Models
PuzzlesSummaryLarger ApplicationImplementationConclusions
![Page 3: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/3.jpg)
3
Constraint ProgrammingCentral Idea
CP
Constraints Search+
![Page 4: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/4.jpg)
4
Constraint ProgrammingFirst key idea
Convey the combinatorial structureRich modeling language
Numerical ConstraintsCombinatorial ConstraintsConstraint Combinators
Logical and cardinality constraintsReification: constraint → variable
Vertical extensionsScheduling / Routing
![Page 5: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/5.jpg)
5
Constraint ProgrammingWhy such a rich modeling language?
ExpressivenessEfficiency
ExpressivenessEasily express complex/idiosyncratic constraintsMore natural and easier to read
EfficiencyExploit special structure in filtering algorithms
![Page 6: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/6.jpg)
6
Constraint ProgrammingSecond key idea
Specify the search procedureRich language for specifying search algorithms
Nondeterministic control structuresSpecifying the search tree
Search StrategiesHow to explore the tree
![Page 7: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/7.jpg)
7
Constraint ProgrammingKey observations: Independence
Can it be useful for another technology?Local search?Integer programming?
Constraint
Languages
Computation
Model
Search
Languages
![Page 8: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/8.jpg)
8
Local SearchNo communication at the model level
Rare to see the word constraint in papersNo modeling language
No coding at model levelNo compositionality, reuse, modularity
Efficiency is an issueImperative in natureIncrementality
![Page 9: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/9.jpg)
9
Local SearchLarge scale optimization
thousands of variablesOptimization under time constraints
online optimizationVarious classes optimization problems
complex schedulingvehicle routingfrequency allocation
![Page 10: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/10.jpg)
10
Comet (2001-)Constraint language for local search
Rich language for expressing problemsRich language for expressing search
Problem modelingDeclarative specification of the solutions
SearchHigh-level control structuresModularity and genericity
![Page 11: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/11.jpg)
11
Goals of the TalkConstraint-based language
For Local SearchComputation model
For Constraint-based Local SearchApplications
![Page 12: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/12.jpg)
12
Central Message
ConstraintsExpress structure
SearchExploit structure
LS = Constraints + SearchCP = Constraints + Search
![Page 13: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/13.jpg)
13
Overview Introduction
PerspectiveBasic example & Computation Models
PuzzlesSummaryLarger ApplicationImplementationConclusions
![Page 14: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/14.jpg)
14
Getting StartedProblem
8-Queens....Model
Decision variablesA row assignment for each column
ConstraintsProperties of the solution
SearchGoals
Illustrate modelingIllustrate search
First in CP....... Then in CB-LS
![Page 15: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/15.jpg)
15
Queens Model in CP
range R = 1..8;var R queen[R];int pos[k in R] = k;int neg[k in R] = -k;solve { allDifferent(queen); allDifferent(queen,neg); allDifferent(queen,pos);};
CombinatorialConstraints
Decision Variables
![Page 16: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/16.jpg)
16
Searching with CP
range R = 1..8;var R queen[R];solve { …};search { forall(i in R ordered by increasing dSize(queen[i])) tryall(v in R) queen[i] = v;};
Non deterministicchoice
Variable selection heuristic
![Page 17: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/17.jpg)
17
Queens Model in Comet
range R = 1..8;
UniformDistribution d(R);
LocalSolver m();var{int} queen[i in R](m) := d.get();ConstraintSystem S(m); S.post(alldifferent(queen)); S.post(alldifferent(all(k in R) queen[k]+k)); S.post(alldifferent(all(k in R) queen[k]-k));m.close();
Combinatorial constraints
Initial value
![Page 18: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/18.jpg)
18
Searching in LS
while (S.violationDegree())
selectMax(k in R)(S.getViolations(queen[k]))
selectMin(v in R)(S.getAssignDelta(queen[k],v))
queen[k] = v;
As long as system is violated
Choose most conflicting queen
Choose a row leading to largest violation decrease
![Page 19: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/19.jpg)
19
Queens Propagation in LS
![Page 20: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/20.jpg)
20
Queens Propagation in LS
![Page 21: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/21.jpg)
21
Queens Propagation in LS
![Page 22: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/22.jpg)
22
Queens Propagation in LS
![Page 23: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/23.jpg)
23
SummaryModeling
Identical for CP and LSSearch
Influenced by computational modelCP
Exploit pruningLS
Exploit violations and differentiability
![Page 24: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/24.jpg)
24
The CP ArchitectureThree Layers
Domain variablesConstraints
Logical / Numerical Combinatorial
SearchTreeStrategy
Computational modelConstraints ⇒ pruningSearch = Tree specification + Tree exploration
Tree spec.
Search
VariablesDomain
Constraints
Stra
tegie
s
c2
c3
c1
c4
c5
c6
![Page 25: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/25.jpg)
25
The LS ArchitectureThree Layers
Incremental variablesConstraints
Logical / Numerical Combinatorial
SearchGraph exploration: HeuristicsMeta-Heuristics
Computational modelConstraints ⇒ violations + differentiationSearch = Neighborhood + Heuristic + Meta
Closu
res Events
Selectors
Incremental
Di!erentiable Objects
Functions Constraints
![Page 26: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/26.jpg)
26
OverviewIntroduction
PerspectiveBasic example & Computation Models
PuzzlesSummaryLarger ApplicationImplementationConclusions
![Page 27: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/27.jpg)
27
Purpose of the sectionModeling
IllustrateNumerical constraintsLogical constraintsCombinatorial constraintsRedundant constraints
SearchIllustrate
Typical search procedures
![Page 28: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/28.jpg)
28
The PuzzlesSend More Money!Magic SeriesThe Zebra
![Page 29: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/29.jpg)
29
Send More Money!Problem statement
AssignDigitTo LettersSatisfy crypto-puzzle
Approaches ?Direct
S E N D+ M O R E M O N E Y
S*1000+E*100+N*10+D+ M*1000+O*100+R*10+E= M*10000+O*1000+N*100+E*10+Y
![Page 30: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/30.jpg)
30
Send More Money!Problem statement
AssignDigitTo LettersSatisfy crypto-puzzle
Approaches ?DirectCarry
S E N D+ M O R E M O N E Y
C4 C3 C2 C1
C1 + N + R = E + 10 * C2
![Page 31: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/31.jpg)
31
CP Model [Carry]
enum Letters = {S,E,N,D,M,O,R,Y}; range Digits = 0..9; Range Bin = 0..1;var Digits value[Letters]; var Bin r[1..4];solve { alldifferent(value); value[S] <> 0; value[M] <> 0; r[4] == value[M]; r[3] + value[S] + value[M] == value[O] + 10 * r[4]; r[2] + value[E] + value[O] == value[N] + 10 * r[3]; r[1] + value[N] + value[R] == value[E] + 10 * r[2]; value[D] + value[E] == value[Y] + 10 * r[1];};
![Page 32: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/32.jpg)
32
LS Model [Carry]
LocalSolver m(); enum Letters = {S,E,N,D,M,O,R,Y}; range Digits = 0..9; UniformDistribution distr(Digits); var{int} value[Letters](m,Digits) := distr.get(); var{int} r[1..4](m,0..1) := 1; ConstraintSystem Sys(m); Sys.post(alldifferent(value)); Sys.post( value[S] != 0); Sys.post( value[M] != 0); Sys.post(r[4] == value[M]); Sys.post(r[3] + value[S] + value[M] == value[O] + 10 * r[4]); Sys.post(r[2] + value[E] + value[O] == value[N] + 10 * r[3]); Sys.post(r[1] + value[N] + value[R] == value[E] + 10 * r[2]); Sys.post( value[D] + value[E] == value[Y] + 10 * r[1]);
![Page 33: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/33.jpg)
33
Magic SeriesObjective
ModelingMeta constraintsNumerical constraintsRedundant constraints
ApproachesCPLS
Impact of redundancies
![Page 34: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/34.jpg)
34
The ProblemFind a sequence of length n such that
Sk = Number of occurences of k in S
ExampleN = 10S = [6,2,1,0,0,0,1,0,0,0]
6 occurences of 02 occurences of 11 occurrence of 0…
![Page 35: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/35.jpg)
35
CP Model
int n = 50;range Size = 0..n-1;var Size magic[Size];forall(k in Size) exactly(magic[k],all(j in Size) magic[j] = k);
sum(k in Size) k * magic[k] = n;
magic[k] is #occurrence of k in magic
![Page 36: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/36.jpg)
36
LS Model
int n = 50;range Size = 0..n-1;LocalSolver m();
var{int} magic[Size](m,Size) := 0;ConstraintSystem S(m);forall(v in Size) S.post(exactly(magic[v],all(i in Size) magic[i] == v));
m.close();
# true expressions is magic[v]
![Page 37: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/37.jpg)
37
PerformanceObservation
The model worksBut it takes a long time
What is going on ?The exactly constraints provide little guidance for value selection
Solution Add a redundant constraintRedundant captures the importance of values
![Page 38: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/38.jpg)
38
Redundant Model
int n = 50;range Size = 0..n-1;LocalSolver m();
var{int} magic[Size](m,Size) := 0;ConstraintSystem S(m);forall(v in Size) S.post(exactly(magic[v],all(i in Size) magic[i] == v));S.post(sum(k in Size) k * magic[k] == n);
m.close();
Same redundant as in CP Model!
![Page 39: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/39.jpg)
39
Plots. No Redundant1 5 9
13
17
21
25
29
33
37
41
45
49
53
57
0
9
18
27
36
45
-50
-40
-30
-20
-10
0
10
20
30
40
50
60
50-60
40-50
30-40
20-30
10-20
0-10
-10-0
-20--10
-30--20
-40--30
-50--40
![Page 40: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/40.jpg)
40
Plots. With The Redundant.
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50-200-7060
190320450580710840970
1,100
TotalSR
Assign Delta Signals (for the 50 values)
![Page 41: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/41.jpg)
41
Who Owns The Zebra ?Objective
ModelingLogical constraint
SearchShow an non-trivial procedure
![Page 42: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/42.jpg)
42
Problem StatementAssign
People/Animals/Drinks/Color/JobsTo HousesSatisfy given constraints
E.g. “The Englishman in the red house”Question
Who owns the Zebra ?
![Page 43: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/43.jpg)
43
LS Model. The Variablesenum N = { England, Spain, Japan, Italy, Norway}; enum C = { green, red, yellow, blue, white}; enum P = { painter, diplomat, violinist, doctor, sculptor}; enum A = { dog, zebra, fox, snails, horse }; enum D = { juice, water, tea, coffee, milk };range R = 1..5;
LocalSolver m(); UniformDistribution distr(R); var{int} n[N](m,R) := distr.get(); var{int} c[C](m,R) := distr.get(); var{int} p[P](m,R) := distr.get(); var{int} a[A](m,R) := distr.get(); var{int} d[D](m,R) := distr.get();
![Page 44: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/44.jpg)
44
LS Model. The Constraints ConstraintSystem S(m); S.satisfy(n[England] == c[red]); S.satisfy(n[Spain] == a[dog]); S.satisfy(n[Japan] == p[painter]); S.satisfy(n[Italy] == d[tea]); S.satisfy(n[Norway] == 1); S.satisfy(d[milk] == 3); S.satisfy(p[violonist] == d[juice]); S.satisfy(c[green] == d[coffee]); S.satisfy(p[sculptor] == a[snails]); S.satisfy(p[diplomat] == c[yellow]); S.satisfy(c[green] == c[white] + 1); S.satisfy(abs(a[fox] - p[doctor]) == 1); S.satisfy(abs(a[horse] - p[diplomat]) == 1); S.satisfy(abs(n[Norway] - c[blue]) == 1); S.post(alldifferent(n));S.post(alldifferent(c)); S.post(alldifferent(p));S.post(alldifferent(a)); S.post(alldifferent(d));
0 or 1
Satisfaction Constraints
![Page 45: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/45.jpg)
45
LS Search IngredientsObjective
Minimize violations of relaxed constraintsConstraint selection
Most violated constraintVariable selection
Most violating variableValue selection
Value leading to largest decrease in violationsMeta-heuristics
Guide the heuristic to avoid local optima
![Page 46: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/46.jpg)
46
void function cdsSearch(ConstraintSystem S) { int it = 0; int tabu[S.getIdRange()] = -1; var{int}[] violation = S.getCstrViolations(); while (Sys.violations() > 0) { select(c in violation.rng(): violation[c] > 0) { Constraint cstr = S.getConstraint(c); var{int}[] x = cstr.getVariables(); selectMin(v in x.rng(),id=x[v].getId(),d in x[v].domain(): tabu[id]<=it && cstr.getAssignDelta(x[v],d) < 0) (S.getAssignDelta(x[v],d)) { x[v] := d; tabu[id] = it + 4; } it++; }}
Select a Violated Constraint
Constrained Directed Search
Select a variable next
![Page 47: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/47.jpg)
47
void function cdsSearch(ConstraintSystem S) { int it = 0; int tabu[S.getIdRange()] = -1; var{int}[] violation = S.getCstrViolations(); while (Sys.violations() > 0) { select(c in violation.rng(): violation[c] > 0) { Constraint cstr = S.getConstraint(c); var{int}[] x = cstr.getVariables(); selectMin(v in x.rng(),id=x[v].getId(),d in x[v].domain(): tabu[id]<=it && cstr.getAssignDelta(x[v],d) < 0) (S.getAssignDelta(x[v],d)) { x[v] := d; tabu[id] = it + 4; } it++; }}
Select a Violated Constraint
Constrained Directed Search
Select a variable next
Select a value in v’s Domain
![Page 48: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/48.jpg)
48
void function cdsSearch(ConstraintSystem S) { int it = 0; int tabu[S.getIdRange()] = -1; var{int}[] violation = S.getCstrViolations(); while (Sys.violations() > 0) { select(c in violation.rng(): violation[c] > 0) { Constraint cstr = S.getConstraint(c); var{int}[] x = cstr.getVariables(); selectMin(v in x.rng(),id=x[v].getId(),d in x[v].domain(): tabu[id]<=it && cstr.getAssignDelta(x[v],d) < 0) (S.getAssignDelta(x[v],d)) { x[v] := d; tabu[id] = it + 4; } it++; }}
Constrained Directed Search
The expression to minimize
![Page 49: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/49.jpg)
49
SummaryModeling = Constraint + Search
CPLS
Computational ModelCP
Exploit pruning to reduce spaceLSExploit violations to guide search
![Page 50: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/50.jpg)
50
OverviewIntroduction
PerspectiveBasic example & Computation Models
PuzzlesSummary
Larger ApplicationImplementationConclusions
![Page 51: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/51.jpg)
51
Car SequencingObjective
ModelingHigher-order constraintsRedundant constraints
ApproachesCPLS
![Page 52: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/52.jpg)
52
Car SequencingThe Problem
Place cars on an assembly line subject toSatisfy customers demand (orders)Respect workshop constraints
K out of N cars can be processed for option z
![Page 53: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/53.jpg)
53
Car Sequencing Solution
![Page 54: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/54.jpg)
54
A Small Instance
Options 1 2 3 4 5 DemandClass 1 ✓ ✓ ✓ 1Class 2 ✓ 1Class 3 ✓ ✓ 2Class 4 ✓ ✓ 2
Class 5 ✓ ✓ 2Class 6 ✓ ✓ 2
Capacity 1/2 2/3 1/3 2/5 1/5
![Page 55: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/55.jpg)
55
GlobalizingMotivation
There is an underlying modeling conceptIt arises in many applications
Time tablingSports scheduling
ImplicationExpress it directly
SolutionA Global constraint
Sequence Combines several elementary constraints
![Page 56: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/56.jpg)
56
Sequence SemanticsA constraint on a sequence of values
Examplesequence(var{int}[] S, set{int} values, int atMost, int length);
Sequence
Length = 4Atmost = 2Values = !3,5"
2 1 3 4
1 3 4 5
3 4 5 3
4 5 3 6
![Page 57: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/57.jpg)
57
CP Constraint
solve { forall(o in Options) sequence(slot,options[o],capacity[o].l,capacity[o].u);}
![Page 58: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/58.jpg)
58
LS Model. The Constraints
int cars[nbCars] = …;RandomPermutation p(Slots);forall(s in Slots) slot[s] := cars[p.get()];
ConstraintSystem S(m);forall(o in Options) S.post(sequence(slot,options[o],cap[o].lb,cap[o].ub));var{int} violations = S.violations();m.close();
![Page 59: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/59.jpg)
59
LS Model. The Search.
int itLimit = 2000000;Counter it(m,0);UniformDistribution d(1..10);int tabu[Slots,Slots] = -1;int best = violations;
while (violations > 0 && it < itLimit) { selectMax(s in Slots)(S.getViolations(slot[s])) { selectMin(v in Slots,nv = S.getSwapDelta(slot[s],slot[v]): slot[s] != slot[v] && (tabu[s,v] <= it || violations + nv < best))(nv) { slot[s] :=: slot[v]; tabu[s,v] = it + violations + d.get(); tabu[v,s] = tabu[s,v]; } } it++;}
Select Most Violating Slot
Select slot to swap with that - Yields largest violation decrease - Is non tabu or outstanding
Swap them!
![Page 60: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/60.jpg)
60
LS Model. Meta-HeuristicHow to introduce…
DiversificationPurpose: When no improvement for a while, perturb the assignment
RestartsPurpose: Starts !om scratch every x iterations.
Bottom lineTrack the best solution at all time.Code it independently from the heuristicUse Events
![Page 61: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/61.jpg)
61
EventsBenefits
Separation of concerns, reuse, modularitySeparate
Animations from the constraints and searchConstraints/Heuristics/Meta-heuristicsGUI from algorithms
Why?These components are independentThey are often presented separately
![Page 62: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/62.jpg)
62
Events AnatomyPublish
Event declarations inside a classSubscribe
Many “users” can subscribe to the same event“when”/“whenever” construct on objects
NotifyThe object implicitly notifies subscribersIt sends information along with the notificationSubscribers are executed upon notification
![Page 63: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/63.jpg)
63
Events and Closuresforall(q in R) { whenever queen[q]@changes(int o,int n) {
tabu.insert(q);when it@reaches[it+tlen]() tabu.remove(q);
}}
This yellow code is executed much later
TimeTabu tenure
![Page 64: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/64.jpg)
64
LS Model. Meta-HeuristicFirst step
Track the best solutionUse an Event!
Solution solution = new Solution(m);
whenever violations@changes(int o,int n) { if (n < best) { solution = new Solution(m); best = violations; }}
![Page 65: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/65.jpg)
65
LS Model. Meta-HeuristicSecond step
Track the stabilityDiversification when stable too long
whenever it@changes(int o,int n) { stable++; if (stable == stableLimit) { solution.restore(); forall(i in 1..3) select(c in Slots,v in Slots: slots[c] != slots[v]) slots[c] :=: slots[v]; best = violations; stable = 0; }}
![Page 66: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/66.jpg)
66
LS Model. Meta-HeuristicThird step
Restart every iterations. restartLimit = 10000;whenever it@changes(int o,int n) { if (n % restartLimit == 0) { RandomPermutation p(Slots); forall(c in Cars) slots[c] := cars[p.get()]; restartLimit = restartLimit * 2; best = violations; stable = 0; } }
2k! 10000
![Page 67: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/67.jpg)
67
OverviewIntroduction
PerspectiveBasic example & Computation Models
PuzzlesSummaryLarger ApplicationImplementation
Conclusions
![Page 68: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/68.jpg)
68
ImplementationThree layers architecture
Invariants Differentiable objectsControl
Closu
res Events
Selectors
Incremental
Di!erentiable Objects
Functions Constraints
![Page 69: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/69.jpg)
69
InvariantsPurpose
SpecifyWhat must be maintained incrementally
AutomateHow to maintain it
ComposeMultiple invariants and their incremental code
Example
LocalSolver m();inc{int} x[i in 1..10](m) := i;
inc{int} y <- sum(i in 1..10) x[i];
![Page 70: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/70.jpg)
70
Invariants VocabularyRich modeling
Numerical invariants
Set-based invariants
Combinatorial invariants
inc{int} loss[w in W] <- - sum(s in S[w]) (d[s] - b[s]) ;
inc{set{int}} S[w in W] <- setof(s in S) (cost[w,s] = b[s]) ;
inc{set{int}} S[] = count(x);
Sj = |{k ! D(x)|x[k] = j}|
![Page 71: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/71.jpg)
71
Differentiable ObjectsKinds
ConstraintsObjective functions
PurposeCapture properties of the solutionAnswer differential queries
E.g....
“What is the impact of assigning variable x to value k ?”
![Page 72: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/72.jpg)
72
Which Properties?Properties of interest
Truth valueViolation degreeContributions of a variable to overall violation...
Differential QueriesVariation of violation degree (or objective value) as a result of...
Single assignmentMultiple assignmentsSwaps....
![Page 73: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/73.jpg)
73
Constraint/Objective API
interface Constraint { inc{int}[] getVariables();
inc{int} true(); inc{int} violationDegree(); inc{int} violations(inc{int} var); … int getAssignDelta(inc{int} x,int v); int getSwapDelta(inc{int} x,inc{int} y);
int getAssignDelta(inc{int}[] x,int[] v); }
interface Objective { inc{int}[] getVariables(); inc{int} value(); inc{int} cost(); inc{int} getCost(inc{int} var); … int getAssignDelta(inc{int} x,int v); int getSwapDelta(inc{int} x,inc{int} y); int getAssignDelta(inc{int}[] x,int[] v);}
API Completely open. Constraints/Objective can be implemented in C++ / Comet
![Page 74: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/74.jpg)
74
ExampleImplementing an alldifferent!Properties
Value cardinality - Value violationVariable violationViolation DegreeTruth
![Page 75: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/75.jpg)
75
Cardinality [⇢value violation]
Variable violation
Total violation degree
Truth
Alldifferent Properties
v!(allDiff) =!
i!D
max(c![i] ! 1, 0)
v!(allDiff, x) = max(c![!(x)] ! 1, 0)
c![j] = |{k ! D(x)|!(x[k]) = j}| " c = count(x)
v!(allDiff) == 0All maintained
with
Invariants
![Page 76: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/76.jpg)
76
Alldifferent Differential APIFocus on
c.getAssignDelta(x,v)
!(x := v) =
!
0 if !(x) = v
(c![v] ! 1) " (c![!(x)] ! 2) otherwise
New violationsintroduced on v
Old violationscaused by x
![Page 77: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/77.jpg)
77
OverviewIntroduction
PerspectiveBasic example & Computation Models
PuzzlesSummaryLarger ApplicationImplementationConclusions
![Page 78: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/78.jpg)
78
ConclusionsKey ideas in constraint languages
Applications = Constraints + SearchConstraints
Make structure explicitSearch
Exploit structure Technology independent
Constraint programming and local search
![Page 79: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/79.jpg)
79
ConclusionsConstraints
NumericalCombinatorialConstraint combinators: Logical, cardinality
Different usesPruning in constraint programmingViolations and differentiation in local search
Modeling techniquesRedundancy: useful in both for different reasonsSymmetries: useful in CP, detrimental in LS?
![Page 80: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/80.jpg)
80
ConclusionsSearch
Independent from modelGenericity
Different computation modelsBranching in constraint programmingNeighborhood exploration/selection in LS
CommonalitiesExploit the model properties (generically)High-level abstractionsSignificant reduction in programming effort
![Page 81: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/81.jpg)
81
CP and LS contrasted
Issue CP LS
VariablesConstraints
Logical / DomainLogical
NumericCombinatorial
IncrementalLogical
NumericCombinatorial
Search TreeNon-deterministic
Strategies
GraphRandomized
Meta-HeuristicsArchitectureConstraints
Search
3 LayersPruning
Choices & Backtrack
3 LayersDifferentiability
Closure & Inverse
![Page 82: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/82.jpg)
82
Questions…
Questions... ?
![Page 83: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/83.jpg)
83
EXTRA MATERIAL
![Page 84: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/84.jpg)
84
Scheduling Vertical ExtensionTake Home Message
Very successful in CPVery natural and effective in LS tooSimilar declarative modelsThe core differences
The searchThe scope
CP optimality proof. “Small” instances
LSno optimality proof. “Large” instances
![Page 85: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/85.jpg)
85
CP-based modeling ActivitiesResources
UnaryCumulative
Precedence
![Page 86: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/86.jpg)
86
Job1
Jobshop Example
ts
Machinek
![Page 87: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/87.jpg)
87
Jobshop ExampleA machine handle activities in sequence
Find a activity ordering on each machine
tt
![Page 88: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/88.jpg)
88
Jobshop ExampleSolution =
A Directed acyclic precedence graph
tt
![Page 89: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/89.jpg)
89
Jobshop ExamplePossible Objectives
Minimize makespanLength of longest path s ⇢ t
Minimize weighted tardinessLateness of tasks
Minimize total tardinessSum of all tasks lateness
![Page 90: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/90.jpg)
90
Cumulativeint demand[Tasks] = …;ScheduleHorizon = totalDuration;Activity task[j in Jobs,t in Tasks](duration[j,t]);Activity makespan(0);DiscreteResource tool(cap);
minimize makespan.endsubject to { forall(j in Jobs) task[j,nbTasks] precedes makespan;
forall(j in Jobs,t in 1..nbTasks-1) task[j,t] precedes task[j,t+1];
forall(j in Jobs, t in Tasks) task[j,t] requires(demand[t]) tool;}
![Page 91: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/91.jpg)
91
ObjectivesImplement a common interface
interface Objective { inc{int}[] getVariables(); inc{int} value(); inc{int} cost(); inc{int} getCost(inc{int} var); … int getAssignDelta(inc{int} x,int v); int getSwapDelta(inc{int} x,inc{int} y); int getAssignDelta(inc{int}[] x,int[] v);}
![Page 92: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/92.jpg)
92
Scheduling ObjectivePurpose
Provide additional servicesProvide domain specific servicesProvide services hard to encode in low level terms
interface ScheduleObjective { … int evalMoveBackwardDelta(…); int evalMoveForwardDelta(…); int evalInsert(Activity,DisjunctiveResource);
int estimateMoveBackwardDelta(…);}
![Page 93: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/93.jpg)
93
Using ObjectivesIdea
Exploit differential API of objectiveExploit objective compositionality
tardiness.evalMoveBackwardDelta(a);
![Page 94: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/94.jpg)
94
Scheduling ObjectivesScheduling supports several objectives
MakespanTardiness
Objectives compose!Tardiness tard[j in Job](sched,job[j].getLast(),dueDate[j]);ScheduleObjectiveSum totalTard(sched);forall(k in Jobs) totalTard.add(tard[k]);
Makespan mks(sched); // A makespan objectiveTardiness tard(sched,a,dueDate); // a tardiness objective
![Page 95: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/95.jpg)
95
LS Model. [Jobshop]
LocalSolver m();Schedule sched = new DisjunctiveSchedule(m);
Job job[Jobs];Activity act[j in Jobs,t in Tasks](sched,duration[j,t]);DisjunctiveResource tool(sched);Objective obj = new Makespan(sched);
forall(j in Jobs,t in Tasks) act[j,t].requires(tool[res[j,t]]);
forall(j in Jobs,t in 1..nbTasks-1) act[j,t].precedes(act[j,t+1]);
m.close();
Create Precedence Graph
Create Job SequencesCreate the ActivitiesDeclare objective function
![Page 96: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/96.jpg)
96
LS SearchOverall strategy
Create an initial solutionUse a constructive heuristicLittle efforts towards optimizationBuild a satisfiable solution
Conduct an iterative improvementPerform a local changeGear towards better value of Objective
What is Difficult ?
![Page 97: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/97.jpg)
97
LS SearchDifficulty
Iterative improvement schemeIn practice
Union of several neighborhood functionsTemporal separation of
Neighborhood explorationFrom neighbor selectionFrom actual transition
![Page 98: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/98.jpg)
98
Tool-less solutionTypical solution
Create classes for each move (with a common interface)
Create instances during the scanning phase to selectExtract the selection and execute it
DrawbacksHeavy machinery (hence not generally done)Code fragmentation between
EvaluationExecution
![Page 99: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/99.jpg)
99
LS Search ExampleLocal Search for jobshop scheduling
high-quality solutions quicklychoosing machine sequences
Dell’Amico & Trubian, 1993fastcomplex neighborhood (RNA + NB)5,000 lines of C++About 6 months to reproduce the results
![Page 100: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/100.jpg)
100
Neighborhood NASwapping vertices on a critical path
![Page 101: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/101.jpg)
101
Neighborhood NBMoving tasks in before or after a critical block
![Page 102: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/102.jpg)
102
Neighborhood Exploration
void exploreNeighborhood(NeighborSelector N){ exploreNA(N); exploreNB(N);}void exploreNA(NeighborSelector N) { forall(v in Critical) {
int delta = obj.moveBackwardDelta(v);if (acceptNA(v,delta)) neighbor(delta,N)
sched.moveBackward(v); }}
![Page 103: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/103.jpg)
103
Neighborhood Exploration
void exploreNB(NeighborSelector N) { forall(v in Critical) {
int lm = sched.getLeftMostFeasible(v);while (lm > 1) { int delta = obj.moveBackwardDelta(v,lm); if (acceptNB(v,lm,delta)) { neighbor(delta,N)
sched.moveBackward(v,m);break;
} lm--;}
}
the yellow code is a closure created on demand
![Page 104: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/104.jpg)
104
Neighbor SelectionNeighborhood exploration
Define what to exploreNot how to use to the neighborhood
Neighbor selectionSpecify how to use the neighborhoodSelect the best neighborSelect a k-best neighbor (semi-greedy algorithm)Select all the neighbors (Nowicki & al)
![Page 105: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/105.jpg)
105
Neighbor TransitionNeighborhood exploration
What to considerNeighbor selection
How to useNeighbor transition
How to move
void executeMove() { MinNeighborSelector sel(); exploreNeighborhood(sel); if (sel.hasMove()) call(sel.getMove());}
neighbor(delta,N) sched.moveBackward(v,m);
![Page 106: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/106.jpg)
106
Jobshop Scheduling with LS ?Ease of use
Avoid the heavy class machinery (200 lines)Readability and separation of concern
Allow to keep the code in one placeseparate the neighborhood from its use
ExtensibilitySmooth integration of other neighborhoods
Efficiency?comparable to specific implementations
![Page 107: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/107.jpg)
107
Experimental Results
abz5 abz6 abz7 abz8 abz9 mt10DT* 6.2 3.8 14.2 15.1 14.2 6.9KS* 4.6 4.8 12.2 13.6 11.9 5.1CO 5.9 5.7 11.7 9.9 9 6.7
![Page 108: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/108.jpg)
108
Cumulative Scheduling in LSOf course!
Modeling frontNew object:
CumulativeResourceSearch front
Different procedureiFlat-iRelax [ICAPS’04]
StrengthBest algorithm for large cumulative problems.
![Page 109: Constraints Based Local Search - Department of …kti.mff.cuni.cz/~bartak/cpaior05/downloads/michel.pdfConstraints-Based Local Search ... 43 LS Model. The Variables enum N = { England,](https://reader036.fdocuments.net/reader036/viewer/2022070607/5aabd7d07f8b9a8d678c504f/html5/thumbnails/109.jpg)
109
Experimental ResultsSet A Set B Set MT
Relax Best Avg Best Avg Best Avg1 2.2 7.86 2.7 7.47 7.15 13.032 0.21 2 -0.33 1.86 2.01 6.074 -0.01 1.07 -1.17 0.47 0.37 3.416 -0.13 0.78 -1.23 -0.04 0.84 2.88
B(A) A(A) B(B) A(B) B(MT) A(MT)-3.8
0
3.8
7.5
11.3
15.0
1246