0% found this document useful (0 votes)
26 views7 pages

Exam2 SA

The document describes a linear programming problem involving the production of two food products, A and B, from products X and Y. The problem aims to minimize the total time required to separate the components from X and Y given demands for A and B, time constraints, and limits on purchasing X and Y. The linear program is modeled and solved using R, and the basic variables and dual linear program are identified.

Uploaded by

PIPO C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

Exam2 SA

The document describes a linear programming problem involving the production of two food products, A and B, from products X and Y. The problem aims to minimize the total time required to separate the components from X and Y given demands for A and B, time constraints, and limits on purchasing X and Y. The linear program is modeled and solved using R, and the basic variables and dual linear program are identified.

Uploaded by

PIPO C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Exam 2

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.

LINEAR PROGRAMMING MODEL


The first thing i have to define is the variables of the model. In particular is important to define the name
of the variable, the type of the variable and the possible values the variables can take. In this problem is
possible to define the following variables:
a) QX which represents the quantity in kg of the product X. QX is a real variable and can assume only
nonnegative values.
b) QY which represents the quantity in kg of the product Y. QY is a real variable and can assume only
nonnegative values.
The next step is to define the function of the model which i want to optimize.
In this problem i have to minimize the total extraction time.
The fuction is composed by the time in hours required for the separation of each component in each product
multiplied by the respective quantity in kg. The function is the following one:
[M in]ext = 5QX + 3QY
Let’s focus on the first term of the function in order to understand if it has been built a function which
represents the time: 5 is the number of hours are required to extract each kg of QX, so the unit of measure
h
is kg while the unit of meausre of QX is kg. So when we multiply these two terms the unit of measure we
obtain is hour (h).
The final step of this part is to define the constraints and assign them a name. In particular in this problem
there are the following constraints
a) Quantity constraint on X “qntX ”: the maximum quantity of X which is possible to buy is 150 kg:
QX ≤ 150
b) Quantity constraint on Y “qntY ”: the maximum quantity of Y which is possible to buy is 130 kg:
QY ≤ 130
c) Constraint on the demand of the product A “demA”: for producing 100 kg of A, which is the demand,
we need to combine 0.7kg of X and 0.3kg of Y: 0.7QX + 0.3QY ≥ 100
The text says that the demand is exactly 100 kg. However we preferred to use the ≥ constraint because
we have more flexibility in the model. The important thing is that the demand is not lower than 100.

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

RESOLUTION OF THE PREVIOUS LPM USING R WITH ITS


SENSIBILITY ANALYSIS
Now i am going to solve the linear model using the package “linprog”. This package can be used if we have
real variables. In our case, since there are only real variables, the constraint is fulfilled. Moreover this package,
differently from Rglpk, makes the sensibility analysis.
The first step is to charge the library:
library("linprog")

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")

Then i create a variable containing the coefficients of the constraint:


coeff_cons<-rbind(c(1,0),
c(0,1),
c(0.7,0.3),
c(0.3,0.7),
c(5,3))

Now i create a variable containing the sign of each contraint:


const<-c("<=", "<=", ">=", ">=", "<=")

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.

IDENTIFICATION OF THE BASIC VARIABLES OF THE PRE-


VIOUS LPM.
From the result it is possible to identify the basic variables which are:
1) QX
2) QY
3) qntX
4) demA
5) time
The number of basic variables is equal to the number of contraints. This means that we have a single solution.

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

RESOLUTION OF THE PREVIOUS DUAL LPM USING R


WITH ITS SENSIBILITY ANALYSIS
The first thing i have to do is to create a variable containing the coefficients of the function we want to
optimize and a variable containing the name of the variables:
ext_dual<-c(-150,-130,100,120,-950)
names(ext_dual)<-c("qntX", "qntY", "demA", "demB", "time")

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")

Then i create a variable containing the coefficients of the constraint:


coeff_cons_dual<-rbind(c(-1,0,0.7,0.3,-5),
c(0,-1,0.3,0.7,-3))

Now i create a variable containing the sign of each constraint:


const_dual<-c("<=","<=")

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.

IDENTIFICATION OF THE BASIC VARIABLES OF THE PRE-


VIOUS DUAL MODEL
In the dual model the number of constraints is equal to two. It means that i need two basic variables to have
a unique solution.
It is possible to see from the previous results that the basic variables are two and they are:
a) qntY = 8.67
b) demB = 16.67

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

## opt cvec min.c max.c marg marg.reg


## QX 96.666667 5 -8.714286 NA NA NA
## QY 130.000000 3 NA 11.666667 NA NA
## S qntX 53.333333 0 NA 3.714286 0.000000 NA
## S qntY 0.000000 0 -8.666667 Inf 8.666667 8.846154
## S demA 6.666667 0 -6.500000 NA 0.000000 NA
## S demB 0.000000 0 -16.666667 Inf 16.666667 4.600000
## S time 76.666667 0 NA 1.000000 0.000000 NA
Since the manager allows us to increase the value of 5, in both cases we are on the range and we can do the
sensibility analysis exploiting the column “marg”, which represents the multiplier rather than solving again
the problem with the change of the indipendent term.
So, if we increase the value of the indipendent term of “qntX ” we would obtain:
5 ∗ 0 = 0.
While if we increase the value of the indipendent term of “qntY ” we would obtain:
5 ∗ 8.67 = 43.35.
It means that in the first case the optimum value would remain equal to 873.33, while in the second case the
optimum value would be equal to:
873.33 − 43.35 = 829.98h
So, if the manager allows us to buy 5 kg more of X or Y we wuold choose the product X because it allows us
to achive a further reduction of the total extraction time.
2) There has been a change in the demand. The new demand of the product B is 125 kg instead of 120 kg.
How does this change affect the solution of the problem? How much does the cost increase or decrease
in the optimal solution?
From the results of the primary model it is possible to observe that the indipendent term of the constraint
related to the demand of the product B “demB” can icrease only by 4.6 units and so reaching the maximum
value of 124.6 products in order to remain in the feasible area (column “dual.reg”).
result$con

## actual dir bvec free dual dual.reg


## qntX 96.66667 <= 150 53.333333 0.000000 53.333333
## qntY 130.00000 <= 130 0.000000 8.666667 8.846154
## demA 106.66667 >= 100 6.666667 0.000000 6.666667

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

You might also like