Академический Документы
Профессиональный Документы
Культура Документы
Engineering
Dr. Evrim Ursavas
Getting Started
with Xpress-IVE and Mosel
language
Optimisation.
Problem definition & data
for parameters.
Real World
Model and
parameters.
Mathematical Model
Computer Program
NOTE: We will be using
XpressMP
Glossary of terms
Program Code
Binary Code
Compile
Array
Mathematical operators
Debugging
Operator
Add
Multiply
Divide
Symbol Used
+
*
/
Operator
Subtract
Exponent ("Power of")
Symbol Used
^
Looping
Xpress-IVE:
Xpress-Mosel:
Run model
Execution
options
620-362 Applied
Operations
Research
(XpressMP
lecture)
Compile model
Switch
between
models
Run Bar
Coding Window
Project
Bar
Information Bar
City 1
$8
$9
$14
45
City 2
$6
$12
$9
20
City 3
$10
$13
$16
30
City 4
$9
$7
$5
30
Balanced Transportation
Problem (BTP)
3
c x
Minimise
i =1 j =1
s.t.
ij
j =1
si = supply limit of
supply point i
= si , i
d j = demand amount of
demand point j
x
i =1
ij ij
ij
= d j , j
xij 0, i, j
12
13
14
15
16
declarations
UnitCost : array(1..10) of integer
end-declarations
initializations from Filename
UnitCost;
end-initializations
17
Cost:=2*x1+3*x2
!...constraints
minimize(Cost) !you dont need to declare Cost
or
Profit:=2*x1+3*x2
!...constraints
maximize(Profit) !you dont need to declare Profit
18
x1 + 3 x2 5 x3 8
(6) Constraints
! simple constraint
X1+3*X2-5*X3<=8
zi 1 for i = 1, .. ,10
10
x
i =1
! sum constraint
sum(i in 1..10) X(i)<=B
x
j =1
ij
=1
for i = 1, .. ,5
19
22
Modules
620-362 Applied
Operations
Research
(XpressMP
lecture)
23
Declarations
declarations
List1 = 1..10
List2 = 1..5
List3 = {Item1,Item2,Item3}
Var1: mpvar
Var2: array(List1) of mpvar
Var3: array(List1,List2) of mpvar
InputParam1: real
InputParam2: array(List1) of integer
InputParam3: array(List1,List3) of real
end-declarations
620-362 Applied
Operations
Research
(XpressMP
lecture)
24
Declarations (contd)
For BTP
620-362 Applied
Operations
Research
(XpressMP
lecture)
25
620-362 Applied
Operations
Research
(XpressMP
lecture)
Initialisation
declarations
List1 = 1..3
List2 = 1..2
InputParam1: array(List1) of integer
InputParam2: array(List1,List2) of real
InputParam3: array(List2,List2,List2) of real
end-declarations
! Initialise input parameters
InputParam1:= [1,2,3]
InputParam1
InputParam2:= [11,12,21,22,31,32]
InputParam2
InputParam3:= [111,112,121,122,211,212 ,221,222]
! initialisation for
! initialisation for
! initialisation for InputParam3
NOTE:
Data input from file is another method of parameter initialisation.
26
Initialisation (contd)
For BTP
620-362 Applied
Operations
Research
(XpressMP
lecture)
27
620-362 Applied
Operations
Research
(XpressMP
lecture)
Objective Function
ObjectiveName:= function
NOTE:
function can be be expressed in
a format very similar to a mathematical function, e.g. the objective for BTP
i =1 j =1
can be expressed in Mosel as
TotalCost:= sum(i in SUPPLY, j in DEMAND)
c(i,j)*x(i,j)
28
620-362 Applied
Operations
Research
(XpressMP
lecture)
Constraints
The following constraint
x
i =1
ij
1, j
x2 1
xn 1 1
xn 1
The corresponding generic version is
xi 1, i = 1,2,..., n
31
620-362 Applied
Operations
Research
(XpressMP
lecture)
Constraints (contd)
and the following constraint
xij 1, i < j
Constraints (contd)
Minimise c x
3
i =1 j =1
s.t.
For BTP
ij
= si , i
ij
= d j , j
j =1
3
x
i =1
ij ij
xij 0, i, j
32
620-362 Applied
Operations
Research
(XpressMP
lecture)
33
620-362 Applied
Operations
Research
(XpressMP
lecture)
Optimisation Statement
This is the easy bit:
If the objective function,
3
4
say TotalCost = cij xij
, is to be
i =1 j =1
minimised, then the following statement is needed:
minimise(TotalCost)
34
620-362 Applied
Operations
Research
(XpressMP
lecture)
Output
To display the objective value:
writeln(Objective value is , getobjval, .)
The output is Objective value is ##.,
displayed at the Output/Input pane of the
Run Bar.
To display the value taken by a decision variable:
writeln(The value of x is , getsol(x), .)
The output is The value of x is ##..
NOTE: write can also be used, instead of writeln. writeln
inserts a new line at the end of the output, write does not.
Output (contd)
For BTP
35
620-362 Applied
Operations
Research
(XpressMP
lecture)
Another Example
A Bin Packing Problem
PROBLEM
DEFINITION:
What is the minimum
Example1:
A Bin
number
of bins needed
to contain all items?
All items are of different
sizes and every bin has a
limit on its capacity.
Packing Problem
IP
formulation
Minimise
1, if item i in bin j
xijBin
= Packing (Contd)
otherwise
0,
1, if bin j is used
yj =
otherwise
0,
qi : size of item i
j =1
s.t. xij y j , i, j
n
x
=
j =1
Q j : capacity of bin j
ij
q x
i =1
i ij
1, i
Q j , j
xij {0,1} , i, j
y j {0,1} , j
xij y j , i, j
y
j =1
x
j =1
ij
= 1, i
q x
i =1
i ij
Q j , j
40
620-362 Applied
Operations
Research
(XpressMP
lecture)
if condition then
Action_if
end-if
43
620-362 Applied
Operations
Research
(XpressMP
lecture)
44