Opl 2
Opl 2
Technical overview
Sofiane Oussedik
[email protected]
1
Outline
ILOG OPL Studio
• Overview
• Models and Data
• Linear Programming Example
• Constraint Programming Example
• Scheduling Example
• Data Management Features
• Iterative Applications
• OPL Component Libraries
2
Optimization Development
ILOG OPL Studio
Business
Process
Expert Programming
Expert
3
ILOG Optimization Suite
ILOG
OPL ILOG ILOG ILOG
Studio Scheduler Dispatcher Configurator
ILOG
C JConfigurator
API
ILOG
VB ILOG Solver & ILOG JSolver
CPLEX
API
ILOG Concert Technology (C++ & Java)
6
OPL features
for development
7
What Are Models?
Linear programming
Project
Model Data
One
Problem
Instance
8
A Production Planning Example
Linear programming
13
Problem Model Is Identical (2)
Linear programming
minimize
sum(p in Products)
(insideCost[p] * inside[p] +
Objective
outsideCost[p]* outside[p] ) Function
subject to {
forall(r in Resources)
sum(p in Products)
consumption[p, r]*inside[p] <= capacity[r];
forall(p in Products)
inside[p] + outside[p] >= demand[p];
};
Constraints
14
Demo of production.prj
Linear programming
• Run production.prj
• Display inside and outside production
15
Linear and Integer Programming
Linear programming
• OPL can represent linear and mixed integer programming
problems
• Objective functions and constraints are linear
• E.g., 5 x + 3 y - 4 z
• Variables can be floating point or integer valued
• Constraints are inequalities or equalities ( ≤, ≥, =)
• OPL Studio can solve
• Linear Programs with any of the CPLEX algorithms
• Mixed Integer Programs using the CPLEX MIP algorithm
• Mixed Integer Programs by using constraint programming-based
search
• OPL provides access to all CPLEX algorithmic settings
16
Map Coloring Example
Constraint programming
• Run map.mod
• Show all solutions
• Rerun to show the propagation
• Select Execution > Browse Active Model
• Right-click on Variables > color and select display domain
• Select Debug > Stop at Choice Point
• Step through the model
• Disable Debug > Stop at Choice Point when finished
19
Visualizing Solutions
Constraint programming
20
Demo of mapgr.prj
• Run mapgr.prj
• Show all solutions
21
Constraint Programming Models
Constraint programming
• OPL allows you to represent problems using
constraint programming features
• Variables can be set to a value from a set
• A variable can index into an array ( y[x[k]] )
• Constraint relations can be strict inequalities
(<, >, < >)
• Logical conditions can be modeled
x < 4 => y > 5
• Global constraints can be written
alldifferent(x)
• Constraints can have values (meta constraints)
sum (j in myset) (x[j] > 5) = 3
22
CP Solutions
Constraint programming
24
Warehouse assignment: MIP
minimize
sum(w in Warehouses) fixed * open[w] +
sum(w in Warehouses, s in Stores)
supplyCost[s,w] * supply[s,w]
subject to {
forall(s in Stores)
sum(w in Warehouses) supply[s,w] = 1;
forall(w in Warehouses, s in Stores)
supply[s,w] <= open[w];
forall(w in Warehouses)
sum(s in Stores) supply[s,w] <= capacity[w];
};
25
Warehouse assignment: CP
minimize
sum(s in Stores) cost[s] +
sum(w in Warehouses) fixed * open[w]
subject to {
forall(s in Stores)
cost[s] = supplyCost[s,supplier[s]];
forall(s in Stores )
open[supplier[s]] = 1;
forall(w in Warehouses)
sum(s in Stores) (supplier[s] = w) <= capacity[w];
};
search {
forall(s in Stores ordered by decreasing regretdmin(cost[s]))
tryall(w in Warehouses ordered by increasing supplyCost[s,w])
supplier[s] = w;
}; 26
MIP versus CP formulation
• Decision variables
• The constraint programming formulation has 2S+W decision variables.
• The mixed integer formulation has SW+W decision variables.
• The CP formulation has a decision variable over a finite set of values to
represent the cost of shipping for store s.
• The MIP formulation represents the cost of shipping for store s as an
implied expression.
sum (w in Warehouses) supplyCost[s,w] * supply[s,w]
• Expressions
• The CP formulation uses expressions of the form open[supplier[s]],
which uses a decision variable to index into another decision variable.
• The CP formulation uses the expression (supplier[s] = w) that
evaluates to a 0/1 value.
27
CP includes search!
search {
forall(s in Stores ordered by decreasing regretdmin(cost[s]))
tryall(w in Warehouses ordered by increasing supplyCost[s,w])
supplier[s] = w;
};
• cost[s] can only take on values from supplyCost[s,w] for the set of open
warehouses w
regretdmin = (second lowest value) - (lowest value)
• Pick the store with the largest regret, then pick the warehouse with the smallest
cost
• Then open that warehouse
28
But Which is BETTER ??
29
Scheduling Example (Part 1)
Scheduling
• Have to schedule a set of tasks to build a house
enum Tasks { masonry, carpentry, plumbing,
ceiling, roofing, painting,
windows, facade, garden, moving };
• Tasks require a given amount of time to be completed
int duration[Tasks] = [7,3,8,3,1,2,1,2,1,1];
int totalDuration =
sum(t in Tasks) duration[t];
scheduleHorizon = totalDuration;
• Some tasks require other tasks to be completed
task[masonry] precedes task[ceiling];
task[carpentry] precedes task[roofing];
task[ceiling] precedes task[painting];
...
30
Scheduling Example (Part 2)
Scheduling
Constraints 33
Demo of house3.mod
Scheduling
• Run house3.mod
• Show the Gantt chart for task activities and
worker resources
34
Scheduling Models
Scheduling
• OPL supports modeling entities for scheduling
problems
• Activities
• Have durations
• Can be breakable
• Constraints to state that activities precede other activities
• Resources
• Unary Resources
• Discrete Resources
• Reservoirs
• State Resources with Transition Times
• Can also add other kinds of constraints using
constraint programming
35
Structured Data
Data Management
• Given a set of cities
enum Cities { MIA, EWR, SFO, BOS };
• Reading
setof(int) TimePeriods from Time avail
SheetRead(sheetData,"Time"); 1 40
2 40
float+ avail[TimePeriods] from 32
3
SheetRead(sheetData,"avail"); 4 40
setof(string) Products from
SheetRead(sheetData,"Product");
float+ revenue[Products,TimePeriods] from
SheetRead(sheetData,"Revenue");
Revenue 1 2 3 4
• Writing bands
coils
25
30
26
35
27
37
27
39
39
OPLScript Example
Iterative Applications
Model produce("mulprod.mod","mulprod.dat") editMode;
import enum Resources produce.Resources;
int+ capFlour := produce.capacity[flour];
Declare Model
forall(i in 1..4) {
produce.capacity[flour] := capFlour;
produce.solve(); Set data, then
cout << "Flour capacity" << capFlour << Solve!
"Objective Function: " <<
produce.objectiveValue() << endl;
for deployment
41
Deployment Options
OPL Component Libraries
C
O
M OPL Generate Application
P
model compiled Read compiled model with
I model VB, Java, C++, Web Fixed
L Model
E
I
N
T
Application OPL OPL
E Read Read script
R reads interpreted Script model
VB, Java, C++, Web
P scripts and models
R from files
E
T 42
Excel Demo
Steel Production Spreadsheet Application
• Open steelt2D.xls
• Show optimization
• Show how if numbers change, answer
changes
43
Visual Basic Example
OPL Component Libraries
• Initialize solver
Dim solver As COPLsolver
Set solver = New COPLsolver
• Java
OPLsolver solver = new OPLsolver();
46
OPL Studio Key Features
Summary
• Powerful Modeling Language (OPL) for
• Constraint Programming
• Scheduling
• Linear and Mixed Integer Programming
• Overview of CPLEX
• Building CPLEX applications using OPL Studio
• Getting started with OPL Studio
Email: [email protected]
Visit: http://www.ilog.com
49