3 x1 + 2 x2 + 2 x3 <= 15
library(lpSolve)
#set up problem
f.obj <- c(1,9,1)
f.con <- matrix(c(1,2,3,3,2,2), nrow=2, byrow=TRUE)
f.dir <- c("<=", "<=")
f.rhs <- c(9,15)
#Objective Function Answer
lp("max", f.obj, f.con, f.dir, f.rhs)
## Success: the objective function is 40.5
#Answers of the Decision variables
lp("max", f.obj, f.con, f.dir, f.rhs)$solution
## [1] 0.0 4.5 0.0
#Get Sensitivities-Objective Function Coeficients
lp("max", f.obj, f.con, f.dir, f.rhs, compute.sens = TRUE)$sens.coef.from
## [1] -1e+30 2e+00 -1e+30
lp("max", f.obj, f.con, f.dir, f.rhs, compute.sens = TRUE)$sens.coef.to
## [1] 4.50e+00 1.00e+30 1.35e+01
#Remove Scientific Notation
options(scipen = 999)
# Dual Values (first dual of the constraints and then dual of the variables)
# Duals of the constraints and variables are mixed
lp("max", f.obj, f.con, f.dir, f.rhs, compute.sens = TRUE)$duals
## [1] 4.5 0.0 -3.5 0.0 -12.5
# Get Sensitivities-Right Hand Sides
lp("max", f.obj, f.con, f.dir, f.rhs, compute.sens = TRUE)$duals.from
## [1] -0.000000000000001776357
## [2] -1000000000000000019924668064446.000000000000000000000
## [3] -1000000000000000019924668064446.000000000000000000000
## [4] -1000000000000000019924668064446.000000000000000000000
## [5] -6.000000000000001776357
lp("max", f.obj, f.con, f.dir, f.rhs, compute.sens = TRUE)$duals.to
## [1] 15 1000000000000000019924668064446
## [3] 3 1000000000000000019924668064446
## [5] 3
# To Get The Integer Solution
lp("max", f.obj, f.con, f.dir, f.rhs, int.vec = 1:3)
## Success: the objective function is 37
lp("max", f.obj, f.con, f.dir, f.rhs, int.vec = 1:3)$solution
## [1] 1 4 0