R/hasConstraints.R

Defines functions hasOtherConstraints.smoof_wrapped_function hasOtherConstraints.smoof_function hasOtherConstraints hasBoxConstraints.smoof_wrapped_function hasBoxConstraints.smoof_function hasBoxConstraints hasConstraints.smoof_wrapped_function hasConstraints.smoof_function hasConstraints

Documented in hasBoxConstraints hasConstraints hasOtherConstraints

#' Checks whether the objective function has constraints.
#'
#' @template arg_smoof_function
#' @return [\code{logical(1)}]
#' @export
hasConstraints = function(fn) {
  UseMethod("hasConstraints")
}

#' @export
hasConstraints.smoof_function = function(fn) {
  (hasBoxConstraints(fn) || hasOtherConstraints(fn))
}

#' @export
hasConstraints.smoof_wrapped_function = function(fn) {
  fn = getWrappedFunction(fn)
  return(hasBoxConstraints(fn) || hasOtherConstraints(fn))
}

#' Checks whether the objective function has box constraints.
#'
#' @template arg_smoof_function
#' @return [\code{logical(1)}]
#' @export
hasBoxConstraints = function(fn) {
  UseMethod("hasBoxConstraints")
}

#' @export
hasBoxConstraints.smoof_function = function(fn) {
  return(hasFiniteBoxConstraints(getParamSet(fn)))
}

#' @export
hasBoxConstraints.smoof_wrapped_function = function(fn) {
  return(hasFiniteBoxConstraints(getParamSet(getWrappedFunction(fn))))
}

#' Checks whether the objective function has other constraints.
#'
#' @template arg_smoof_function
#' @return [\code{logical(1)}]
#' @export
hasOtherConstraints = function(fn) {
  UseMethod("hasOtherConstraints")
}

#' @export
hasOtherConstraints.smoof_function = function(fn) {
  return(!is.null(attr(fn, "constraint.fn")))
}

#' @export
hasOtherConstraints.smoof_wrapped_function = function(fn) {
  return(hasOtherConstraints(getWrappedFunction(fn)))
}

Try the smoof package in your browser

Any scripts or data that you put into this service are public.

smoof documentation built on March 31, 2023, 11:48 p.m.