The Battle of Hoth

Directions

What is the optimum production mix?

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_hoth <- c(75, 50, 25)
obj_coeff_hoth
## [1] 75 50 25

2.2 Constaints Coefficients

Set matrix corresponding to coefficients of constraints by rows.

constraints_coeff_hoth <- matrix(c(6, 4, 4,
                              1, 1.5, 0,
                              4, 2, 1,
                              0, 0, 2,
                              -2, 1, 0), 
                            nrow = 5, byrow = TRUE)
constraints_coeff_hoth
##      [,1] [,2] [,3]
## [1,]    6  4.0    4
## [2,]    1  1.5    0
## [3,]    4  2.0    1
## [4,]    0  0.0    2
## [5,]   -2  1.0    0

Set inequalities signs.

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

Set right hand side constraints.

constraints_rhs_hoth <- c(84,
                          21,
                          30,
                          10,
                          0)
constraints_rhs_hoth
## [1] 84 21 30 10  0

2.3 Linear Solution

optimum_hoth <- lp(direction = "max",
                   objective.in = obj_coeff_hoth,
                   const.mat = constraints_coeff_hoth,
                   const.dir = constraints_dir_hoth,
                   const.rhs = constraints_rhs_hoth,
                   compute.sens = TRUE)
optimum_hoth
## Success: the objective function is 671.875

The final values

optimum_hoth$solution
## [1] 3.125 6.250 5.000
optimum_hoth$objval
## [1] 671.875

2.4 Solution Evaluation

Reduced costs.

optimum_hoth$sens.coef.from
## [1] -100.000   37.500   21.875
optimum_hoth$sens.coef.to
## [1] 1.00e+02 6.25e+01 1.00e+30
product_hoth_name <- c("At-At", "Snow Speeder", "Tauntaun") 
coeff_hoth_max <- optimum_hoth$sens.coef.to
coeff_hoth_min <- optimum_hoth$sens.coef.from

coeff_hoth <- obj_coeff_hoth

solution_hoth_reduced_cost <- data.frame(product_hoth_name,
                                         coeff_hoth,
                                         coeff_hoth_max, 
                                         coeff_hoth_min)
solution_hoth_reduced_cost
##   product_hoth_name coeff_hoth coeff_hoth_max coeff_hoth_min
## 1             At-At         75       1.00e+02       -100.000
## 2      Snow Speeder         50       6.25e+01         37.500
## 3          Tauntaun         25       1.00e+30         21.875

Shadow prices.

optimum_hoth$duals
## [1]  0.0000  0.0000 21.8750  1.5625  6.2500  0.0000  0.0000  0.0000
constraint_hoth_name <- c("Assembly", "Finishing", "Equipping",
                          "Feeding", "Mix")
constraints_hoth <- constraints_rhs_hoth
shadow_price_hoth <- optimum_hoth$duals[1:5]

solution_hoth_shadow_price <- data.frame(constraint_hoth_name,
                                         constraints_hoth,
                                         shadow_price_hoth)
solution_hoth_shadow_price
##   constraint_hoth_name constraints_hoth shadow_price_hoth
## 1             Assembly               84            0.0000
## 2            Finishing               21            0.0000
## 3            Equipping               30           21.8750
## 4              Feeding               10            1.5625
## 5                  Mix                0            6.2500

3. Integer Optimisation

3.1 Integer Solution

optimum_hoth_int <- lp(direction = "max",
                   objective.in = obj_coeff_hoth,
                   const.mat = constraints_coeff_hoth,
                   const.dir = constraints_dir_hoth,
                   const.rhs = constraints_rhs_hoth,
                   int.vec = 1:5,
                   compute.sens = TRUE)
optimum_hoth_int
## Success: the objective function is 650

The final values

optimum_hoth_int$solution
## [1] 4 5 4
optimum_hoth_int$objval
## [1] 650

3.2 Solution Evaluation

Reduced costs.

optimum_hoth_int$sens.coef.from
## [1] -100    0    0
optimum_hoth_int$sens.coef.to
## [1] 1e+30 1e+30 1e+30
product_hoth_int_name <- c("At-At", "Snow Speeder", "Tauntaun") 
coeff_hoth_int_max <- optimum_hoth_int$sens.coef.to
coeff_hoth_int_min <- optimum_hoth_int$sens.coef.from

coeff_hoth_int <- obj_coeff_hoth

solution_hoth_int_reduced_cost <- data.frame(product_hoth_int_name,
                                         coeff_hoth_int,
                                         coeff_hoth_int_max, 
                                         coeff_hoth_int_min)
solution_hoth_int_reduced_cost
##   product_hoth_int_name coeff_hoth_int coeff_hoth_int_max coeff_hoth_int_min
## 1                 At-At             75              1e+30               -100
## 2          Snow Speeder             50              1e+30                  0
## 3              Tauntaun             25              1e+30                  0

Shadow prices.

optimum_hoth_int$duals
## [1]   0   0  25   0   0 -25   0   0
constraint_hoth_int_name <- c("Assembly", "Finishing", "Equipping",
                          "Feeding", "Mix")
constraints_hoth_int <- constraints_rhs_hoth
shadow_price_hoth_int <- optimum_hoth_int$duals[1:5]

solution_hoth_int_shadow_price <- data.frame(constraint_hoth_name,
                                         constraints_hoth_int,
                                         shadow_price_hoth_int)
solution_hoth_int_shadow_price
##   constraint_hoth_name constraints_hoth_int shadow_price_hoth_int
## 1             Assembly                   84                     0
## 2            Finishing                   21                     0
## 3            Equipping                   30                    25
## 4              Feeding                   10                     0
## 5                  Mix                    0                     0

May the force be with you