R/sof.deflected.corrugated.spring.R

Defines functions makeDeflectedCorrugatedSpringFunction

Documented in makeDeflectedCorrugatedSpringFunction

#' @title Deflected Corrugated Spring function
#'
#' @description Scalable single-objective test function based on the formula
#' \deqn{f(\mathbf{x}) = 0.1 \sum_{i = 1}^{n} (x_i - \alpha)^2 - \cos\left(K \sqrt{\sum_{i = 1}^{n} (x_i - \alpha)^2}\right)}
#' with \eqn{\mathbf{x}_i \in [0, 2\alpha], i = 1, \ldots, n} and \eqn{\alpha = K = 5}
#' by default.
#'
#' @references See \url{https://al-roomi.org/benchmarks/unconstrained/n-dimensions/238-deflected-corrugated-spring-function}.
#'
#' @template arg_dimensions
#' @param K [\code{numeric(1)}]\cr
#'   Parameter.
#'   Default is 5.
#' @param alpha [\code{numeric(1)}]\cr
#'   Parameter.
#'   Default is 5.
#'
#' @return
#' An object of class \code{SingleObjectiveFunction}, representing the Deflected Corrugated Spring Function. 
#'   
#' @template ret_smoof_single
#' @export
makeDeflectedCorrugatedSpringFunction = function(dimensions, K = 5, alpha = 5) {
  checkmate::assertCount(dimensions)
  checkmate::assertNumber(K)
  checkmate::assertNumber(alpha)

  force(K)
  force(alpha)
  force(dimensions)

  makeSingleObjectiveFunction(
    name = paste(dimensions, "-d Deflected Corrugated Spring function", sep = ""),
    #FIXME: eventually encode K and alpha in fun?
    id = paste0("deflectedCorrugatedSpring_", dimensions, "d_K", K, "alpha", alpha),
    fn = function(x) {
      checkNumericInput(x, dimensions)
      a = (x - alpha)^2
      sa = sum(a)
      0.1 * sa - cos(K * sqrt(sa))
    },
    par.set = ParamHelpers::makeNumericParamSet(
      len = dimensions,
      id = "x",
      lower = rep(0, dimensions),
      upper = rep(2 * alpha, dimensions),
      vector = TRUE
    ),
    tags = attr(makeDeflectedCorrugatedSpringFunction, "tags"),
    global.opt.params = rep(alpha, dimensions),
    global.opt.value = -1
  )
}

class(makeDeflectedCorrugatedSpringFunction) = c("function", "smoof_generator")
attr(makeDeflectedCorrugatedSpringFunction, "name") = c("Deflected Corrugated Spring")
attr(makeDeflectedCorrugatedSpringFunction, "type") = c("single-objective")
attr(makeDeflectedCorrugatedSpringFunction, "tags") = c("single-objective", "continuous", "differentiable", "non-separable", "scalable", "multimodal")
jakobbossek/smoof documentation built on Feb. 17, 2024, 2:23 a.m.