2016-05-25 59 views
0

我有三個變量在不同範圍的方程變量優化有三個變量

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的瞭解太少,無法自己解決。

+1

您可能正在尋找線性編程。查看[lpSolveAPI](http://cran.r-project.org/web/packages/lpSolveAPI/index.html)軟件包。 –

+1

看'constrOptim'。並提供真實的代碼。 –

回答

1

您可以將問題分爲z=0z>=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<=y<=600。還請注意,設置「<」限制並不是非常有用(或可能),但使用「< =」要好得多。最後,請注意,lpSolveAPI默認情況下假定決策變量不具有否定性,因此它假定爲z>=0

第一個子問題可以類似地解決。正如你已經知道在這種情況下,決策變量的數量減少到2

問題的解決方案是兩個子解決方案中最好的。正如@RHertel已經評論過的那樣,這是您儘可能多地將其放到x上的解決方案,因此,yz是0.