Exam2 SA
Exam2 SA
Lorenzo Capelli
07 January 2019
PROBLEM STATEMENT
G.C.R. produces two types of food: A and B. For producing 1 kg of A, we need to combine 0.7 kg of the
product X and 0.3 kg of the product Y. And for producing 1 kg of B, we need to combine 0.3 kg of the
product X and 0.7 kg of the product Y.
The total demand of A is 100 kg and of B is 120 kg.
The time required to separate A and B in the product X is 5 hours per kg, and in the product Y is 3 hours
per kg, where the total time we have to separate them is 950 hours.
The maximum quantity of the product X and Y we can buy is 150 kg and 130 kg respectively, and their cost
per kg is 2 and 3 euros. Since the cost depends on the quantity we are going to extract and since we do not
have any constraints on the budget, we can avoid to use these information in the first part. They could be
used in point 7 to compute the difference of costs.
1
d) Constraint on the demand of the product B “demB”: for producing 120 kg of B, which is the demand,
we need to combine 0.3kg of X and 0.7kg of Y: 0.3QX + 0.7QY ≥ 120
For the same reason of point c we preferred to use the ≥ constraint.
e) Constraint on the maximum time of extraction “time”: the maximum time available for the extraction
is equal to 950 hours : 5QX + 3QY ≤ 950
After that i create a variable containing the coefficients of the function we want to optimize and a variable
containing the names of the variables:
ext<-c(5,3)
names(ext)<-c("QX", "QY")
Now i create a variable containing the indipendent terms of the constraints and a variable containing the
name of the constraints:
coeff_ext<-c(150,130,100,120,950)
names(coeff_ext)<-c("qntX", "qntY", "demA", "demB", "time")
Finally i am going to use the function SolveLp to solve the linear programming model and print the result:
result<-solveLP(ext,coeff_ext,coeff_cons, maximum=FALSE,const.dir=const)
print(result)
##
##
## Results of Linear Programming / Linear Optimization
##
## Objective function (Minimum): 873.333
##
## Iterations in phase 1: 3
## Iterations in phase 2: 0
## Solution
## opt
## QX 96.6667
## QY 130.0000
2
##
## Basic Variables
## opt
## QX 96.66667
## QY 130.00000
## S qntX 53.33333
## S demA 6.66667
## S time 76.66667
##
## Constraints
## actual dir bvec free dual dual.reg
## qntX 96.6667 <= 150 53.33333 0.00000 53.33333
## qntY 130.0000 <= 130 0.00000 8.66667 8.84615
## demA 106.6667 >= 100 6.66667 0.00000 6.66667
## demB 120.0000 >= 120 0.00000 16.66667 4.60000
## time 873.3333 <= 950 76.66667 0.00000 76.66667
##
## All Variables (including slack variables)
## opt cvec min.c max.c marg marg.reg
## QX 96.66667 5 -8.71429 NA NA NA
## QY 130.00000 3 NA 11.66667 NA NA
## S qntX 53.33333 0 NA 3.71429 0.00000 NA
## S qntY 0.00000 0 -8.66667 Inf 8.66667 8.84615
## S demA 6.66667 0 -6.50000 NA 0.00000 NA
## S demB 0.00000 0 -16.66667 Inf 16.66667 4.60000
## S time 76.66667 0 NA 1.00000 0.00000 NA
The result proposed by SolveLp is:
QX = 96.67
QY = 130.00
It means that the the quantities of the product X and the product Y which minimize the extraction time are
respectively equal to 96.67 kg and 130.00 kg.
The minimum extraction time is equal to 873.33 hours.
We can see from the results that all the constraints are fulfilled.
3
DEFINITION OF THE DUAL OF THE LPM.
The starting point to write the dual model is to check the function of the original model.
Since we have a function which has to be minimize:
a) the greater than or equal constraints “demA”, “demB” are transformed in nonnegative variables.
b) the lesser than or equal constraints “qntX ”, “qntY ”, and “time” are transformed in non-positive variable.
Now i am going to write the new function. In order to do that i have to consider that the old constraint are
the new variables and the coefficient of the old constraints become the coefficient of the variables.
So the new function, which has to be maximize, is:
[M ax]ext = −5QX − 3QY
The coefficient of the variables “qntX ”, “qntY ”, and “time” become negative because now they are non-positive
variables.
Now i am going to write the new constraints. In order to do that i have to take into account that the old
variables become the new constraints and the coefficient of the old variables become the coefficient of the
constraints. Moreover, since in the original model there are two nonnegative variables, the dual model will
have two lesser than or equal constraints. Their names are the variables of the original model. So the new
constraints are:
a) “QX ”: -1qntX + 0.7demA + 0.3demB - 5time ≤ 5
b) “QY ”: -1qntY + 0.3demA + 0.7demB - 3time ≤ 3
Now i create a varaible containing the indipendent terms of the constraints and a variable containing the
name of the constraints:
coeff_ext_dual<-c(5,3)
names(coeff_ext_dual)<-c("QX","QY")
Finally i am going to use the function SolveLp to solve the linear programming model and print the result:
result_dual<-solveLP(ext_dual,coeff_ext_dual,
coeff_cons_dual, maximum=TRUE,const.dir=const_dual)
print(result_dual)
##
##
## Results of Linear Programming / Linear Optimization
4
##
## Objective function (Maximum): 873.333
##
## Iterations in phase 1: 0
## Iterations in phase 2: 3
## Solution
## opt
## qntX 0.00000
## qntY 8.66667
## demA 0.00000
## demB 16.66667
## time 0.00000
##
## Basic Variables
## opt
## qntY 8.66667
## demB 16.66667
##
## Constraints
## actual dir bvec free dual dual.reg
## QX 5 <= 5 0 96.6667 3.71429
## QY 3 <= 3 0 130.0000 Inf
##
## All Variables (including slack variables)
## opt cvec min.c max.c marg marg.reg
## qntX 0.00000 -150 -Inf -96.6667 -53.33333 Inf
## qntY 8.66667 -130 -135.000 -121.1538 NA NA
## demA 0.00000 100 -Inf 106.6667 -6.66667 6.50000
## demB 16.66667 120 117.143 124.6000 NA NA
## time 0.00000 -950 -Inf -873.3333 -76.66667 Inf
## S QX 0.00000 0 -Inf 96.6667 -96.66667 3.71429
## S QY 0.00000 0 -Inf 130.0000 -130.00000 Inf
The result proposed by SolveLp is:
a) qntX = 0.00
b) qntY = 8.67
c) demA = 0.00
d) demB = 16.67
e) time = 0.00
The optimal value of the function is equal to 873.33. This value is exactly equal to the value found in the
original problem. This means that the dual model has been created in the right way.
5
It is possible to notice that the basic variables of the dual model are exactly those variables which were not
basic in the original model. Also this thing is a characteristic of the dual model and it means that the dual
model has been created in the right way.
QUESTIONS
In this part i have to answer to two questions:
1) If the manager allows us to buy 5 kg more of X or Y. What would you decide?
The manager allows us to buy an higher quantity. It means that we are modifing the indipendent terms of
the constraint “qntX ” or “qntY ”. The first thing we have to do in order to resolve this question is to check if
we are in the range or not for doing the sensibility analysis on the coefficients without computing again the
solution. From the results obtained in point 2, analysing the column “marg.reg” we can notice that we can
increase the indipendent term of the constraint “qntX ” until infinite and we can increase the indipendent
term of the constraint “qntY ” until 8.85.
result$allvar
6
## demB 120.00000 >= 120 0.000000 16.666667 4.600000
## time 873.33333 <= 950 76.666667 0.000000 76.666667
In our case the demand of the product B increases by 5 units and this means we are going out of the ranges.
So the result is that if we increase the indipendent term of 5 units, we obtain a unfeasible solution.
Since we do not have any optimal solution we can not analyse the increase or decrease of the cost.
CONCLUSIONS
REFERENCES
[1] R Core Team (2016). R: A language and environment for statistical computing. R Foundation for
Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.
[2] Arne Henningsen (2017). linprog: Linear Programming / Optimization. R package version 0.9-2.
http://linprog.r-forge.r-project.org/
APPENDIX