Search code examples
rlinear-programminglpsolve

how to retrieve values of variables in the optimised objective function using Lpsolve in R


Im trying to find the values of x and y at the optimized objective function. This is the code for finding the optimum that i used

objective.in=c(6.55,7.9)
const.mat=matrix(c(0.25,0,0.25,0.5,0.5,0.5),nrow=3,byrow = TRUE)
const.dir<-c("<=","<=","<=")
const.rhs<-c(500,200,200)
lp("max",objective.in,const.mat,const.dir,const.rhs)

enter image description here


Solution

  • > library(lpSolve)
    > objective.in=c(6.55,7.9)
    > const.mat=matrix(c(0.25,0,0.25,0.5,0.5,0.5),nrow=3,byrow = TRUE)
    > const.dir<-c("<=","<=","<=")
    > const.rhs<-c(500,200,200)
    > res<-lp("max",objective.in,const.mat,const.dir,const.rhs)
    > res$objval
    [1] 3160
    

    Use ?lp.object to find more information about what is available in the object that lp() returns.