OPL Optimization Programming Language - PowerPoint PPT Presentation

Loading...

PPT – OPL Optimization Programming Language PowerPoint presentation | free to download - id: 81948-ZDc1Z



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

OPL Optimization Programming Language

Description:

Variables must be declared explicitly using var. ... var float inv[Products,0..nbPeriods]; Product Types. Resource Types. Time Period (Months) ... – PowerPoint PPT presentation

Number of Views:851
Avg rating:3.0/5.0
Slides: 81
Provided by: bernd4
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: OPL Optimization Programming Language


1
OPL Optimization Programming Language
  • Today we will look at OPL
  • Structure
  • Syntax
  • Modelling Linear Problems in OPL
  • Constraint Programming in OPL

2
Mathematical Modelling Language
  • Using AMPL
  • var B var T
  • maximize profit 25B30T
  • subject to (1/200)B(1/140)T lt 40
  • subject to 0 lt B lt 6000
  • subject to 0 lt T lt 4000
  • solve

3
Modelling Languages
  • Mathematical Modelling Languages (AMPL, GAMS)
  • very high-level specification of (typically
    linear)
  • models
  • specialized optimization algorithms
  • limited flexibility for search
  • Constraint Programming
  • programming language
  • backtracking search with consistency based
    methods
  • to refine variable domains
  • limited optimization capabilities
  • limited data structures
  • flexible specification of search, heuristics, etc.

4
Modelling Languages
  • OPL combines both approaches
  • High-level specification of linear programs
  • High-level specification of constraint programs
  • Expressive data structures
  • Flexible search
  • Specialized optimization algorithms
  • BUT not a universal programming language
  • OPL models can be solved using
  • linear programming
  • integer programming techniques
  • (branchbound etc)
  • backtracking search consistency techniques
  • The OPL system identifies the class of problem
  • and chooses the appropriate technique.

5
Linear Programming in OPL
enum Products gas, chloride enum Components
nitrogen, hydrogen, chlorine float
demandProducts, Components 1, 3, 0, 1,
4, 1 float profitProducts 30,
40 float stockComponents 50, 180,
40 var float productionProducts maximize
sum (p in Products) profitp
productionp subject to forall (c in
Components) sum (p in Products) demandp, c
productionp lt stockc
Data
Variables
Objective
Constraints
GasNH3, ChlorideNH4CL
6
(Mixed) Integer Programming in OPL
int nbItems 5 range Items 1..nbItems int
capacity 1000 int valueItems
59,44,30,12,170 int weightItems 20, 30,
16, 22, 70 var int takeItems in
0..capacity maximize sum(i in Items) valuei
takei subject to sum(i in Items) weighti
takei lt capacity
Knapsack Problem
7
Separating the Data
In a reusable model the concrete instance data is
separated from the generic part of the problem.
enum Products ... enum Components ... float
demandProducts, Components ... float
profitProducts ... float stockComponents
... var float productionProducts maximize
sum (p in Products) profitp
productionp subject to forall (c in
Components) sum (p in Products) demandp, c
productionp lt stockc
8
Model Data
Initialization of model data can be performed in
a separate data file.
Products gas, chloride Components
nitrogen, hydrogne, chlorine demand 1,
3, 0, 1, 4, 1 profit 40,50 stock
50, 180, 40
9
Basic Data Types
OPL knows only two basic data types. Integer in
t x2 int x2 (positive only) Real float
x2.5 float x2.5 (positive only) All
other types must be declared.
10
Type Declarations
OPL knows most structured data types that are
used in typical programming languages
Enumerations, Arrays and Records. Additionally,
some structured types typically needed in in
mathematical modelling are available Ranges
(Intervals) and Sets.
  • Enumerations
  • enum Colors red, green, blue
  • Colors todaysSky blue
  • Ranges
  • range Queens 1..4
  • range Queens 1..boardSize
  • Queens position 1
  • Float Range
  • range float angle 0.0..23.1415

11
Arrays
Arrays can be indexed by any enumerable type --
ranges (integer), enumerations and sets
int fn1..10 1, 1, 2, 3, 5, 8, 13, 21, 34,
55 Range I 1..10 int fnI 1, 1, 2,
3, 5, 8, 13, 21, 34, 55 enum Colors red,
green, blue, orange, purple, yellow int
amountColors 100, 300, 250, 50, 320,
90 Colors primary red, green, blue
int amountprimary 100, 300, 250
Set declaration
Set index
12
Array Initialization
An array can either be initalized by enumerating
its elements or by using explicit indices
enum Products gas, chloride enum
Components nitrogen, hydrogen,
chlorine float demandProducts, Components
... demand 1, 3, 0, 1, 4,
1 or demand gas nitrogen 1,
hydrogen 3 chlorine 0 chloride
nitrogen 1, hydrogen 4, chlorine
1
13
Generic Array Initialization
If the array elements are dependent on the
index generic expressions can be used for their
initialization
int fni in 1..10 i
This also works for multi-dimensional arrays, for
example
range d 1..10 int ad,d ... int
aTransposedi in d, j in d aj,i
14
Structures (Records)
struct Coord int x int y
Once declared, structures can be used like any
other data type
Coord x lt 10, 20 gt Coord xs lt10, 20gt,
lt30, 30gt, lt50, 50gt Coord xa1..3 lt10,
20gt, lt30, 30gt, lt50, 50gt
Elements of a structure can be addressed by name
int xCoordsi in 1..3 xai.x
an important usage of structures is for the
representation of sparse problems
15
Sets
int s1 3, 4, 5, 6 int s2 5, 1,
3, 7, 9 int s1 union s2
also inter, diff, symdiff
  • Sets can be initialized generically with
  • range expressions
  • query-like expressions

int odd1 1..100 by 2 int odd2 i
i in 1..100 i mod 2 1
int s 1..10 struct Interval int low,
int high Interval nonEmpty lti,jgt
ordered i,j in s Interval nonEmpty
ltlow i, high jgt ordered i,j in s
A set is always implicitly ordered!
16
Exploiting Sparsity
Sparse problems should be modelled with arrays
indexed by elements of sets instead of by
elements of ranges. This keeps the arrays small.
Consider a weighted graph
int maxNode ... int Node
1..maxNode float edgeWeightNode,
Node ...
If the graph is sparse, the following is likely
to be more efficient
int Node 1..maxNode struct Edge Node
start Node end Edge edges lt1,7gt
lt3,4gt, lt4,3gt float edgeWeightedges 3.2,
4.4, 1.7
This array has only 3 elements (edgeWeightlt1,7gt,
etc.)
17
Variables
  • Variables must be declared explicitly using var.
  • They are logical or mathematical
    variables. It is the
  • role of OPL to find values for them.
  • Admissible types are
  • int, int
  • float, float
  • enumerations
  • arrays of these types

var int x var int x in 0..100 var int x0..
10, 0..10 in 0..100 enum Colors red,
green, blue, orange, purple, yellow enum
Rooms lounge, bed, kitchen, study,
bath var Colors paintRooms var
float amountr in Routes in 0.0..capacityr
18
Input and Output
Input can be taken from data files or from the
user
int maxFromFile ... int maxFromUser ltlt
Input number of positions
Output is generated using the display keyword
var float amountr in Routes in
0.0..capacityr ... float slackr in Routes
capacityr-amountr display(r in Routes
amountrgt0) slackr display sum(r in Routes)
slackr
The implementation OPLstudio also offers an
interactive browser.
19
Consistency Conditions (Integrity)
Like in relational databases, consistency
conditions or integrity conditions can be
asserted. These allow input data to be checked.
assert forall (p in Products) sum(s in
Suppliers) supplys,p sum(c in Customers)
demandc,p
These raise an execution exception when violated.
20
Expressions
A number of mathematical expressions are
supported abs, sqrt, ceil, distToInt, floor,
frac, nearest, trunc float f 5.5 float g
sqrt(2f) Integer expressions only support ,
-, , /, mod int x3 int y22 int zy mod
x Float expressions must explicitly be
converted to integer int x ftoi(floor(f))
21
Aggregates
Aggregate expressions are specified directly
without using loops int costEdges
... Edge path ... int totalCost
sum(e in path) coste The following types of
aggregates are supported min (minimum) max (ma
ximum) sum (summation) prod (product)
22
Piecewise Linear Functions
30
20
amountp
10
20
sum(p in products) piecewise2 -gt 10 1 -gt 20,
0.5(0,0) amountp
point on function
argument
breakpoint
slope
23
Constraints
  • Float constraints linear or piecewise linear
  • Discrete constraints arbitrary relations on
    integers or enumerations
  • Basic Constraints
  • forall(t in tasks)
  • t.end gt t.startt.duration
  • Boolean Combinations
  • forall ( ordered t1, t2 in tasks)
  • t1.start gt t2.startt2.length \/
  • t2.start gt t1.startt1.length

24
Linear Programming Example
A company produces and sells different kinds of
products. Each product can be produced inside of
the company from certain resources at a fixed
cost or bought at another cost from outside. The
company can only produce a limited amount of each
product since there is a limit on the available
resources. The company wants to decide which
amount to produce inside and which amount to buy
to satisfy a given customer demand. It should
maximise profit but must satisfy the resource
constraints.
25
Planning
enum Products ... enum Resources ... float
consumptionProducts,Resources ... float
capacityResources ... float
demandProducts ... float insideCostProducts
... float outsideCostProducts
... var float insideProducts var float
outsideProducts
Product Types
Resource Types
Amount of resource required to produce a given
product
Available resources
Demand for product
Cost of producing product
Amount of product to produce
minimize sum(p in Products)
(insideCostpinsidep outsideCostpoutside
p) subject to forall(r in Resources)
sum(p in Products) consumptionp,rinsidep lt
capacityr forall(p in Products)
insidep outsidep gt demandp
26
Planning (Data)
Products penne orecchiette fettucine Resource
s flour eggs consumption 0.5 0.2
0.4 0.4 0.3 0.6 capacity 20,
40 demand 100, 200, 300 insideCost 0.6,
0.8, 0.3 outsideCost 0.8, 0.9, 0.4
(Answer)
Optimal Solution with Objective Value 372.0000
insidepenne 40.0000 insideorecchiette
0.0000 insidefettucine 0.0000
outsidepenne 60.0000 outsideorecchiette
200.0000 outsidefettucine 300.0000
27
Better Planning Model
enum Products ... enum Resources ... struct
ProductData float demand float
insideCost float outsideCost float
consumptionResources ProductData
productProducts var float
insideProducts var float outsideProducts
28
Better Planning Model
minimize sum(p in Products)
(productp.insideCostinsidep
productp.outsideCostoutsidep ) subject to
forall(r in Resources) sum(p in
Products) productp.consumptionrinsidep lt
capacityr forall(p in Products)
insidep outsidep gt productp.demand

29
Linear Programming Example II
(1) An oil company sells three kinds of
gas name super regular diesel price 70
60 50 octane gt 10 gt 8 gt 6 lead lt 1 lt
2 lt 1 demand 3000 2000 1000 (2) These are
produced from three kinds of crude
oil name crude1 crude2 crude3 octane 12 6
8 lead 0.5 2.0 3.0 (3) If the company
advertises one of its products, it will
sell 10 barrels more per 1 spent on
advertising. (4) The cost of transforming oil
into gasoline is 4 (per barrel). (5) The
company can buy 5000 barrels of each crude oil
per day. (6) The maximum production capacity is
14000 barrels per day
30
Blending Problem (Declarations)
enum Gasolines ... enum Oils ... struct
GasType float demand float price
float octane float lead struct OilType
float capacity float price float
octane float lead
GasType gasGasolines ... OilType oilOils
... float maxProduction ... float prodCost
... var float aGasolines var float
blendOils,Gasolines
Advertising investment
blendo,g barrels o blended into barrels g
31
Blending Problem (Data)
Gasolines super regular diesel Oils
crude1 crude2 crude3 gas
ltdemand3000 price70 octane10 lead1 gt
ltdemand2000 price60 octane8 lead2 gt
ltdemand1000 price50 octane6 lead1 gt
oil ltcapacity5000 price45 octane12
lead0.5 gt ltcapacity5000 price35 octane6
lead2 gt ltcapacity5000 price25 octane8
lead3 gt maxProduction
14000 prodCost 4
32
Blending Problem (Model)
maximize sum(g in Gasolines, o in Oils)
(gasg.price - oilo.price - prodCost)
blendo,g - sum(g in Gasolines) ag subject
to forall(g in Gasolines) sum(o in
Oils) blendo,g gasg.demand 10ag
forall(o in Oils) sum(g in Gasolines)
blendo,g lt oilo.capacity sum(o in Oils,
g in Gasolines) blendo,g lt maxProduction
forall(g in Gasolines) sum(o in Oils)
(oilo.octane - gasg.octane) blendo,g gt
0 forall(g in Gasolines) sum(o in
Oils) (oilo.lead - gasg.lead) blendo,g lt
0
33
Multistage Planning Example
A company produces and sells three different
kinds of products. Each product can be produced
inside of the company from certain resources at a
fixed cost or bought at another cost from
outside. The company wants to decide which
amount to produce inside and which amount to buy
to satisfy a given customer demand. The company
can only produce a limited amount of each product
per month, but it can decide to produce more
than it sells and store the overproduction in an
inventory for later sale. Holding a product in
the inventory incurs a product-dependent storage
cost.
34
Multistage Planning (Declarations)
enum Products ... enum Resources ... int
nbPeriods ... range Periods 1..nbPeriods stru
ct Plan float inside float outside
float inv float consumptionResources,Produ
cts ... float capacityResources
... float demandProducts,Periods
... float insideCostProducts ... float
outsideCostProducts ... float
inventoryProducts ... float
invCostProducts ... var float
insideProducts,Periods var float
outsideProducts,Periods var float
invProducts,0..nbPeriods
Product Types
Resource Types
Time Period (Months)
only needed for result display
Initial Inventory Contents
Inventory Contents in Period i
35
Multistage Planning (Model)
minimize sum(p in Products, t in Periods)
(insideCostpinsidep,t
outsideCostpoutsidep,t
invCostpinvp,t) subject to forall(r in
Resources, t in Periods) sum(p in Products)
consumptionr,p insidep,t lt capacityr
forall(p in Products, t in Periods)
invp,t-1 insidep,t outsidep,t
demandp,t invp,t forall(p in
Products) invp,0 inventoryp
The crucial trick is to link the inventory from
time period t to t1 with the framed statement.
36
Multistage Planning (Output)
struct Plan float inside float
outside float inv Plan planp in
Products, t in Periods ltinsidep,t,
outsidep,t, invp,tgt
output, e.g. planprod1, 1 lt inside 5.00,
outside 7.50, inv 2.50 gt planprod1, 2 lt
inside 5.00, outside 1.50, inv 5.00 gt etc...
37
Constraint Programming in OPL
Q1
Q2
Q3
Q4
var int queens1..4 in 1..4 solve
forall(ordered i,j in 1..4) queensi
ltgt queensj queensi i ltgt
queensj j queensi - i ltgt
queensj - j
Variables
Constraints
38
Relations as Boolean Functions
All boolean expressions are treated as binary
values. Higher order expressions can be treated
as integer functions
int numbers0..max ... int counti in 0..max
sum(j in 0..max) (numbersji)
This generalizes to the use of other boolean
expressions (and), \/ (or), not, gt
(implication), ltgt (equivalence)
int numbers0..max ... Interval ranges0..max
... int count i in 0..max sum(j in
0..max) ( numbersj gt rangesi.low
numbersj lt rangesi.high )
39
Higher Order Constraints
Basic Constraints forall(t in tasks) t.end
gt t.startt.duration Boolean Combinations fora
ll ( ordered t1, t2 in tasks) t1.start gt
t2.startt2.length \/ t2.start gt
t1.startt1.length Higher Order counti
sum(j in 0..10) (sji)
40
Stable Marriages
A group of n women and n men must be grouped into
n couples such that if a man x prefers a woman y
to his own partner, then y must prefer her own
partner to x. (and vice versa) Otherwise the
couple is deemed unstable.
enum Women ... enum Men ... int
rankWomenWomen,Men ... int
rankMenMen,Women ... var Women
wifeMen var Men husbandWomen
41
Stable Marriages
solve forall(m in Men)
husbandwifem m forall(w in Women)
wifehusbandw w forall(m in Men o in
Women) rankMenm,o lt rankMenm,wifem
gt rankWomeno,husbando lt
rankWomeno,m forall(w in Women o in
Men) rankWomenw,o lt rankWomenw,husband
w gt rankMeno,wifeo lt
rankMeno,w
42
Magic Series
A magic series is a series of integers in which
the i-th integer is equal to the number of
occurrences of i in the series,
e.g. 1,2,1,0 (note that the first index is 0)
int n ltlt "Number of Variables" range Range
0..n-1 range Domain 0..n var Domain
sRange solve forall(i in Range) si
sum(j in Range) (sj i) sum(i in Range)
si n sum(i in Range) sii n
Higher Order
Redundant Constraints
Higher order constraints are handled internally
by using 0-1 variables.
43
Global Constraints
  • alldifferent(arr)
  • if all elements in the array arr are different
  • circuit(succ)
  • if the integer array succ interpreted as node
    labels such that
  • succi is the successor of node i
  • describes a Hamiltonian circuit
  • distribute(occ, val, arr)
  • if occi is the count of vali in the array arr

// Magic Series with Global Constraints range
Range 0..n-1 range Domain 0..n int valuei in
Range i var Domain sRange solve
distribute(s,value,s)
44
Constraint Programming
  • Constraint programming uses backtracking search
    in combination with consistency based methods to
    reduce the domain of the finite domain variables.
  • The shape and size of the resulting search tree
    depends on the order in which variables are
    chosen to be labelled I.e. given a value and
    in what order the values in the variables domain
    are tried.
  • To see this consider
  • X?Y, Y?Z, Z?X
  • D(X) 1,2, D(Y)1,2, D(Z)1,2,3
  • and the different trees that will result when
    using arc consistency in combination with
    backtracking search

45
Search in OPL
  • OPL allows the modeller to control how the search
    tree is
  • constructed by specifying the order in which to
    label variables
  • and the order in which to try values.
  • It provides a mini-programming language for
    specifying the
  • search procedure
  • choice
  • iteration
  • conditional construct
  • local variables

46
Search--Simple Example
var int queen1..4 in 1..4 solve forall
(ordered i, j in 1..4) queeni ltgt
queenj queenii ltgt queenjj queeni-i
ltgt queenj-j search forall(i in
1..4) tryall(v in 1..4) queeniv
Specify variables to label
Specify values to try
Add constraint
47
Basic Search
search try x1v11 x1v12 ... x1v1m1
endtry try x2v21 x1v22 ... x1v2m2
endtry ... try xnvn1 xnvn2 ...
xnvnm1 endtry
  • Assigns values to each of the xi in turn in
    ascending order.
  • Values are tried in the order of occurrence.
  • Generates a backtracking search tree with
  • levels corresponding to variables
  • order of branches on level i corresponding to
    values vij

48
Search
search try queen11 queen12
queen13 queen14 endtry try queen21
queen22 queen23 queen24 endtry try
queen31 queen32 queen33 queen34
endtry try queen41 queen42
queen43 queen44 endtry
search
queen11
queen12
queen21
queen24
...
queen21
queen24
...
queen31
queen41
queen43
...
v
49
Tryall
search forall(i in 1..4) tryall(v in
1..4) queeniv
equivalent to
search try queen11 queen12
queen13 queen14 endtry try queen21
queen22 queen23 queen24 endtry try
queen31 queen32 queen33 queen34
endtry try queen41 queen42
queen43 queen44 endtry
tryall(var in Bounds) Relation Order
try all even numbers from 100 down to 2 tryall(x
in 1..100 x mod 2 0 ordered by decreasing x)
50
Search Quantifiers
forall(v in Range Relation Order)
specifies the variables to be labelled (like
universal quantification or iteration) Dynamic
ordering can be used dsize(x) domain
size dmax(x) maximum value in domain dmin(x) min
imum value in domain These allow the modeller to
specify heuristics
51
First Fail Search Heuristic
A good heuristic is to fail as quickly as
possible this is called the first-fail
heuristic I.e. choose the variable with the
smallest domain to label next
search forall(i in 1..4 ordered by increasing
dsize(queeni)) tryall(v in 1..4) queeniv

52
Choice in Search
Conditionals can be used inside search
search forall(I in 1..10) if I mod 10 0
then tryall(v in 1..10 ordered by increasing
I) xIv else tryall(v in 1..10 ordered
by decreasing I) xIv endif
Note The choices in a try instruction can be
general constraints (and not only equations)
53
Iterative Search
while Relation do Choice... iterates a choice
statement until the condition becomes true.
search while not bound(x) do let mdmin(x)
in try xm x ltgt m endtry
The select instruction allows selection of data
satisfying some condition
Note The choices in a try instruction can be
general constraints (and not only equations)
54
Linear Relaxation
A reflective function allows direct access to the
linear relaxation (Simplex value). Branch and
bound can therefore be programmed by the search
instruction
while not bound(x) do let vsimplexValue(x)
in let ffloor(v) in let cceiling(v)
in try x lt f x gt c endtry
We can use local variables let VarExpression
in Choice binds a new local variable
55
Predefined Search
if no special search strategy is required
simplified built-in search procedures can be
used.
search forall(i in 1..4) tryall(v in
1..4) queeniv
search forall(i in 1..4) generate(queeni)

Generate also extends canonically to arrays
search generate(queen)
generateSize(x) in increasing order of dsize(x)
(generate) generateMin in increasing order of
dmin(x) generateMax in increasing order of
dmax(x)
56
Data-driven Constructs
As part of the search one can include constraint-
or data-driven expressions. when openw 0
do forall(c in Customers) supplyc ltgt
w Addition of this constraint is delayed until
openw 0 holds. I.e. when it is first
encountered openw 0 is checked to see if it
holds, if so the body is executed, if it
definitely does not then the constraint is
deleted and if the value of openw is not known
then the constraint suspends until the value is
set. Apart from when OPL provides onValue,
onRange and onDomain.
57
Integer Programming Example
Problem a company wants to build a number of
warehouses to supply its stores. (1) There is a
universal fixed maintenance cost for every
warehouse. (2) There is an individual maximum
capacity (stores) for each warehouse. (3) The
transport costs depend on the warehouse and the
supplied store. (4) Each store must be supplied
by a single warehouse. (but a warehouse can
supply several stores)
58
Warehouse Problem (Declarations)
range Boolean 0..1 int fixed ... enum
Warehouses ... int nbStores ... range
Stores 0..nbStores-1 int capacityWarehouses
... int supplyCostStores,Warehouses
... var Boolean openWarehouses var Boolean
supplyStores,Warehouses
  • Decision Variables
  • Shall a warehouse be opened?
  • Which warehouse supplies which store?

59
Warehouse Problem (Data)
fixed 30 Warehouses Bonn,Bordeaux,London,Par
is,Rome nbStores 10 capacity
1,4,2,1,3 supplyCost 20, 24, 11,
25, 30 , 28, 27, 82, 83, 74 ,
74, 97, 71, 96, 70 , 2, 55, 73, 69,
61 , 46, 96, 59, 83, 4 , 42,
22, 29, 67, 59 , 1, 5, 73, 59, 56 ,
10, 73, 13, 43, 96 , 93, 35,
63, 85, 46 , 47, 65, 55, 71, 95
60
Warehouse Problem (Model)
minimize sum(w in Warehouses) fixed
openw sum(w in Warehouses, s in Stores)
supplyCosts,w supplys,w subject to
forall(s in Stores) sum(w in
Warehouses) supplys,w 1 forall(w in
Warehouses, s in Stores) supplys,w lt
openw forall(w in Warehouses)
sum(s in Stores) supplys,w lt
capacityw display open Stores
storesofw in Warehouses s s in Stores
supplys,w display storesof
61
Warehouse Problem with Constraints (Declarations)
int fixed ... int nbStores ... enum
Warehouses ... range Stores 0..nbStores-1 int
capacityWarehouses ... int
supplyCostStores,Warehouses ... var int
openWarehouses in 0..1 var Warehouses
supplierStores
  • New (Constraint) Decision Variables (in red)
  • Array of suppliers for each store indexed by store

62
Warehouse Problem (constraints)
Note the use of a variable as an array index
minimize sum(s in Stores)
supplyCosts,suppliers sum(w in
Warehouses) fixed openw subject to
forall(s in Stores ) opensuppliers
1 forall(w in Warehouses) sum(s in
Stores) (suppliers w) lt capacityw
Note the higher-order constraints these cannot
be rewritten as an integer program
63
Regret Heuristics
Idea Give priority to assignments for which
using the second best value causes the maximal
change in the objective. regretdmin(x)
Difference between two lowest values in
dom(x). regretdmax(x) Difference between two
highest values in dom(x).
search forall(s in Stores ordered by
decreasing regretdmin(costs)) tryall(w in
Warehouses ordered by increasing
supplyCosts,w) suppliers w
generateSeq(open)
  • Results in a search that
  • assigns the warehouse in order of maximal regret
    for
  • costs supplyCosts,suppliers
  • try possible suppliers in increasing order of
    supply cost
  • Note that generateSeq(open) uses default
    labelling to assign values
  • to variables in the array open

64
Warehouse Problem with Constraints
II (Declarations)
int fixed ... int nbStores ... enum
Warehouses ... range Stores 0..nbStores-1 int
capacityWarehouses ... int
supplyCostStores,Warehouses ... int maxCost
max(s in Stores, w in Warehouses)
supplyCosts,w var int openWarehouses in
0..1 var Warehouses supplierStores var int
costStores in 0..maxCost
  • New (Constraint) Decision Variables (in red)
  • supply cost for each store

65
Warehouse Problem II (constraints)
minimize sum(s in Stores) costs sum(w
in Warehouses) fixed openw subject to
forall(s in Stores) costs
supplyCosts,suppliers forall(s in Stores
) opensuppliers 1 forall(w in
Warehouses) sum(s in Stores) (suppliers
w) lt capacityw
66
Warehouse Problem (search heuristics)
The model is no longer a linear program, but we
can now easily specify a search heuristics!
search forall(s in Stores ordered by
decreasing regretdmin(costs)) tryall(w in
Warehouses ordered by increasing
supplyCosts,w) suppliers w
generateSeq(open)
67
Integration of IP and CP
Linear Integer Programming and Constraint
Programming can often be used for the same
problem. Their advantages are complementary
Linear IP / 0-1 Programming Constraint
Programming faster algorithms - search
required - complicated modelling high
expressiveness - little influence on search
explicit heuristics
  • Combining both approaches can be done by
  • linking constraint variables with integer
    variables (using constraints)
  • using linear relaxation on numerical constraint
    variables.

68
Integrated Warehouse Model
  • We can now integrate both models in order to
    utilize a combination of
  • linear programming algorithms
  • constraint propagation
  • search heuristics
  • Steps for combining the models
  • copy one model into the other
  • link constraint variables with integer variables
    (using constraints)
  • forall(s in Stores)
  • supplys,suppliers 1
  • forall(s in Stores)
  • costs sum(w in Warehouses)
    supplyCosts,w supplys,w
  • use a linear objective and instruct OPL to use
    linear relaxation
  • minimize with linear relaxation
  • sum(w in Warehouses) fixed openw
  • sum(w in Warehouses, s in Stores)
    supplyCosts,w supplys,w

69
Revised Warehouse Model (Declarations)
range Boolean 0..1 int fixed ... int
nbStores ... enum Warehouses ... range
Stores 0..nbStores-1 int capacityWarehouses
... int supplyCostStores,Warehouses
... int maxCost max(s in Stores, w in
Warehouses) supplyCosts,w var Boolean
openWarehouses var Boolean supplyStores,Wareho
uses var Warehouses supplierStores var int
costStores in 0..maxCost
shared
70
Integrated Warehouse Model
minimize with linear relaxation sum(w in
Warehouses) fixed openw sum(w in
Warehouses, s in Stores) supplyCosts,w
supplys,w subject to forall(s in
Stores) sum(w in Warehouses)
supplys,w 1 forall(w in Warehouses, s
in Stores) supplys,w lt openw
forall(w in Warehouses) sum(s in Stores)
supplys,w lt capacityw forall(s in
Stores) costs supplyCosts,suppliers
forall(s in Stores
) opensuppliers 1 forall(w in
Warehouses) sum(s in Stores)
(suppliers w) lt capacityw
forall(s in Stores) supplys,suppliers 1
forall(s in Stores) costs sum(w
in Warehouses) supplyCosts,w supplys,w
71
Scheduling
  • OPL provides specialised data types and search
    strategies for
  • modelling and solving scheduling and resource
    allocation
  • applications.
  • The basic model is that you schedule activities.
    An activity a has
  • a starting time start
  • a duration duration
  • a finish time end
  • an implicit constraint that a.end
    a.starta.duration
  • Activity carpentry
  • carpentry.duration 10
  • Activities can be optionally initialised with
    their duration
  • Activity carpentry(10)
  • var int durationCarpentry in 8..10
  • Activity carpentry(durationCarpentry)

72
Scheduling
Activities are scheduled over the global-time
interval scheduleOrigen,scheduleHorizon Both
scheduleOrigen and scheduleHorizon must be
initialised before declaring schedule
activities. scheduleOrigen 0 scheduleHorizon
364 Typically one adds constraints on the
order of activities b.start gt a.end a
precedes b
73
Resources
Activities can require or consume resources. A
unary resource is a resource than cannot be
shared by two activities. UnaryResource
crane Activity excavation(3) excavation
requires crane A discrete resource with
capacity n has n different instances of the
resource DiscreteResource crane(4) excavation
requires(2) crane Sometimes an activity
consumes the resource, I.e. it is not
available afterwards DiscreteResource
budget(1000) excavation consumes(2000) budget
74
Breakable Resources
In the real-world there may be periods such as
the weekend in which a resource is unavailable.
These periods are often called breaks.
periodicBreak(crane,5,2,7) break(crane,10,12)
Activities may or may not be interuptable by
breaks. By default they are not
breakable Activity excavation breakable More
generally one can vary the capacity of a discrete
resource over time capacityMax(crane,10,12,4) ca
pacityMin(crane,1,20,2)
75
Reservoirs
Sometimes activities may themselves generate the
resources needed by other activities. Resources
that can be created and used by activities are
called reservoirs Reservoir Budget(20000) Activ
ity produceWidget, sellWidget produceWidget
consumes(1000) Budget sellWidget provides(1200)
Budget
76
Reservoirs
Sometimes activities may themselves generate the
resources needed by other activities. Resources
that can be created and used by activities are
called reservoirs Reservoir Budget(20000) Activ
ity produceWidget, sellWidget produceWidget
consumes(1000) Budget sellWidget provides(1200)
Budget
77
House Scheduling
enum Tasks masonry, carpentry, plumbing,
ceiling, roofing, painting int
durationTasks 7,3,8,3,1,2 Activity at in
Tasks(duration(t)) DiscreteResource
budget(24000) minimize apainting.end subjec
t to amasonry precedes acarpentry amason
ry precedes aplumbing amasonry precedes
aceiling acarpentry precedes
aroofing acarpentry precedes
apainting aceiling precedes
apainting capacityMax(budget,0,15,20000) f
orall(t in Tasks) at consumes(1000durationt
) budget
78
House Scheduling
Optimal solution with Objective value
20 amasonry 0 -- 7 --gt 7 acarpentry 7
-- 3 --gt 10 aplumbing 7 -- 8 --gt
15 aceiling 15 -- 3 --gt 18 aroofing
10 -- 1 --gt 11 apainting 18 -- 2 --gt 20
79
Where is it???
  • Installed on honspc06 and honspc09-14. 8
    machines in total
  • OPLstudio binary
  • /usr/local/ilog/bin/i86_linux2_glibc2.1_egcs1.1/o
    plst
  • MUST set ILOG_LICENSE_FILE to /usr/local/ilog/acce
    ss.ilm
  • Xwin needs to be set to 16 bit done
    automatically startx -- -bpp 16
  • Report problems to
  • tech_at_help.csse.monash.edu.au (cc me)

80
OPLStudio
  • It is installed on honspc01-15 under Windows XP
    but only 10
  • users can use it at a time.
  • Report problems to
  • tech_at_help.csse.monash.edu.au (cc me)

81
Summary
  • In this unit we have looked at the modelling
    language OPL
  • Structure and Syntax
  • Modelling Linear Problems in OPL
  • Constraint Programming in OPL

Homework
  • Read P. van Hentenryck, The OPL Optimization
    Programming Language
  • Trace the examples of this lecture in OPL Studio
About PowerShow.com