R COMPLEMENTARIA 13

## R Markdown

library(lpSolveAPI)
## Warning: package 'lpSolveAPI' was built under R version 4.1.3
#Crear modelo de optimizacion lineal, inicializamos con 0 restricciones y las 2 variables

model<-make.lp(nrow = 0,ncol = 2)

#Funcion objetivo
set.objfn(model,c(1,1))
lp.control(model,sense="min")
## $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] "minimize"
## 
## $simplextype
## [1] "dual"   "primal"
## 
## $timeout
## [1] 0
## 
## $verbose
## [1] "neutral"
#Incluir restricciones

add.constraint(model, c(-0.72,0.82),">=",0.8)
add.constraint(model, c(-0.54,0.64),">=",0.4)
add.constraint(model, c(0.73,-0.63),">=",0.3)
add.constraint(model, c(0.55,-0.45),">=",0.5)


#Determinar nombres a variables y restricciones
dimnames(model)<-list(c("AS-C","AS-S","AC-C","AC-S"),c("AC", "AS"))

#Ver modelo PL planteado
model
## Model name: 
##              AC     AS         
## Minimize      1      1         
## AS-C      -0.72   0.82  >=  0.8
## AS-S      -0.54   0.64  >=  0.4
## AC-C       0.73  -0.63  >=  0.3
## AC-S       0.55  -0.45  >=  0.5
## Kind        Std    Std         
## Type       Real   Real         
## Upper       Inf    Inf         
## Lower         0      0
#Graficar region factible del modelo

plot(model)

#Resolver sistema lineal
solve(model)
## [1] 0
#Obtener funcion objetivo, variables y restricciones
get.objective(model)
## [1] 12.3622
get.variables(model)
## [1] 6.062992 6.299213
get.constraints(model)
## [1] 0.8000000 0.7574803 0.4574803 0.5000000
#Determina decision optima mediante dual
#Quiero saber las restriciiones sin holgura
#La restricciones sin holgura es las que tienen asociado un dual mayor a 0

get.dual.solution(model)[-1]
## [1]  7.874016  0.000000  0.000000 12.125984  0.000000  0.000000