View
220
Download
1
Embed Size (px)
DESCRIPTION
Cpo Presentation
IBM ILOG CP Optimizer
CP-AI-OR 2009 Masterclass
28/05/2009
Paul ShawConstraint Programming Group
paul.shaw@fr.ibm.com
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
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
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 = {
| 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 = {
| 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...
{, , , , , , ...
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 ]
subject to / constraints { ; ; ...}
28/05/2009 ILOG, All rights reserved 27
Overview of an OPL Model
For allffffffoooooorrrrrraaaaaallllllllllll (i in {1,3,5})
x[i]
28/05/2009 ILOG, All rights reserved 28
Overview of an OPL Model
For allffffffoooooorrrrrraaaaaallllllllllll (i in {1,3,5})
x[i]
28/05/2009 ILOG, All rights reserved 29
Overview of an OPL Model
For allffffffoooooorrrrrraaaaaallllllllllll (i in {1,3,5})
x[i]
28/05/2009 ILOG, All rights reserved 30
Overview of an OPL Model
For allffffffoooooorrrrrraaaaaallllllllllll (i in {1,3,5})
x[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
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
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
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
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
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 diff