R Error: (all(xi <= xj) && any(xi < xj)) { : missing value where TRUE/FALSE needed

Hello @swaheera ,

two remarks to start with:

  • always use set.seed to that we can exactly reproduce your results
  • please always include a reprex . Of course I know that you included all parts of your code but while copying you made a mistake: you mentioned library(nsga2r) instead of library(nsga2R).
    Not something that can't be solved, but this could have been avoid when you had used the reprex package to show us the code.

That said, I don't understand the purpose of your optimization so I can't help you there.
What strikes me is that you want to optimize (in some way?) four dependent numbers: the mean of a variable and then the mean of subsets thereof. Apparently this is not accepted here. By the way, I think you could have shown more of the context of the error message:

initializing the population
ranking the initial population
Error in if (all(xj <= xi) && any(xj < xi)) { : 
  missing value where TRUE/FALSE needed

I think your code is not wrong because I can run it when I slightly change the function and the optimization call:


#define function

funct_set <- function (x) {

results <- nsga2R(fn=funct_set, varNo=7, objDim=2, 
                  lowerBounds=c(80,80,80,80, 100, 200, 300), 
                  popSize=50, tourSize=2, generations=50, 
                  cprob=0.9, XoverDistIdx=20, mprob=0.1,MuDistIdx=3)

I think this suggests that the code is not wrong but that this optimization is not fit for your purpose (?)