2

我有以下代码定义了我想在我的多目标优化问题中使用的两个约束,model1 model2并且model3之前已经可以验证工作。

restrictions <- function (var) {
  x <- var[1]; y <- var[2]
  restrictions <- logical(2)
  restrictions[1] <- (predict(get(model1), data.frame(x, y), type = "response") < 500)
  restrictions[2] <- (predict(get(model1), data.frame(x, y), type = "response") > 0)
  return (restrictions);
}

在以下代码中构建遗传算法多目标函数:

fn <- function (var) {
  x <- var[1]; y <- var[2]
  f <- numeric(3)
  f[1] <- predict(get(model1), data.frame(x, y), type = "response")
  f[2] <- predict(get(model2), data.frame(x, y), type = "response")
  f[3] <- predict(get(model3), data.frame(x, y), type = "response")
  return (f);
}

最后是使用 mco 库的优化过程

library (mco)
optimum <- mco::nsga2 (fn = fn, idim = 2, odim=3,
                                constraints = restrictions, cdim = 2,
                           generations = 100,
                           popsize= 40,
                           cprob = 0.5,
                           cdist = 20,
                           mprob = 0.5,
                           mdist = 20, 
                           lower.bounds = c(-80, 50),
                           upper.bounds = c(-70, 60)
)

主要问题是解决方案不遵守指定的约束。对此有什么想法吗?

4

0 回答 0