1

I need to optimize the following to find the maximum value for r1:

ad = 0.95*M_D + 0.28*G_D + 0.43*S_D + 2.25*Q_D
as = 0.017*M_A + 0.0064*G_A + 0.0076*S_A + 0.034*Q_A
ccb = 0.0093*M_CC+ 0.0028*G_CC + 0.0042*S_CC + 0.0186*Q_CC
ccd = 0.0223*M_CD + 0.0056*G_CD + 0.0078*S_CD + 0.0446*Q_CD
apb = 1.28*M_P + 2.56*Q_P 
r1=(1+ccb*(1+ccd))*ad*as*100/(130-apb)

subject to the following constraints:

0 <= M_CD <= M_CC <= M_A <= M_D <= M_P <= 9
0 <= G_CD <= G_CC <= G_A <= G_D <= 9
0 <= S_CD <= S_CC <= S_A <= S_D <= 9
0 <= Q_CD <= Q_CC <= Q_A <= Q_D <= Q_P <= 3

The approach I've tried before doesn't work very well and I'm hoping to find a better solution.

4

2 回答 2

2

一旦正确说明了问题,您也许可以首先将参数映射到 [0,1] 的下限和上限。然后,您可以在函数内部实现不等式,并使用接受基本下限和上限约束的算法进行优化。nlminb可以使用,但小插图表明使用的算法可能不是最好的。

更新:

带OP修改功能

dumFun <- function(p){
    p[1] -> M_CD; p[2] -> M_CC; p[3] -> M_A; p[4] -> M_D; p[5] -> M_P;
    M_P <- 9*M_P; M_D <- M_P*M_D; M_A <- M_D*M_A; M_CC <- M_A*M_CC; M_CD <- M_CC*M_CD; 
    p[6] -> G_CD; p[7] -> G_CC; p[8] -> G_A; p[9] -> G_D;
    G_D <- 9*G_D; G_A <- G_D*G_A; G_CC <- G_A*G_CC; G_CD <- G_CC*G_CD; 
    p[10] -> S_CD; p[11] -> S_CC; p[12] -> S_A; p[13] -> S_D;
    S_D <- 9*S_D; S_A <- S_D*S_A; S_CC <- S_A*S_CC; S_CD <- S_CC*S_CD; 
    p[14] -> Q_CD; p[15] -> Q_CC; p[16] -> Q_A; p[17] -> Q_D; p[18] -> Q_P;
    Q_P <- 3*Q_P; Q_D <- Q_P*Q_D; Q_A <- Q_D*Q_A; Q_CC <- Q_A*Q_CC; Q_CD <- Q_CC*Q_CD; 

    ad = 0.95*M_D + 0.28*G_D + 0.43*S_D + 2.25*Q_D
    as = 0.017*M_A + 0.0064*G_A + 0.0076*S_A + 0.034*Q_A
    ccb = 0.0093*M_CC+ 0.0028*G_CC + 0.0042*S_CC + 0.0186*Q_CC
    ccd = 0.0223*M_CD + 0.0056*G_CD + 0.0078*S_CD + 0.0446*Q_CD
    apb = 1.28*M_P + 2.56*Q_P 
    r1=(1+ccb*(1+ccd))*ad*as*100/(130-apb)
    -r1
}
require(minqa)
p <- rep(.1, 18)
bobyqa(p, dumFun, lower = rep(0, length(p)), upper = rep(1, length(p)))
parameter estimates: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 
objective: -9.65605526502482 
number of function evaluations: 97 
> 
于 2013-06-07T13:28:36.893 回答
0

我终于不是用矢量化而是用 C 解决了我的问题。我的程序包含 14 个嵌套循环,用 C 比用 R 执行快 100 到 1000 倍!这很可悲,因为我没有从中学到任何新东西,这证明 R 在某些问题上可能毫无用处,但我们能做些什么。

于 2013-06-12T18:36:57.023 回答