Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Introduction into Optimization GLPK model of examples
Mt Hegyhti 1
Department of Computer Science and Systems Technology Faculity of Information Technology University of Pannonia
Last modied: November 30, 2012
[email protected]
IntOpt - GLPK model of examples
http://dcs.uni-pannon.hu/hegyhati/oktatas
Mate Hegyhati - University of Pannonia, Hungary
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Contents
Introduction to GLPK Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK GLPK model of the examples Geothermal well installation Product mix Transportation problem Advanced GLPK model of the examples Geothermal well installation Product mix Transportation problem
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Optimization softwares
The previously mentioned (and other) optimization algorithms has been implemented in many general purpose optimization softwares.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Optimization softwares
The previously mentioned (and other) optimization algorithms has been implemented in many general purpose optimization softwares. COIN-OR open source linear optimization project OpenOpt free numerical optimization framework with automatic dierentiation features GLPK open source MILP/LP solver CLPEX Proprietary linear and quadratic optimization software Gurobi Proprietary linear and quadratic optimization software ...
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Optimization softwares
The previously mentioned (and other) optimization algorithms has been implemented in many general purpose optimization softwares. COIN-OR open source linear optimization project OpenOpt free numerical optimization framework with automatic dierentiation features GLPK open source MILP/LP solver CLPEX Proprietary linear and quadratic optimization software Gurobi Proprietary linear and quadratic optimization software ... These softwares dier in input format capabilities algorithms implementation
IntOpt - GLPK model of examples
Mate Hegyhati - University of Pannonia, Hungary
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
GUSEK,GLPK, and GMPL
In this course we use the GUSEK software
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
GUSEK,GLPK, and GMPL
In this course we use the GUSEK software, that is a graphical interface for the GLPK (GNU Linar Programming Kit) solver
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
GUSEK,GLPK, and GMPL
In this course we use the GUSEK software, that is a graphical interface for the GLPK (GNU Linar Programming Kit) solver, that can solve problems described in GMPL (GNU MathProg Language).
Mate Hegyhati - University of Pannonia, Hungary
Download GUSEK: http://sourceforge.net/projects/gusek/
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Files, commands
lename.mod the problem description in GMPL format lename.out the solution in GLPK format lename.d data le for the model (optional)
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Files, commands
lename.mod the problem description in GMPL format lename.out the solution in GLPK format lename.d data le for the model (optional) Check Tools
Generate Output File on Go.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Files, commands
lename.mod the problem description in GMPL format lename.out the solution in GLPK format lename.d data le for the model (optional) Check Tools
Generate Output File on Go. Test the model with Ctrl + F7, solve by F5.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Files, commands
lename.mod the problem description in GMPL format lename.out the solution in GLPK format lename.d data le for the model (optional) Check Tools
Generate Output File on Go. Test the model with Ctrl + F7, solve by F5.
If the model is bad the output of GLPK on the right pane gives some hints about the error good the solution le is opened in a new tab
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Declaring variables
The general format is to declare a variable:
var Vname
Options
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Declaring variables
The general format is to declare a variable:
var Vname
Options
where
Vname name of the variable (mandatory, and unique) Options some examples (optional, can be combined): >= 0 for nonnegative variables binary for binary variables integer for integer variables
var keyword for variable declaration (mandatory)
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Declaring variables
The general format is to declare a variable:
var Vname
Options
where
Vname name of the variable (mandatory, and unique) Options some examples (optional, can be combined): >= 0 for nonnegative variables binary for binary variables integer for integer variables Don't forget the semicolon at the end.
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
var keyword for variable declaration (mandatory)
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Constraints
The general format for a constraint:
s.t. Cname : Constraint ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Constraints
The general format for a constraint: where
s.t. Cname : Constraint ;
Cname name of the constraint (mandatory, and unique) Contraint constraint expression, use >=, =, <= for , =, for multiplication
s.t. "subject to", keyword for constraints (mandatory)
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Constraints
The general format for a constraint: where
s.t. Cname : Constraint ;
Cname name of the constraint (mandatory, and unique) Contraint constraint expression, use >=, =, <= for , =, for multiplication
s.t. "subject to", keyword for constraints (mandatory)
Pay attention to the use of colon and semicolon, it is a frequent source of syntactic errors.
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Objective function
The general format for the objective function:
Goal Oname : Objective ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Objective function
The general format for the objective function: where
Goal Oname : Objective ;
Oname name of the objective (mandatory, and unique) Objective expression of the objective.
Goal mandatory, either maximize or maximize
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Objective function
The general format for the objective function: where
Goal Oname : Objective ;
Oname name of the objective (mandatory, and unique) Objective expression of the objective. Pay attention to the use of colon and semicolon, it is a frequent source of syntactic errors.
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Goal mandatory, either maximize or maximize
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Names, Comments
Names
Should not contain spaces, dots, special characters.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Optimization tools in general GNU Linear Programing Kit - GLPK GNU MathProg Language - GLPK
Names, Comments
Names
Should not contain spaces, dots, special characters.
Comments
Comments can be left in the source the facilitate understanding Single line comments start with # Multiple line comments start with /* and end with */
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Reminder: the problem
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Reminder: the model
y1 y1 y1
+ +
y2
+
y2 y2
y4
+ +
y3 y3 y3 y4
+ + +
y5 y5 y5
1 1 1 1 1 1
y1 y2 y3 y4 y5
{0, 1}
y1
+ y2 + y3 + y4 + y5 min
IntOpt - GLPK model of examples
Mate Hegyhati - University of Pannonia, Hungary
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Variable declrations
y1 y2 y3 y4 y5
{0, 1}
var var var var var
y1 , y2 , y3 , y4 , y5 ,
binary ; binary ; binary ; binary ; binary ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Constrainsts
y1 y1 y1
+ +
y2
+
y2 y2
y4
+ +
y3 y3 y3 y4
+ + +
y5 y5 y5
1 1 1 1 1 1
s.t. s.t. s.t. s.t. s.t. s.t.
Ahmed : Alae : Mimi : Omar : Rajae : Zarioh :
y1 y1 y1 y2 y3 y4
+ + + + + +
y2 y4 y2 y3 y5 y5
>= 1 ; >= 1 ; + y3 >= 1 ; + y5 >= 1 ; >= 1 ; >= 1 ;
IntOpt - GLPK model of examples
Mate Hegyhati - University of Pannonia, Hungary
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Objective
y1
+ y2 + y3 + y4 + y5 min
minimize number_of_wells_to_intall : y1 + y2 + y3 + y4 + y5 ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Overall modell
var var var var var y1 , y2 , y3 , y4 , y5 , binary ; binary ; binary ; binary ; binary ; y 1 + y 2 >= 1 ; y 1 + y 4 >= 1 ; y 1 + y 2 + y 3 >= 1 ; y 2 + y 3 + y 5 >= 1 ; y 3 + y 5 >= 1 ; y 4 + y 5 >= 1 ;
s . t . Ahmed : s.t. s.t. s.t. s.t. Alae : Mimi : Rajae : Zarioh :
s . t . Omar :
minimize
number_of_wells_to_intall :
y1 + y2 + y3 + y4 + y5 ;
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Output le
Problem : Rows : Columns : Non z e r o s : Status : Objective : No . 1 2 3 4 5 6 7 model_simple 7 5 (5 i n t e g e r , 5 b i n a r y ) 19 INTEGER OPTIMAL n u m b e r _ o f _ w e l l s _ t o _ i n t a l l = 2 ( MINimum ) Activity 1 1 1 1 1 1 2 L o w e r bound 1 0 0 0 1 0 0 0 0 0 U p p e r bound 1 1 1 1 1 L o w e r bound 1 1 1 1 1 1 U p p e r bound
Row name
Ahmed Alae Mimi Omar Rajae Zarioh number_of_wells_to_intall
No . 1 2 3 4 5 Integer
Column name y1 y2 y3 y4 y5 feasibility
Activity
conditions : IntOpt - GLPK model of examples
Mate Hegyhati - University of Pannonia, Hungary
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Output le - Important parts
Status : Objective : INTEGER OPTIMAL n u m b e r _ o f _ w e l l s _ t o _ i n t a l l = 2 ( MINimum )
The optimal solution is found and its value is 2.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Output le - Important parts
Status : Objective : INTEGER OPTIMAL n u m b e r _ o f _ w e l l s _ t o _ i n t a l l = 2 ( MINimum )
The optimal solution is found and its value is 2.
No . 1 2 3 4 5
Column name y1 y2 y3 y4 y5
Activity
L o w e r bound 1 0 0 0 1 0 0 0 0 0
U p p e r bound 1 1 1 1 1
The values of the variables in the optimal solution (Activity column).
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Reminder: the problem
Shampoo Price (dh/l) 30 Cream 25 Conditioner 35 Lotion 40
Ingredients (kg/l) Herb 1 Herb 2 Herb 3 Herb 4 0.1 0.1 0.01 0.05 0.2 0.1 0.1 0.1 0.03 0.01 0.02 0.05
Stock(kg) 7 10 13 6
Footprints (kg/l) Water
Limit(kg) 5 2.0 3 3.5 3 2.2 2 4.2 400 350
CO2
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Reminder: the model
0.1 xSh 0.1 xSh 0 xSh 0 xSh 5 xSh 2.0 xSh
+ 0.01 xCr + 0.05 xCr + 0.2 xCr + 0 xCr + 5 xCr + 3.5 xCr + + + + + +
0 xCo 0.1 xCo 0.1 xCo 0.1 xCo 5 xCo 2.2 xCo
+ + + + + +
0.03 xLo 0.01 xLo 0.02 xLo 0.05 xLo 2 xLo 4.2 xLo
7 10 13 6 400 350
Sh , xCr , xCo , xLo [0, [
30 xSh + 25 xCr + 35 xCo + 40 xLo max
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Variable declrations
Sh , xCr , xCo , xLo [0, [
var var var var
xSh xCr xCo xLo
>=0; >=0; >=0; >=0;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Constrainsts
0.1 0.1
xSh xSh 0 xSh 0 xSh 5 xSh 2.0 xSh
+ + + + + +
0.01 0.05
xCr xCr 0.2 xCr 0 xCr 5 xCr 3.5 xCr
+ + + + + +
xCo xCo 0.1 xCo 0.1 xCo 5 xCo 2.2 xCo
0 0.1
+ + + + + +
0.03 0.01
xLo xLo 0.02 xLo 0.05 xLo 2 xLo 4.2 xLo
7 10 13 6 400 350
s.t.
Herb1 : 0 . 1 xSh + 0 . 0 1 x C r + 0 . 0 3 xLo <= 7 ; Herb2 : 0 . 1 xSh + 0 . 0 5 x C r + 0 . 1 xCo + 0 . 0 1 xLo <= 1 0 ; Herb3 : 0 . 2 x C r + 0 . 1 xCo + 0 . 0 2 xLo <= 1 3 ; Herb4 : 0 . 1 xCo + 0 . 0 5 xLo <= 6 ; Water : 5 xSh + 3 x C r + 3 xCo + 2 xLo <= 4 0 0 ;
s.t.
s.t.
s.t.
s.t.
s . t . CO2 : 2 xSh + 3 . 5 x C r + 2 . 2 xCo + 4 . 2 xLo <= 3 5 0 ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Objective
30 xSh + 25 xCr + 35 xCo + 40 xLo max
maximize p r o f i t : 30 xSh + 25 xCr + 35 xCo + 40 xLo ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Overall modell
var var var var s.t. xSh xCr xCo xLo >=0; >=0; >=0; >=0;
Herb1 : 0 . 1 xSh + 0 . 0 1 x C r + 0 . 0 3 xLo <= 7 ; Herb2 : 0 . 1 xSh + 0 . 0 5 x C r + 0 . 1 xCo + 0 . 0 1 xLo <= 1 0 ; Herb3 : 0 . 2 x C r + 0 . 1 xCo + 0 . 0 2 xLo <= 1 3 ; Herb4 : 0 . 1 xCo + 0 . 0 5 xLo <= 6 ; Water : 5 xSh + 3 x C r + 3 xCo + 2 xLo <= 4 0 0 ;
s.t.
s.t.
s.t.
s.t.
s . t . CO2 : 2 xSh + 3 . 5 x C r + 2 . 2 xCo + 4 . 2 xLo <= 3 5 0 ; maximize p r o f i t : 30 xSh + 25 x C r + 35 xCo + 40 xLo ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Output le - Important parts
Status : Objective :
OPTIMAL p r o f i t = 4294.137931
(MAXimum)
The maximal prot is 4294.137931.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Output le - Important parts
Status : Objective :
OPTIMAL p r o f i t = 4294.137931
(MAXimum)
The maximal prot is 4294.137931. It can be achieved by producing 39.52 l of shampoo, 37.59 l of Conditioner, and 44.83 l of Lotion:
No . 1 2 3 4 Column name xSh xCr xCo xLo St B NL B B Activity 39.5172 0 37.5862 44.8276 L o w e r bound 0 0 0 0 U p p e r bound Marginal
8.46552
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Reminder: the problem
Distance (km) Berkane Driouch Errachidia Demand
Talsint Khouribga Ouarzazate Nador 500 600 1200 80 700 600 1000 60 100 700 500 600 50 100 250 150
IntOpt - GLPK model of examples
Stock 100 150 300
Mate Hegyhati - University of Pannonia, Hungary
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Reminder: the model
x
B T + xB K + xB O + xB N = 100 xD T + xD K + xD O + xD N = 150 xE T + xE K + xE O + xE N = 300 B T + xD T + xE T = 50 xB K + xD K + xE K = 100
x
B O + xD O + xE O = 250 xB N + xD N + xE N = 150
minimize: 500 xB T + 600 xB K + 1200 xB O + 80 xB N + 700 xD T + 600 xD K + 1000 xD O + 60 xD N + 100 xE T + 700 xE K + 500 xE O + 600 xE N
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
B T , xB K , xB O , xB N , xD T , xD K , xD O , xD N , xE T , xE K , xE O , xE N 0
x
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Variable declrations
B T , xB K , xB O , xB N , xD T , xD K , xD O , xD N , xE T , xE K , xE O , xE N 0
x
v a r xBT>=0; v a r xBK>=0; v a r xBO>=0; v a r xBN>=0; v a r xDT>=0; v a r xDK>=0; v a r xDO>=0; v a r xDN>=0; v a r xET>=0; v a r xEK>=0; v a r xEO>=0; v a r xEN>=0;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Constrainsts
xB T + xB K + xB O + xB N = 100
xB T +xD T +xE T
= 50
xD T + xD K + xD O + xD N = 150 xE T + xE K + xE O + xE N = 300
s . t . Supply_Berkane : xBT + xBK + xBO + xBN = 1 0 0 ; s . t . Supply_Driouch : xDT + xDK + xDO + xDN = 1 5 0 ; s . t . Supply_Errachidia : xET + xEK + xEO + xEN = 3 0 0 ; s . t . Demand_Talsint : xBT + xDT + xET = 5 0 ; s . t . Demand_Khouribga : xBK + xDK + xEK = 1 0 0 ; s . t . Demand_Ouarzazate : xBO + xDO + xEO = 2 5 0 ; s . t . Demand_Nador : xBN + xDN + xEN = 1 5 0 ; Mate Hegyhati - University of Pannonia, Hungary
xB K +xD K +xE K = 100 xB O +xD O +xE O = 250 xB N +xD N +xE N = 150
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Objective
minimize: 500 xB T + 600 xB K + 1200 xB O + 80 xB N + 700 xD T + 600 xD K + 1000 xD O + 60 xD N + 100 xE T + 700 xE K + 500 xE O + 600 xE N
minimize transportation_cost : 500 xBT + 600 xBK + 1200 xBO + 80 xBN + 700 xDT + 600 xDK + 1000 xDO + 60 xDN + 100 xET + 700 xEK + 500 xEO + 600 xEN ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Overall modell
v a r xBT>=0; v a r xBK>=0; v a r xBO>=0; v a r xBN>=0; v a r xDT>=0; v a r xDK>=0; v a r xDO>=0; v a r xDN>=0; v a r xET>=0; v a r xEK>=0; v a r xEO>=0; v a r xEN>=0;
s . t . Supply_Berkane : xBT + xBK + xBO + xBN = 1 0 0 ; s . t . Supply_Driouch : xDT + xDK + xDO + xDN = 1 5 0 ; s . t . Supply_Errachidia : xET + xEK + xEO + xEN = 3 0 0 ; s . t . Demand_Talsint : xBT + xDT + xET = 5 0 ; s . t . Demand_Khouribga : xBK + xDK + xEK = 1 0 0 ; s . t . Demand_Ouarzazate : xBO + xDO + xEO = 2 5 0 ; s . t . Demand_Nador : xBN + xDN + xEN = 1 5 0 ; minimize transportation_cost : 500 xBT + 600 xBK + 1200 xBO + 80 xBN + 700 xDT + 600 xDK + 1000 xDO + 60 xDN + 100 xET + 700 xEK + 500 xEO + 600 xEN ; Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Output le - Important parts
Status : Objective : OPTIMAL t r a n s p o r t a t i o n _ c o s t = 199000 ( MINimum )
The minimal cost is 199000.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Output le - Important parts
Status : Objective : OPTIMAL t r a n s p o r t a t i o n _ c o s t = 199000 ( MINimum )
The minimal cost is 199000. It can be achieved by the following transportation plan:
No . 1 2 3 4 5 6 7 8 9 10 11 12 Column name xBT xBK xBO xBN xDT xDK xDO xDN xET xEK xEO xEN St NL B NL B NL NL NL B B B B NL Activity 0 100 0 0 0 0 0 150 50 0 250 0 L o w e r bound 0 0 0 0 0 0 0 0 0 0 0 0 IntOpt - GLPK model of examples U p p e r bound Marginal 500 800 720 20 620
420
Mate Hegyhati - University of Pannonia, Hungary
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Advanced GLPK models
If the data of the problem (number of wells, products, shops, . . . ) changes, the structure of the mathematical model remains the same, if the problem is the same.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Advanced GLPK models
If the data of the problem (number of wells, products, shops, . . . ) changes, the structure of the mathematical model remains the same, if the problem is the same. The model can be separated from the data, as it is not dependent on the data itself.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Advanced GLPK models
If the data of the problem (number of wells, products, shops, . . . ) changes, the structure of the mathematical model remains the same, if the problem is the same. The model can be separated from the data, as it is not dependent on the data itself. If the moel and the data is in one le, the le should be built like this: 1. Model section (variables, constraints, objective function) 2. data; (Keyword) 3. Data section (sets, parameter values, etc.) 4. end; (Keyword)
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Sets and parameters
Instead of using the values of the exact problem, sets and parameters are introduced, that takes values in the data section.
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Sets and parameters
Instead of using the values of the exact problem, sets and parameters are introduced, that takes values in the data section. Declarations extended:
set Sname ; param Pname ; var Vname ; s.t. Cname : Constraint ; minimize/maximize Oname: Objective ;
{Domain}, default Nvalue {Domain} Options {Domain}
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Well installation example - model section
set set Houses ; Wells ; c o v e r s {w i n Wells , Wells } , in h in Houses } , default 0;
param var s.t.
i n s t a l l {w i n
binary ;
House_cover {h Wells }
Houses } :
sum{w i n minimize
i n s t a l l [w]
c o v e r s [ w , h ] >= 1 ;
number_of_installed_wells : Wells } i n s t a l l [w ] ;
sum{w i n data ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Well installation example - data section
data ; set set H o u s e s := A l a e Ahmed Mimi W e l l s := W1 W2 W3 W4 W5 ; covers Alae W1 W2 W3 W4 W5 ; end ;
Mate Hegyhati - University of Pannonia, Hungary IntOpt - GLPK model of examples
Z a r i o h Omar R a j a e ;
param
: Ahmed 1 1 . . . Mimi 1 1 1 . . Zarioh . . . 1 1 Omar . 1 1 . 1 R a j a e := . . 1 . 1
1 . . 1 .
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Product mix - model section
set set
Products ; Resources ; ingredient{r p r i c e {p stock { r in in in in Resources , p in Products } , default 0;
param param param var
Products }; Resources }; P r o d u c t s }>=0;
q u a n t i t y {p
s . t . stock_constraint { r in Resources }: sum{ p i n P r o d u c t s } q u a n t i t y [ p ] i n g r e d i e n t [ r , p ] <= s t o c k [ r ] ; maximize p r o f i t : sum{ p i n P r o d u c t s } data ;
p r i c e [ p ] quantity [ p ] ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Product mix - data section
data ; set set P r o d u c t s := Shampoo Cream C o n d i t i o n e r L o t i o n ; R e s o u r c e s := H e r b 1 H e r b 2 H e r b 3 H e r b 4 Water CO2 ; param ingredient : Shampoo Herb1 0.1 Herb2 0.1 Herb3 . Herb4 . Water 5 CO2 2
Cream 0.01 0.05 0.2 . 3 3.5
Conditioner . 0.1 0.1 0.1 3 2.2
Lotion 0.03 0.01 0.02 0.05 2 4.2
:=
param p r i c e := Shampoo Cream Conditioner Lotion ; param s t o c k := Herb1 7 H e r b 2 10 H e r b 3 13 Herb4 6 Water 400 CO2 350 ;
30 25 35 40
Mate e n d ; Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Transportation problem - model section
set set
Farms ; Shops ; distance {f in Farms , s in Shops } , default 999999;
param
param s t o c k { f i n Farms } ; param demand { s i n S h o p s } ; var transported {f in Farms , s in S h o p s }>=0;
s . t . S u p p l y { f i n Farms } : sum{ s i n S h o p s } t r a n s p o r t e d [ f , s ] = s t o c k [ f ] ; s . t . Demand{ s i n S h o p s } : sum{ f i n Farms } t r a n s p o r t e d [ f , s ] = demand [ s ] ; minimize transportation_cost : sum{ f i n Farms , s i n S h o p s } data ;
transported [ f , s ] d i s t a n c e [ f , s ] ;
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Geothermal well installation Product mix Transportation problem
Transportation problem - data section
data ; set set Farms := B e r k a n e S h o p s := T a l s i n t Driouch E r r a c h i d i a ; Khouribga Ouarzazate Khouribga 600 600 700
N ador ; Nad or 80 60 600 :=
param d i s t a n c e : Berkane Driouch Errachidia ; param s t o c k := Berkane 100 Driouch 150 E r r a c h i d i a 300 ; param demand := Talsint 50 Khouribga 100 O u a r z a z a t e 250 Nado r 150 ;
Talsint 500 700 100
Ouarzazate 1200 1000 500
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples
Introduction to GLPK GLPK model of the examples Advanced GLPK model of the examples
Lake Balaton at sunset
Mate Hegyhati - University of Pannonia, Hungary
IntOpt - GLPK model of examples