caRamel is a multiobjective evolutionary algorithm combining the MEAS algorithm and the NGSA-II algorithm.
Download the package from CRAN or GitHub and then install and load it.
## Loading required package: geometry
## Loading required package: parallel
## Package 'caRamel' version 1.4
Schaffer test function has two objectives with one variable.
schaffer <- function(i) {
if (x[i,1] <= 1) {
s1 <- -x[i,1]
} else if (x[i,1] <= 3) {
s1 <- x[i,1] - 2
} else if (x[i,1] <= 4) {
s1 <- 4 - x[i,1]
} else {
s1 <- x[i,1] - 4
}
s2 <- (x[i,1] - 5) * (x[i,1] - 5)
return(c(s1, s2))
}
Note that :
The variable lies in the range [-5, 10]:
nvar <- 1 # number of variables
bounds <- matrix(data = 1, nrow = nvar, ncol = 2) # upper and lower bounds
bounds[, 1] <- -5 * bounds[, 1]
bounds[, 2] <- 10 * bounds[, 2]
Both functions are to be minimized:
Before calling caRamel in order to optimize the Schaffer’s problem, some algorithmic parameters need to be set:
popsize <- 100 # size of the genetic population
archsize <- 100 # size of the archive for the Pareto front
maxrun <- 1000 # maximum number of calls
prec <- matrix(1.e-3, nrow = 1, ncol = nobj) # accuracy for the convergence phase
Then the minimization problem can be launched:
results <-
caRamel(nobj,
nvar,
minmax,
bounds,
schaffer,
popsize,
archsize,
maxrun,
prec,
carallel=FALSE) # no parallelism
## Beginning of caRamel optimization <-- Mon Nov 11 07:26:39 2024
## Number of variables : 1
## Number of functions : 2
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 4 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 2 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Done in 3.01017665863037 secs --> Mon Nov 11 07:26:42 2024
## Size of the Pareto front : 100
## Number of calls : 1020
Test if the convergence is successful:
## [1] TRUE
Plot the Pareto front:
Kursawe test function has two objectives of three variables.
kursawe <- function(i) {
k1 <- -10 * exp(-0.2 * sqrt(x[i,1] ^ 2 + x[i,2] ^ 2)) - 10 * exp(-0.2 * sqrt(x[i,2] ^2 + x[i,3] ^ 2))
k2 <- abs(x[i,1]) ^ 0.8 + 5 * sin(x[i,1] ^ 3) + abs(x[i,2]) ^ 0.8 + 5 * sin(x[i,2] ^3) + abs(x[i,3]) ^ 0.8 + 5 * sin(x[i,3] ^ 3)
return(c(k1, k2))
}
The variables lie in the range [-5, 5]:
nvar <- 3 # number of variables
bounds <- matrix(data = 1, nrow = nvar, ncol = 2) # upper and lower bounds
bounds[, 1] <- -5 * bounds[, 1]
bounds[, 2] <- 5 * bounds[, 2]
Both functions are to be minimized:
Set algorithmic parameters and launch caRamel:
popsize <- 100 # size of the genetic population
archsize <- 100 # size of the archive for the Pareto front
maxrun <- 1000 # maximum number of calls
prec <- matrix(1.e-3, nrow = 1, ncol = nobj) # accuracy for the convergence phase
results <-
caRamel(nobj,
nvar,
minmax,
bounds,
kursawe,
popsize,
archsize,
maxrun,
prec,
carallel=FALSE) # no parallelism
## Beginning of caRamel optimization <-- Mon Nov 11 07:26:45 2024
## Number of variables : 3
## Number of functions : 2
## Warning in delaunayn(obj): 4 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 3 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 4 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 5 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 2 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 2 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 3 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 4 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 2 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 5 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 5 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 10 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 9 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 5 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 5 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 2 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 7 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 3 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 5 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 3 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 1 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Warning in delaunayn(obj): 14 points missing from triangulation.
## It is possible that setting the 'options' argument of delaunayn may help.
## For example:
## options = "Qt Qc Qz Qbb"
## options = "Qt Qc Qz QbB"
## If these options do not work, try shifting the centre of the points
## to the origin by subtracting the mean coordinates from every point.
## Done in 2.45570254325867 secs --> Mon Nov 11 07:26:47 2024
## Size of the Pareto front : 76
## Number of calls : 1011
Test if the convergence is successful and plot the optimal front:
## [1] TRUE
plot(results$objectives[,1], results$objectives[,2], main="Kursawe Pareto front", xlab="Objective #1", ylab="Objective #2")
Finally plot the convergences of the objective functions: