我是 R 的新手,需要解决多目标优化问题 (MOOP)。我已经导入了 mco 包,定义了我的函数并检查了 nsga2 函数。问题是,当前者与数字变量匹配时,我还没有找到绑定函数定义中的参数(形式参数)和调用中的参数(实际参数)的正确方法。
我有以下代码:
funct_set <- function (x1,x2,x3) {
f <- numeric(2)
f[1] <- min(-5*x1 - 2*x2 - 8*x3)
f[2] <- min(1000*x1 + 8000*x2 + 12000*x3)
return (f);
}
restrictions <- function (x1,x2,x3) {
restrictions <- numeric(3)
restrictions[1] <- (x1 + x2 + x3 <= 30)
restrictions[2] <- (x1 + x2 + x3 > 0)
restrictions[3] <- (2*x1 + 3*x2 + 1.5*x3 <= 45)
return (restrictions);
}
optimization <- nsga2(funct_set('x1', 'x2', 'x3'),
constraints = restrictions('x1', 'x2', 'x3'),
2, 2,
NULL,
generations=150,
popsize=100,
cprob=0.7,
cdist=20,
mprob=0.2,
mdist=20,
lower.bounds=rep(-5, 2),
upper.bounds=rep(10, 2)
);
然而,这导致 R 认为 'x1'、'x2' 和 'x3' 不是数字:Error in x1 + x2 : non-numeric argument to binary operator
传递这些参数的正确方法是什么?