From 4ced25933fce584b759997c37cbebc58ff8654ba Mon Sep 17 00:00:00 2001 From: Kaustubh Patil Date: Sun, 14 Mar 2021 23:18:57 +0100 Subject: [PATCH 1/4] fixing the hardcoded ncol=2 which leads to a carsh when number of objectives is not 2 --- R/geneticoperator.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geneticoperator.R b/R/geneticoperator.R index 7f803c7..1c70240 100644 --- a/R/geneticoperator.R +++ b/R/geneticoperator.R @@ -332,7 +332,7 @@ nsga_spCrossover <- function(object, parents) { children <- matrix(as.double(NA), nrow = 2, ncol = n) crossOverPoint <- sample(0:n, size = 1) if (crossOverPoint == 0) { - fitnessChildren <- matrix(as.double(NA), nrow = 2, ncol = 2) + fitnessChildren <- matrix(as.double(NA), nrow = 2, ncol = ncol(fitness)) children[1:2, ] <- parents[2:1, ] fitnessChildren[1:2, ] <- fitness[2:1, ] } else if (crossOverPoint == n) { From 45974b57535e3523ecdc03fdc26e01ef99ca6165 Mon Sep 17 00:00:00 2001 From: Kaustubh Patil Date: Thu, 25 Mar 2021 14:04:56 +0100 Subject: [PATCH 2/4] fix invalid check for real-values nsga2 --- R/nsga2.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/nsga2.R b/R/nsga2.R index 0af0a30..f277b00 100644 --- a/R/nsga2.R +++ b/R/nsga2.R @@ -222,8 +222,8 @@ nsga2 <- function(type = c("binary", "real-valued", "permutation"), nBits <- NA if (length(lower) != length(upper)) stop("lower and upper must be vector of the same length") - if ((length(lower) != nObj) & (length(upper) != nObj)) - stop("The lower and upper limits must be vector of the same number of objectives") + #if ((length(lower) != nObj) & (length(upper) != nObj)) + # stop("The lower and upper limits must be vector of the same number of objectives") nvars <- length(upper) if (is.null(names) & !is.null(lnames)) names <- lnames if (is.null(names) & !is.null(unames)) names <- unames From d8f4bb5f1deadcb78444a62c1b634aa0a41c180b Mon Sep 17 00:00:00 2001 From: Kaustubh Patil Date: Thu, 25 Mar 2021 14:23:37 +0100 Subject: [PATCH 3/4] fix numbers of variable for real-values nsga2 --- R/nsga2.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/nsga2.R b/R/nsga2.R index f277b00..1e9c9c2 100644 --- a/R/nsga2.R +++ b/R/nsga2.R @@ -305,7 +305,7 @@ nsga2 <- function(type = c("binary", "real-valued", "permutation"), switch(type, binary = { Pop <- P <- Q <- matrix(as.double(NA), nrow = popSize, ncol = nBits) }, `real-valued` = { - Pop <- P <- Q <- matrix(as.double(NA), nrow = popSize, ncol = nObj) + Pop <- P <- Q <- matrix(as.double(NA), nrow = popSize, ncol = nvars) }, permutation = { Pop <- P <- Q <- matrix(as.double(NA), nrow = popSize, ncol = nvars) }) From 8c2fdd783b3c1440a47e4a00f27bea672f4f5d2e Mon Sep 17 00:00:00 2001 From: Kaustubh Patil Date: Thu, 25 Mar 2021 15:43:43 +0100 Subject: [PATCH 4/4] fixing number of objectives returned in real-valued crossover --- R/geneticoperator.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geneticoperator.R b/R/geneticoperator.R index 1c70240..cff1b9b 100644 --- a/R/geneticoperator.R +++ b/R/geneticoperator.R @@ -251,7 +251,7 @@ nsgareal_sbxCrossover <- function(object, parents, nc = 20) { children[2, j] <- child2 } out <- list(children = children, - fitness = matrix(as.double(NA), ncol = n)) + fitness = matrix(as.double(NA), ncol = ncol(object@fitness))) return(out) }