IBM ILOG CP Optimizer
CP-AI-OR 2009 Masterclass
28/05/2009
Paul ShawConstraint Programming Group
28/05/2009 © ILOG, All rights reserved 2
What is CP Optimizer?
A Constraint Programming engine with an emphasis on modelling and automatic search
General feeling that CP toolkits were becoming too complicated, and the audience more limited
Models quickly became very hard to maintain
Simplify learning and use of the productIncrease model development speedQuickly evaluate CP technology on the problemYou can still program the search in the native engine
language (C++) if you wish
28/05/2009 © ILOG, All rights reserved 3
What kinds of problems?
CP Optimizer has a large emphasis on scheduling problems
However, we will not have time to cover interval-based modelling today
Look at examples beginning with “sched_”
Also addresses more traditional combinatorial problems
What we will do today
28/05/2009 © ILOG, All rights reserved 4
Getting at CP Optimizer
Available as a toolkit in C++, Java, .NETC++ is the native language and allows more
possibilities, like writing incremental custom constraints, and fully controlling the search process
Available as an engine inside OPLWhat we will use todayHigher level modelling and data manipulationCustom visualisation and scenarios via ODM
28/05/2009 © ILOG, All rights reserved 5
Getting Started with OPL Development Studio
28/05/2009 © ILOG, All rights reserved 6
Getting Started with OPL Development Studio
Import Existing OPL 6.x projects
28/05/2009 © ILOG, All rights reserved 7
Getting Started with OPL Development Studio
28/05/2009 © ILOG, All rights reserved 8
Getting Started with OPL Development Studio
Browse projects
28/05/2009 © ILOG, All rights reserved 9
Getting Started with OPL Development Studio
A project = - a set of model files (.mod) - a set of data files (.dat) - a set of settings files (.ops) - other files (e.g. .xls files …) - a set of rrrrrruuuuuunnnnnn ccccccoooooonnnnnnffffffiiiiiigggggguuuuuurrrrrraaaaaatitititititioooooonnnnnnssssss
28/05/2009 © ILOG, All rights reserved 10
Getting Started with OPL Development Studio
Model edition: - data manipulation - expression - objective - constraint - script for pre- and post-processing - use Help-> Dynamic Help for information on keywords
28/05/2009 © ILOG, All rights reserved 11
Getting Started with OPL Development Studio
Model navigation
28/05/2009 © ILOG, All rights reserved 12
Getting Started with OPL Development Studio
Data file: - explicit data - connection to: * databases * Excel worksheets
28/05/2009 © ILOG, All rights reserved 13
Getting Started with OPL Development Studio
Double-click for full-size window
28/05/2009 © ILOG, All rights reserved 14
Overview of an OPL Model
TopData manipulation and pre-processing
declarative (expressions) and/or imperative (script)
Variable declarations
28/05/2009 © ILOG, All rights reserved 15
Getting Started with OPL Development Studio
CP Optimizer model
28/05/2009 © ILOG, All rights reserved 16
Getting Started with OPL Development Studio
DDDDDDaaaaaattttttaaaaaa ssssssttttttrrrrrruuuuuuccccccttttttuuuuuurrrrrreeeeeessssss aaaaaannnnnndddddd dadadadadadattttttaaaaaa rrrrrreeeeeeaaaaaaddddddininininininggggggHere, read input grid
28/05/2009 © ILOG, All rights reserved 17
Getting Started with OPL Development Studio
PrPrPrPrPrPrepreprepreprepreprococococococeeeeeessssssssssssiiiiiinnnnnnggggggHere: display grid
28/05/2009 © ILOG, All rights reserved 18
Getting Started with OPL Development Studio
VVVVVVaaaaaarrrrrriiiiiiaaaaaabbbbbblllllle e e e e e DDDDDDeeeeeeccccccllllllaaaaaararararararattttttiiiiiionononononon
28/05/2009 © ILOG, All rights reserved 19
Some OPL Syntax: declarations
CP Optimizer has integer variables only (dvar int)No set variables, no floating point variables
BUT, floating point expressions are allowede.g. 0.3 * x + y / 13 <= 25.5;
Example declarationsint numColors = 3;
int numNodes = ...; // Comes from a data file
int capacity[1..4] = [5, 7, 2, 3];
range Nodes = 1..numNodes;
dvar int x[Nodes] in 1..numColors;
dvar int y[Nodes,Nodes] in 0..1;
28/05/2009 © ILOG, All rights reserved 20
Some OPL Syntax: declarations
CP Optimizer has integer variables only (dvar int) No set variables, no floating point variables
BUT, floating point expressions are allowede.g. 0.3 * x + y / 13 <= 25.5;
Example declarationsint numColors = 3;
int numNodes = ...; // Comes from a data file
int capacity[1..4] = [5, 7, 2, 3];
range Nodes = 1..numNodes;
dvar int x[Nodes] in 1..numColors;
dvar int y[Nodes,Nodes] in 0..1;
28/05/2009 © ILOG, All rights reserved 21
Some OPL Syntax: data preparation
int n = ...; // From data file
range R = 1..n;
int area[i in R] = width[i] * height[i];
int totalArea = sum(i in R) area[i];
{int} bigOnes = {i | i in R : area[i] >= 100};
tuple Pair { int p1; int p2; };
{Pair} sumTo100 = {
<a,b> | ordered a,b in R : area[a] + area[b] >= 100
};
28/05/2009 © ILOG, All rights reserved 22
Some OPL Syntax: data preparation
int n = ...; // From data file
range R = 1..n;
int area[i in R] = width[i] * height[i];
int totalArea = sum(i in R) area[i];
{int} bigOnes = {i | i in R : area[i] >= 100};
tuple Pair { int p1; int p2; };
{Pair} sumTo100 = {
<a,b> | ordered a,b in R : area[a] + area[b] >= 100
};
28/05/2009 © ILOG, All rights reserved 23
Some OPL Syntax: data preparation
An initial execution block can be useful for debugging and displaying input data
execute { writeln(sumTo100);}
gives...
{<1,99>, <2,98>, <3,97>, <4,96>, <5,95>, <6,94>, ...
28/05/2009 © ILOG, All rights reserved 24
Overview of an OPL Model
TopData manipulation and pre-processing
declarative (expressions) and/or imperative (script)
Variable declarationsMiddle
Declarative modelobjective (optional) and constraints
28/05/2009 © ILOG, All rights reserved 25
Getting Started with OPL Development Studio
MMMMMModelodelodelodelodelodel::::::-VVVVVVaaaaaarrrrrriaiaiaiaiaiablblblblblbleeeeeessssss-EEEEEExxxxxxpppppprerererereressssssssssssionionionionionionssssss-OOOOOObjecbjecbjecbjecbjecbjecttttttiiiiiivvvvvveeeeee-CCCCCCononononononssssssttttttrrrrrraaaaaaiiiiiinnnnnnttttttssssss
28/05/2009 © ILOG, All rights reserved 26
Overview of an OPL Model
Basic structure of middle section
[ minimize/maximize <expression> ]
subject to / constraints { <constraint>; <constraint>; ...}
28/05/2009 © ILOG, All rights reserved 27
Overview of an OPL Model
For allffffffoooooorrrrrraaaaaallllllllllll (i in {1,3,5})
x[i] <= capacity[i];
For all (2)ffffffoooooorrrrrraaaaaallllllllllll (i,j in 1..100 : i < j)
...
Sum (likewise max, min, or)ssssssuuuuuummmmmm (i in 1..10) x[i] == 1;
AllallDifferent (aaaaaallllllllllll (i in 0..n-1) slot[i]);
28/05/2009 © ILOG, All rights reserved 28
Overview of an OPL Model
For allffffffoooooorrrrrraaaaaallllllllllll (i in {1,3,5})
x[i] <= capacity[i];
For all (2)ffffffoooooorrrrrraaaaaallllllllllll (i,j in 1..100 : i < j)
...
Sum (likewise max, min, or)ssssssuuuuuummmmmm (i in 1..10) x[i] == 1;
AllallDifferent (aaaaaallllllllllll (i in 0..n-1) slot[i]);
28/05/2009 © ILOG, All rights reserved 29
Overview of an OPL Model
For allffffffoooooorrrrrraaaaaallllllllllll (i in {1,3,5})
x[i] <= capacity[i];
For all (2)ffffffoooooorrrrrraaaaaallllllllllll (i,j in 1..100 : i < j)
...
Sum (likewise max, min, or)ssssssuuuuuummmmmm (i in 1..10) x[i] == 1;
AllallDifferent (aaaaaallllllllllll (i in 0..n-1) slot[i]);
28/05/2009 © ILOG, All rights reserved 30
Overview of an OPL Model
For allffffffoooooorrrrrraaaaaallllllllllll (i in {1,3,5})
x[i] <= capacity[i];
For all (2)ffffffoooooorrrrrraaaaaallllllllllll (i,j in 1..100 : i < j)
...
Sum (likewise max, min, or)ssssssuuuuuummmmmm (i in 1..10) x[i] == 1;
AllallDifferent (aaaaaallllllllllll (i in 0..n-1) slot[i]);
28/05/2009 © ILOG, All rights reserved 31
Expressions and Constraints
Arithmetic constraints x + y, x – y, x * y, x / y, x div y, x % y min, max, abs, log, exp etc. Piecewise linear functions
Relational constraints x == y, x != y, x <= y, x < y, lb <= x <= ub
Logical constraints !c, c||d, c && d, c => d c and d are relational or conditional constraints
28/05/2009 © ILOG, All rights reserved 32
Expressions and Constraints
Arithmetic constraints x + y, x – y, x * y, x / y, x div y, x % y min, max, abs, log, exp etc. Piecewise linear functions
Relational constraints x == y, x != y, x <= y, x < y, lb <= x <= ub
Logical constraints !c, c||d, c && d, c => d c and d are relational or conditional constraints
28/05/2009 © ILOG, All rights reserved 33
Expressions and Constraints
Arithmetic constraints x + y, x – y, x * y, x / y, x div y, x % y min, max, abs, log, exp etc. Piecewise linear functions
Relational constraints x == y, x != y, x <= y, x < y, lb <= x <= ub
Logical constraints !c, c||d, c && d, c => d c and d are relational or conditional constraints
28/05/2009 © ILOG, All rights reserved 34
Expressions and Constraints
Reification Relational or logical constraints can be used in a value
context, where they evaluate to 0 or 1
Examples Arithmetic: max(0, abs(load[i] - cap)) Relational: wid * hei * depth * density <= maxLoad Logical: end[i] <= start[j] || start[j] <= end[i] Reification: spill == (load[i] > cap)
28/05/2009 © ILOG, All rights reserved 35
Expressions and Constraints
Reification Relational or logical constraints can be used in a value
context, where they evaluate to 0 or 1
Examples Arithmetic: max(0, abs(load[i] - cap)) Relational: wid * hei * depth * density <= maxLoad Logical: end[i] <= start[j] || start[j] <= end[i] Reification: spill == (load[i] > cap)
28/05/2009 © ILOG, All rights reserved 36
Expressions and Constraints
Count expression count(dvar int[] x, int c) Evaluates the number of variables in x with value c e.g. Count the number of nurses allocated to ward 5
count(wardAllocation, 5) >= 3
Element expression (int[] a)[dvar int x] OR (dvar int[] a)[dvar int x] Evaluates to the xth member of a e.g. travel == 2 * distFromPittsburgh[holidayTown] travel and holidayTown are variables
28/05/2009 © ILOG, All rights reserved 37
Expressions and Constraints
Count expression count(dvar int[] x, int c) Evaluates the number of variables in x with value c e.g. Count the number of nurses allocated to ward 5
count(wardAllocation, 5) >= 3
Element expression (int[] a)[dvar int x] OR (int var[] a)[dvar int x] Evaluates to the xth member of a e.g. travel == 2 * distFromPittsburgh[holidayTown] travel and holidayTown are variables
28/05/2009 © ILOG, All rights reserved 38
Expressions and Constraints
All Different allDifferent(dvar int[] x) All variables in x must take different values e.g. The rank (visit priority) of each city is different
allDifferent(rankOfVisit)
Allowed / Forbidden assignments allowedAssignments({<a,b,c>} A, dvar int[3] x) The assignments to x must fit with a tuple of A forbiddenAssignments is the negation of this e.g. Combinations of engine, gearbox, on promotion
28/05/2009 © ILOG, All rights reserved 39
Expressions and Constraints
All Different allDifferent(dvar int[] x) All variables in x must take different values e.g. The rank (visit priority) of each city is different
allDifferent(rankOfVisit)
Allowed / Forbidden assignments allowedAssignments({<a,b,c>} A, dvar int[3] x) The assignments to x must fit with a tuple of A forbiddenAssignments is the negation of this e.g. Combinations of engine, gearbox, on promotion
28/05/2009 © ILOG, All rights reserved 40
Expressions and Constraints
Bin packing constraint pack(dvar int[m] ld, dvar int[n]x, int[n] sz, dvar int c) ld[i] == sum(j ) (x[j] == i ) * sz[j]
c is the number of containers used
e.g. Length of ad breaks given the ad assignmentInverse constraint
inverse(dvar int[n] x, dvar int[n] y) x[i] == j <=> y[j] == i --- link primary and dual models
Lexicographic ordering constraint lex(dvar int[n] x, dvar int[n] y) --- break symmetries
28/05/2009 © ILOG, All rights reserved 41
Expressions and Constraints
Bin packing constraint pack(dvar int[m] ld, dvar int[n]x, int[n] sz, dvar int c) ld[i] == sum(j ) (x[j] == i ) * sz[j]
c is the number of containers used
e.g. Length of ad breaks given the ad assignmentInverse constraint
inverse(dvar int[n] x, dvar int[n] y) x[i] == j <=> y[j] == i --- link primary and dual models
Lexicographic ordering constraint lex(dvar int[n] x, dvar int[n] y) --- break symmetries
28/05/2009 © ILOG, All rights reserved 42
Overview of an OPL Model
TopData manipulation and pre-processing
declarative (expressions) and/or imperative (script)
Variable declarationsMiddle
Declarative modelobjective (optional) and constraints
BottomPost-processing of solutions
Declarative (expressions) and/or imperative (script)
28/05/2009 © ILOG, All rights reserved 43
Getting Started with OPL Development Studio
PosPosPosPosPosPosttttttprprprprprprococococococeeeeeessssssssssssiiiiiinnnnnnggggggHere: display solution grid
28/05/2009 © ILOG, All rights reserved 44
Some OPL Syntax: post-processing
dvar int day[Jobs] in Days;
constraints { ... }
// .........................
{int} jobsOnDay[d in Days] = { j | j in Jobs : day[j] == d };
execute {for (var d in Days) {
write(“Day “ + d + “: “);for (j in jobsOnDay[d])
write(“ “ + j);
writeln(); }
}
28/05/2009 © ILOG, All rights reserved 45
Some OPL Syntax: post-processing
dvar int day[Jobs] in Days;
constraints { ... }
// .........................
{int} jobsOnDay[d in Days] = { j | j in Jobs : day[j] == d };
execute {for (var d in Days) {
write(“Day “ + d + “: “);for (j in jobsOnDay[d])
write(“ “ + j);
writeln(); }
}
28/05/2009 © ILOG, All rights reserved 46
Getting Started with OPL Development Studio
A run configuration = A variation of a project for execution purposes: - at least one model file (.mod) - a set of data files (.dat) - a set of settings files (.ops)
28/05/2009 © ILOG, All rights reserved 47
Getting Started with OPL Development Studio
Running a configuration:Right-click Run this
28/05/2009 © ILOG, All rights reserved 48
Getting Started with OPL Development Studio
Engine log
28/05/2009 © ILOG, All rights reserved 49
Getting Started with OPL Development Studio
Engine statistics for performance analysis
28/05/2009 © ILOG, All rights reserved 50
Getting Started with OPL Development Studio
Script output
28/05/2009 © ILOG, All rights reserved 51
Getting Started with OPL Development Studio
Solution and data inspection
28/05/2009 © ILOG, All rights reserved 52
Search in CP OptimizerAutomatic search is emphasised
Simpler, more maintainable, benefit from upgradesSearch Phases
What group of variables to assign first(optionally) define instantiation strategy
ParametersInference levels and search control parameters
Problem still hard?Improve modelSimplify or relax specificationDecompose: CPLEX often useful here
28/05/2009 © ILOG, All rights reserved 53
TTTTTTyyyyyypipipipipipiccccccaaaaaallllll uuuuuusssssseeeeee ooooooffffff CCCCCCPPPPPP OOOOOOptptptptptptiiiiiimmmmmmiiiiiizzzzzzeeeeeerrrrrr
UUUUUUse se se se se se CCCCCCP P P P P P OOOOOOptptptptptptiiiiiimmmmmmiiiiiizzzzzzeeeeeerrrrrr’’’’’’ssssssaaaaaauuuuuuttttttomomomomomomaaaaaattttttiiiiiicccccc sssssseeeeeeaaaaaarcrcrcrcrcrchhhhhh
RRRRRReeeeeevvvvvviewiewiewiewiewiewmmmmmmodelodelodelodelodelodel((((((rrrrrreeeeeedudududududunnnnnndadadadadadannnnnnttttttccccccononononononssssssttttttrrrrrraaaaaaiiiiiinnnnnnttttttssssss,,,,,,dedededededeccccccisisisisisisiiiiiiononononononvvvvvvaaaaaarrrrrriiiiiiaaaaaablblblblblbleeeeeessssss eeeeeettttttcccccc......))))))
MMMMMModelodelodelodelodelodel prprprprprproblobloblobloblobleeeeeemmmmmmiiiiiinnnnnn OOOOOOPLPLPLPLPLPL
Satisfied?
UUUUUUsssssseeeeee ““““““sssssseeeeeeaaaaaarrrrrrcccccchhhhhhphphphphphphaaaaaasssssseeeeeessssss”””””” tttttto o o o o o aaaaaadddddddddddd ssssssomomomomomomeeeeeedomdomdomdomdomdomaaaaaaiiiiiinnnnnnkkkkkknnnnnnoooooowlwlwlwlwlwledgedgedgedgedgedgeeeeeetttttto o o o o o tttttthhhhhheeeeee sssssseeeeeeaaaaaarrrrrrcccccchhhhhhprprprprprprococococococeeeeeessssssssssss
CCCCCChhhhhhaaaaaannnnnnggggggeeeeeepapapapapaparrrrrraaaaaammmmmmeteteteteteteeeeeerrrrrrssssssorororororor seaseaseaseaseasearrrrrrcccccchhhhhhmmmmmmeeeeeetttttthhhhhhodododododod
YES NO
DDDDDDeeeeeeccccccomomomomomomposposposposposposeeeeeemmmmmmooooooddddddeeeeeellllll
CCCCCCuuuuuussssssttttttomomomomomom ggggggoaoaoaoaoaoallllllorororororor ccccccononononononssssssttttttrrrrrraaaaaaininininininttttttssssss((((((CCCCCC++++++++++++))))))
MMMMMModelodelodelodelodelodel prprprprprproblobloblobloblobleeeeeemmmmmmiiiiiinnnnnn OOOOOOPLPLPLPLPLPL
UUUUUUse se se se se se CCCCCCP P P P P P OOOOOOptptptptptptiiiiiimmmmmmiiiiiizzzzzzeeeeeerrrrrr’’’’’’ssssssaaaaaauuuuuuttttttomomomomomomaaaaaattttttiiiiiicccccc sssssseeeeeeaaaaaarcrcrcrcrcrchhhhhh
MMMMMModelodelodelodelodelodel prprprprprproblobloblobloblobleeeeeemmmmmmiiiiiinnnnnn OOOOOOPLPLPLPLPLPL
UUUUUUse se se se se se CCCCCCP P P P P P OOOOOOptptptptptptiiiiiimmmmmmiiiiiizzzzzzeeeeeerrrrrr’’’’’’ssssssaaaaaauuuuuuttttttomomomomomomaaaaaattttttiiiiiicccccc sssssseeeeeeaaaaaarcrcrcrcrcrchhhhhh
Satisfied?Satisfied?
UUUUUUsssssseeeeee ““““““sssssseeeeeeaaaaaarrrrrrcccccchhhhhhphphphphphphaaaaaasssssseeeeeessssss”””””” tttttto o o o o o aaaaaadddddddddddd ssssssomomomomomomeeeeeedomdomdomdomdomdomaaaaaaiiiiiinnnnnnkkkkkknnnnnnoooooowlwlwlwlwlwledgedgedgedgedgedgeeeeeetttttto o o o o o tttttthhhhhheeeeee sssssseeeeeeaaaaaarrrrrrcccccchhhhhhprprprprprprococococococeeeeeessssssssssss
UUUUUUsssssseeeeee ““““““sssssseeeeeeaaaaaarrrrrrcccccchhhhhhphphphphphphaaaaaasssssseeeeeessssss”””””” tttttto o o o o o aaaaaadddddddddddd ssssssomomomomomomeeeeeedomdomdomdomdomdomaaaaaaiiiiiinnnnnnkkkkkknnnnnnoooooowlwlwlwlwlwledgedgedgedgedgedgeeeeeetttttto o o o o o tttttthhhhhheeeeee sssssseeeeeeaaaaaarrrrrrcccccchhhhhhprprprprprprococococococeeeeeessssssssssss
CCCCCChhhhhhaaaaaannnnnnggggggeeeeeepapapapapaparrrrrraaaaaammmmmmeteteteteteteeeeeerrrrrrssssssorororororor seaseaseaseaseasearrrrrrcccccchhhhhhmmmmmmeeeeeetttttthhhhhhodododododod
CCCCCChhhhhhaaaaaannnnnnggggggeeeeeepapapapapaparrrrrraaaaaammmmmmeteteteteteteeeeeerrrrrrssssssorororororor seaseaseaseaseasearrrrrrcccccchhhhhhmmmmmmeeeeeetttttthhhhhhodododododod
RRRRRReeeeeevvvvvviewiewiewiewiewiewmmmmmmodelodelodelodelodelodel((((((rrrrrreeeeeedudududududunnnnnndadadadadadannnnnnttttttccccccononononononssssssttttttrrrrrraaaaaaiiiiiinnnnnnttttttssssss,,,,,,dedededededeccccccisisisisisisiiiiiiononononononvvvvvvaaaaaarrrrrriiiiiiaaaaaablblblblblbleeeeeessssss eeeeeettttttcccccc......))))))
RRRRRReeeeeevvvvvviewiewiewiewiewiewmmmmmmodelodelodelodelodelodel((((((rrrrrreeeeeedudududududunnnnnndadadadadadannnnnnttttttccccccononononononssssssttttttrrrrrraaaaaaiiiiiinnnnnnttttttssssss,,,,,,dedededededeccccccisisisisisisiiiiiiononononononvvvvvvaaaaaarrrrrriiiiiiaaaaaablblblblblbleeeeeessssss eeeeeettttttcccccc......))))))
DDDDDDeeeeeeccccccomomomomomomposposposposposposeeeeeemmmmmmooooooddddddeeeeeellllllDDDDDDeeeeeeccccccomomomomomomposposposposposposeeeeeemmmmmmooooooddddddeeeeeellllll
CCCCCCuuuuuussssssttttttomomomomomom ggggggoaoaoaoaoaoallllllorororororor ccccccononononononssssssttttttrrrrrraaaaaaininininininttttttssssss((((((CCCCCC++++++++++++))))))
28/05/2009 © ILOG, All rights reserved 54
Automatic Search in CP OptimizerCP Optimizer's search is based on restarts
Search is can be restarted at the top of the search tree, allowing initial bad decisions to be undone
Search can be make complete by iteratively increasing the time between restarts
This technique is only really effective if a different search path is taken at each restart
…
28/05/2009 © ILOG, All rights reserved 55
Following Different Search Paths
Impact-based strategiesBy observing constraint propagation during previous
restarts, search learns about the problem and modifies its strategy accordingly
RandomisationDecisions are slightly randomised, for example as a tie-
breaking techniqueNo-goods
The explored part of the search tree is represented in CNF and maintained as a global constraint
28/05/2009 © ILOG, All rights reserved 56
Impact-based Strategies
An implementation of the general principles1/ Pick a variable which leaves least future choice2/ Choose a value which leaves the most future choice
Idea is to measure the remaining search space when an assignment is made
Impact is the proportion of search space reduction arising from an assignment
The impact for a particular assignment x = a is learned by averaging individual impacts over previous assignments
28/05/2009 © ILOG, All rights reserved 57
Search Phases
In CP Optimizer, search phases are simple search directives to help the automatic search process
Most common useDefine decision variables, or the most important onesDefine priority-ordered groups of decision variables
Less common useDefine decision variables and how to instantiate those
variablesFor this, there are various pre-defined evaluators
28/05/2009 © ILOG, All rights reserved 58
Search Phases in OPL
In OPL, search phases are created in an executeblock before the main constraint block
dvar int x[1..n] in 1..n;
// ... other declarations ...
execute {
var f = cp.factory;
cp.setSearchPhases(f.searchPhase(x));
}
28/05/2009 © ILOG, All rights reserved 59
Search Phases in OPL
Instantiate variables in x, then those in y
dvar int x[1..n] in 1..n;
dvar int y[1..n] in 1..n;
// ...other declarations...
execute {
var f = cp.factory;
cp.setSearchPhases(f.searchPhase(x), f.searchPhase(y));
}
28/05/2009 © ILOG, All rights reserved 60
Search Phases in OPL
Instantiate variables in x using minimum domain size and maximum value
dvar int x[1..n] in 1..n;
// ...other declarations...
execute {
var f = cp.factory;
cp.setSearchPhases(
f.searchPhase(x, f.selectSmallest(f.domainSize()),
f.selectLargest(f.value()))
);
}
28/05/2009 © ILOG, All rights reserved 61
Search Control Parameters
Controlling inference strengthGlobal, or per constraint type
Set limits on searchRun time, branches, fails, etc.
Optimality toleranceRelative and/or absolute gap
Controlling restartsControl the growth factor
Search LogVerbosity, frequency
28/05/2009 © ILOG, All rights reserved 62
Getting Started with OPL Development Studio
Settings file -
© ILOG, All rights reserved63
Worked Examples
CP-AI-OR 2009 Masterclass
28/05/2009
Paul ShawConstraint Programming Group
28/05/2009 © ILOG, All rights reserved 64
CSPLIB 38: Steel mill slab designSlabs size 44
Slabs size 32
Slabs size 23
...(20 different sizes available)
16
16
16
14
14
14
...(100+ orders, with weightand build process identified by color)
1216 16
16 14
(loss 2)
•Max 2 colors per slab•Process all orders•Minimize total loss
© ILOG, All rights reserved
28/05/2009 © ILOG, All rights reserved 65
Addition chains
© ILOG, All rights reserved
1
2
3
5
10
20
40
60
100
Build a minimal length sequence of numbers leading to a particular target, beginning with 1
Each number is built as the sum as two smaller numbers
The first two numbers are necessarily 1 and 2
© ILOG, All rights reserved66
End of Part One
Thank You