# \donttest{
if (requireNamespace("mirai", quietly = TRUE)) {
# NOTE: Examples were excluded from testing
# to reduce package check time.
# stays within 2-core limit
mirai::daemons(1, dispatcher = FALSE)
set.seed(42)
# Warning: the examples are run using a very small number of
# iterations to decrease execution time. Because they are very
# cheap to compute, parallel evaluation is actually detrimental.
# Shekel 5 problem
#
# 0 <= xj <= 10, j = {1, 2, 3, 4}
# There are five local minima and the global minimizer is
# located at x* = (4.00, 4.00, 4.00, 4.00) with
# f(x*) ~~ -10.1499.
#
# Source:
# Ali, M. Montaz, Khompatraporn, Charoenchai, and
# Zabinsky, Zelda B. (2005).
# A numerical evaluation of several stochastic algorithms
# on selected continuous global optimization test problems.
# Journal of Global Optimization 31, 635-672.
# https://doi.org/10.1007/s10898-004-9972-2
a_ij <- matrix(c(4, 4, 4, 4,
1, 1, 1, 1,
8, 8, 8, 8,
6, 6, 6, 6,
3, 7, 3, 7), ncol = 4, byrow = TRUE)
c_i <- c(0.1, 0.2, 0.2, 0.4, 0.4)
a_ji <- t(a_ij)
shekel5 <- function(x) {
-sum(1/( colSums((x - a_ji)^2) + c_i ))
}
SPJDEoptim(rep(0, 4), rep(10, 4), shekel5,
a_ji = a_ji, c_i = c_i,
maxiter = 10, trace = TRUE)
# Sinusoidal problem
#
# 0 <= xi <= 180, i = {1, 2, ..., n}
# The variable x is in degrees. Parameter A affects the
# amplitude of the global optimum; B affects the peridiocity
# and hence the number of local minima; z shifts the location
# of the global minimum. The location of the global solution
# is at x* = (90+z, 90+z, ..., 90+z) with the global optimum
# value of f(x*) = -(A+1).
#
# Source:
# Ali, M. Montaz, Khompatraporn, Charoenchai, and
# Zabinsky, Zelda B. (2005).
# A numerical evaluation of several stochastic algorithms
# on selected continuous global optimization test problems.
# Journal of Global Optimization 31, 635-672.
# https://doi.org/10.1007/s10898-004-9972-2
sinusoidal <- function(x, A, B, z) {
var_in_rad <- (x - z)*pi/180
-( A*prod(sin(var_in_rad)) + prod(sin(B*var_in_rad)) )
}
SPJDEoptim(rep(0, 10), rep(180, 10), sinusoidal,
further_args = list(A = 2.5, B = 5, z = 30),
maxiter = 10, trace = TRUE)
mirai::daemons(0) # reset
Sys.sleep(1)
}
# }
Run the code above in your browser using DataLab