import library

library(lpSolveAPI)


define the datasets

https://civil.colorado.edu/~balajir/CVEN5393/R-sessions/sess1/lpSolveAPI-vignettes.pdf

https://www.r-bloggers.com/2012/07/linear-programming-in-r-an-lpsolveapi-example/

Hillier, F. S., & Hillier, M. S. (2019). Introduction to management science: A modeling and case studies approach with spreadsheets (6th). McGraw-Hill Education.pp26-47

Introduction MS2019

A new lpSolve linear program model object with m constraints and n decision variables can be created using the make.lp function. For example, the following command creates an lpSolve linear program model object with 3 constraints and 2 decision variables.

create an LP model with 3 constraints and 2 decision variables

 my.lp <- make.lp(3, 2)
hours<-data.frame(plant=c('plant1','plant2','plant3'), door_hours=c(1,0,3), window_hours=c(0,2,2),avaible_hours=c(4,12,18))
 set.column(my.lp, 1, hours$door_hours)
 set.column(my.lp, 2, hours$window_hours)
set.constr.type(my.lp, rep("<=", 3))
set.objfn(my.lp, c(300, 500))
RowNames <- c("plant1", "plant2", "plant3")
ColNames <- c("door", "window")
dimnames(my.lp) <- list(RowNames, ColNames)
set.rhs(my.lp, hours$avaible_hours)
set.type(my.lp, c(1,2), "integer")
lp.control(my.lp,sense='max')
## $anti.degen
## [1] "fixedvars" "stalling" 
## 
## $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] "maximize"
## 
## $simplextype
## [1] "dual"   "primal"
## 
## $timeout
## [1] 0
## 
## $verbose
## [1] "neutral"
my.lp
## Model name: 
##             door  window        
## Maximize     300     500        
## plant1         1       0  <=   4
## plant2         0       2  <=  12
## plant3         3       2  <=  18
## Kind         Std     Std        
## Type         Int     Int        
## Upper        Inf     Inf        
## Lower          0       0
solve(my.lp)
## [1] 0
#this return the proposed solution
get.objective(my.lp)
## [1] 3600
get.variables(my.lp)
## [1] 2 6
get.constraints(my.lp)
## [1]  2 12 18