#Example 1
#Two Objectives - Real Valued
zdt1 <- function (x) {
if (is.null(dim(x))) {
x <- matrix(x, nrow = 1)
}
n <- ncol(x)
g <- 1 + rowSums(x[, 2:n, drop = FALSE]) * 9/(n - 1)
return(cbind(x[, 1], g * (1 - sqrt(x[, 1]/g))))
}
#Not run:
if (FALSE) {
result <- rmoo(type = "real-valued",
fitness = zdt1,
algorithm = "NSGA-II",
lower = c(0,0),
upper = c(1,1),
popSize = 100,
nObj = 2,
monitor = FALSE,
maxiter = 500)
}
#Example 2
#Three Objectives - Real Valued
dtlz1 <- function (x, nobj = 3){
if (is.null(dim(x))) {
x <- matrix(x, 1)
}
n <- ncol(x)
y <- matrix(x[, 1:(nobj - 1)], nrow(x))
z <- matrix(x[, nobj:n], nrow(x))
g <- 100 * (n - nobj + 1 + rowSums((z - 0.5)^2 - cos(20 * pi * (z - 0.5))))
tmp <- t(apply(y, 1, cumprod))
tmp <- cbind(t(apply(tmp, 1, rev)), 1)
tmp2 <- cbind(1, t(apply(1 - y, 1, rev)))
f <- tmp * tmp2 * 0.5 * (1 + g)
return(f)
}
#Define uniformly distributed reference points.
ref_points <- generate_reference_points(3,12)
#Not Run
if (FALSE) {
result <- rmoo(type = "real-valued",
fitness = dtlz1,
algorithm = "NSGA-III",
lower = c(0,0,0),
upper = c(1,1,1),
popSize = 92,
nObj = 3,
reference_dirs = ref_points,
monitor = FALSE,
maxiter = 500)
}
#Example 3
#Two Objectives - Real Valued with Preference-guided
zdt2 <- function (x)
{
if (is.null(dim(x))) {
x <- matrix(x, nrow = 1)
}
n <- ncol(x)
g <- 1 + rowSums(x[, 2:n, drop = FALSE]) * 9/(n - 1)
return(cbind(x[, 1], g * (1 - (x[, 1]/g)^2)))
}
#Define uniformly distributed reference points.
ref_points <- rbind(c(1.0, 0.0), c(0.0, 1.0), c(0.5, 0.5))
#Not run
if (FALSE) {
result <- rmoo(type = "real-valued",
fitness = zdt2,
algorithm = "R-NSGA-II",
lower = c(0,0),
upper = c(1,1),
reference_dirs = ref_points,
popSize = 92,
nObj = 2,
monitor = FALSE,
maxiter = 500)
}
Run the code above in your browser using DataLab