Problem with multi-objective optimization constraints: R

260 views Asked by At

I have the following code that defines two constraints I want to use in my multi-objective optimization problem, given that model1 model2 and model3 are already verifiably working before.

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);
}

Building a genetic algorithm multi objective function in the following code:

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);
}

And finally the optimization process here using mco library

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)
)

The main problem is that the solution does not abide with the constraint specified. Any thoughts on that?

0

There are 0 answers