# Case Study 2
A manufacturing manager is in charge of minimizing the total costs (raw materials, labor and storage costs) of the following four months. In Table 3.1 can be found the cost of raw materials of one unit of final product, the demand of final product and the working hours available for each month. Labor costs are of 12 e per hour, and only worked hours are payed. Each unit of final product needs 30 minutes of labor. Storage costs are equal to 2 e for each unit stored at the end of the month. Any unit produced at a given month can be used to cover the demand of the same month, or be stored to cover the demand of months to come. At the beginning of month 1 there is no stock, and there are no minimum stock requirements for any month.
#calling the lpSolve
library(lpSolve)
#set coefficient of the objective function
f.obj <- c(2, 12)
#set matrix corresponding to coefficient of constraint by rows
#Don't consider the non-negative constraint, it is automatically assumed
f.con <- matrix(c(100, 400,
200, 400,
150, 300,
400, 300), nrow = 4, byrow = TRUE)
#set unequality signs
f.dir <- c(">=",
">=",
">=",
">=") #dir, a character vector specifying the types of constraints: each element must be one of "<=", "=", or ">=".
#set right hand side coefficients
f.rhs <- c(6, #rhs, a single numeric value specifying the right-hand-side of the constraint.
8,
10,
12)
#Final value (z)
lp("min", f.obj, f.con, f.dir, f.rhs)## Success: the objective function is 0.1333333
## [1] 0.06666667 0.00000000
## [1] 0 4
## [1] 6e+00 1e+30
# Dual Values (first dual of the constraints and then dual of the variables)
# Duals of the constraints and variables are mixed
lp("min", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$duals## [1] 0.00000000 0.00000000 0.01333333 0.00000000 0.00000000 8.00000000
*The minimum value of z obtained is 0.13333333, where x1 is 0.06666667, x2 is 0.00000000. The sensitivity coefficient changes from 0 and 4 to 6. 10^0 and 1.10^30
## Model name:
## C1 C2
## Minimize 0 0
## R1 0 0 free 0
## R2 0 0 free 0
## R3 0 0 free 0
## R4 0 0 free 0
## Kind Std Std
## Type Real Real
## Upper Inf Inf
## Lower 0 0
## $anti.degen
## [1] "none"
##
## $basis.crash
## [1] "none"
##
## $bb.depthlimit
## [1] -50
##
## $bb.floorfirst
## [1] "automatic"
##
## $bb.rule
## [1] "pseudononint" "greedy" "dynamic" "rcostfixing"
##
## $break.at.first
## [1] FALSE
##
## $break.at.value
## [1] -1e+30
##
## $epsilon
## epsb epsd epsel epsint epsperturb epspivot
## 1e-10 1e-09 1e-12 1e-07 1e-05 2e-07
##
## $improve
## [1] "dualfeas" "thetagap"
##
## $infinite
## [1] 1e+30
##
## $maxpivot
## [1] 250
##
## $mip.gap
## absolute relative
## 1e-11 1e-11
##
## $negrange
## [1] -1e+06
##
## $obj.in.basis
## [1] TRUE
##
## $pivoting
## [1] "devex" "adaptive"
##
## $presolve
## [1] "none"
##
## $scalelimit
## [1] 5
##
## $scaling
## [1] "geometric" "equilibrate" "integers"
##
## $sense
## [1] "minimize"
##
## $simplextype
## [1] "dual" "primal"
##
## $timeout
## [1] 0
##
## $verbose
## [1] "neutral"
#We define the objective function and the constraint
set.objfn(lprec, c(2, 12))
add.constraint(lprec, c(100, 400), ">=", 6)
add.constraint(lprec, c(200, 400), ">=", 8)
add.constraint(lprec, c(150, 300), ">=", 10)
add.constraint(lprec, c(400, 300), ">=", 12)
#Let's have a lookn at the LP problem we have defined
lprec## Model name:
## C1 C2
## Minimize 2 12
## R1 0 0 free 0
## R2 0 0 free 0
## R3 0 0 free 0
## R4 0 0 free 0
## R5 100 400 >= 6
## R6 200 400 >= 8
## R7 150 300 >= 10
## R8 400 300 >= 12
## Kind Std Std
## Type Real Real
## Upper Inf Inf
## Lower 0 0
## [1] 0
## [1] 0.1333333
#Let's finally get the values for how many acres of Wheat and Barley to be planted.
get.variables(lprec)## [1] 0.06666667 0.00000000