如何在R中使用Lpsolve检索优化目标函数中的变量值

问题描述

我正在尝试在优化的目标函数处找到x和y的值。 这是找到我使用的最优值的代码

objective.in=c(6.55,7.9)
const.mat=matrix(c(0.25,0.25,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

解决方法

> library(lpSolve)
> objective.in=c(6.55,7.9)
> const.mat=matrix(c(0.25,0.25,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

使用?lp.object查找有关lp()返回的对象中可用内容的更多信息。