Directions

What is the optimum solution? (c.f. Baltz an, 2012)

Back to the spellbook

1. Library

library(lpSolve)
## Warning: package 'lpSolve' was built under R version 4.2.2

2. Linear Optimisation

2.1 Coefficients of Objective Function

obj_coeff_spa <- c(400, 345)
obj_coeff_spa
## [1] 400 345

2.2 Constaints Coefficients

Set matrix corresponding to coefficients of constraints by rows.

constraints_coeff_spa <- matrix(c(15.5, 10.5,
                                   14.5, 20,
                                   1, 1),
                                 nrow = 3, byrow = TRUE)
constraints_coeff_spa
##      [,1] [,2]
## [1,] 15.5 10.5
## [2,] 14.5 20.0
## [3,]  1.0  1.0

Set inequalities signs.

constraints_dir_spa <- c("<=",
                          "<=",
                          "<=")
constraints_dir_spa
## [1] "<=" "<=" "<="

Set right hand side constraints.

constraints_rhs_spa <- c(2650,
                          3450,
                          231)
constraints_rhs_spa
## [1] 2650 3450  231

2.3 Linear Solution

optimum_spa <- lp(direction = "max",
                   objective.in = obj_coeff_spa,
                   const.mat = constraints_coeff_spa,
                   const.dir = constraints_dir_spa,
                   const.rhs = constraints_rhs_spa,
                   compute.sens = TRUE)
optimum_spa
## Success: the objective function is 75450.08

The final values

optimum_spa$solution
## [1] 106.33914  95.40412
optimum_spa$objval
## [1] 75450.08

2.4 Solution Evaluation

Reduced costs.

optimum_spa$sens.coef.from
## [1] 250.1250 270.9677
optimum_spa$sens.coef.to
## [1] 509.2857 551.7241
product_spa_name <- c("Luxury", "Original") 
coeff_spa_max <- optimum_spa$sens.coef.to
coeff_spa_min <- optimum_spa$sens.coef.from

coeff_spa <- obj_coeff_spa

solution_spa_reduced_cost <- data.frame(product_spa_name,
                                         coeff_spa,
                                         coeff_spa_max, 
                                         coeff_spa_min)
solution_spa_reduced_cost
##   product_spa_name coeff_spa coeff_spa_max coeff_spa_min
## 1           Luxury       400      509.2857      250.1250
## 2         Original       345      551.7241      270.9677

Shadow prices.

optimum_spa$duals
## [1] 19.001585  7.274168  0.000000  0.000000  0.000000
constraint_spa_name <- c("Labour", "Piping", "Pumps")
constraints_spa <- constraints_rhs_spa
shadow_price_spa <- optimum_spa$duals[1:3]

solution_spa_shadow_price <- data.frame(constraint_spa_name,
                                         constraints_spa,
                                         shadow_price_spa)
solution_spa_shadow_price
##   constraint_spa_name constraints_spa shadow_price_spa
## 1              Labour            2650        19.001585
## 2              Piping            3450         7.274168
## 3               Pumps             231         0.000000

3. Integer Optimisation

optimum_spa_int <- lp(direction = "max",
                   objective.in = obj_coeff_spa,
                   const.mat = constraints_coeff_spa,
                   const.dir = constraints_dir_spa,
                   const.rhs = constraints_rhs_spa,
                   int.vec = 1:2,
                   compute.sens = TRUE)
optimum_spa_int
## Success: the objective function is 75230

The final values

optimum_spa_int$solution
## [1] 107  94
optimum_spa_int$objval
## [1] 75230

May the force be with you