【问题标题】:how to retrieve values of variables in the optimised objective function using Lpsolve in R如何使用 R 中的 Lpsolve 检索优化目标函数中的变量值
【发布时间】:2020-10-08 14:51:22
【问题描述】:

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

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)

【问题讨论】:

  • 在最后一行,将其分配给一个对象,然后使用str() 查看该对象的结构。

标签: r linear-programming lpsolve


【解决方案1】:
> 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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    相关资源
    最近更新 更多