【问题标题】:Optimization with three variables三变量优化
【发布时间】:2016-09-22 20:54:30
【问题描述】:

我有一个方程,其中包含三个变量,变量范围不同

f(x)= 150*x + 92*y + 41,1*z -> max

为准
x > 0 & x < 600
x > 0 & x < 600
x+y+z <600
if x<200 or y<200 or x+y <200 -> z=0

我想找到变量的最大值。我对R的了解太少,无法自己解决。

【问题讨论】:

  • 您可能正在寻找线性规划。看看lpSolveAPI 包。
  • 看看constrOptim。并提供真实代码。

标签: r optimization mathematical-optimization linear-programming constraint-programming


【解决方案1】:

您可以将问题划分为z=0z&gt;=0。对于第二个子问题,您可以这样设置和解决问题:

library(lpSolveAPI)

# create object
lprec <- make.lp(0,3)
invisible(lp.control(lprec, sense="max")) # sense defaults to "min" 

# add objective and constraints
set.objfn(lprec, obj=c(150,92,41.1), indices=c(1,2,3)) 
add.constraint(lprec, 1, type="<=", rhs=600, indices=1)
add.constraint(lprec, 1, type=">=", rhs=200, indices=1)
add.constraint(lprec, 1, type="<=", rhs=600, indices=2)
add.constraint(lprec, 1, type=">=", rhs=200, indices=2)
add.constraint(lprec, c(1,1,1), type="<=", rhs=600, indices=c(1,2,3))
add.constraint(lprec, c(1,1), type=">=", rhs=200, indices=c(1,2))

# solve
print(lprec)
solve(lprec)
get.variables(lprec)

请注意,我假设您在问题中指的是0&lt;=y&lt;=600。另请注意,设置“lpSolveAPI默认假设决策变量的非负性,因此假设z&gt;=0

第一个子问题可以类似地解决。如您所知,在这种情况下z=0,决策变量的数量减少到2

问题的解决方案是两个子解决方案中最好的。正如@RHertel 已经评论的那样,这是您在x 上尽可能多地投入的解决方案,因此yz 为0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-29
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多