Skip to content

Commit

Permalink
cleanup makeOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbossek committed Dec 6, 2015
1 parent a2d2a17 commit 16cfbab
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions R/makeOperator.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#' @title
#' Construct evolutionary operator.
#' @title Construct evolutionary operator.
#'
#' @description
#' Helper function which constructs an evolutionary operator.
#' Helper function which constructs an evolutionary operator.
#'
#' @note
#' In general you will not need this function, but rather one of its
#' deriviatives like \code{\link{makeMutator}} or \code{\link{makeSelector}}.
#' In general you will not need this function, but rather one of its
#' deriviatives like \code{\link{makeMutator}} or \code{\link{makeSelector}}.
#'
#' @param operator [\code{function}]\cr
#' Actual mutation operator.
Expand All @@ -15,18 +14,20 @@
#' @param description [\code{character(1)}]\cr
#' Short description of how the mutator works.
#' Default is \code{NULL} which means no description at all.
#' @param params [\code{list}]\cr
#' Named list of the parameters the operator has been initialized with.
#' Default is the empty list.
#' @param supported [\code{character}]\cr
#' Vector of names of supported parameter representations. Possible choices:
#' \dQuote{permutation}, \dQuote{float}, \dQuote{binary} or \dQuote{custom}.
#' @param params [\code{list}]\cr
#' Named list of the parameters the operator has been initialized with.
#' Default is the empty list.
#' @return [\code{ecr_operator}] Operator object.
#' @export
makeOperator = function(operator, name, description = NULL,
makeOperator = function(
operator,
name,
description = NULL,
supported = getAvailableRepresentations(),
params = list(),
supported.opt.direction = c("minimize", "maximize")) {
params = list()) {
assertFunction(operator)
assertString(name)
if (!is.null(description)) {
Expand All @@ -35,17 +36,16 @@ makeOperator = function(operator, name, description = NULL,
assertSubset(supported, choices = getAvailableRepresentations(), empty.ok = FALSE)
assertList(params, unique = TRUE, any.missing = FALSE, all.missing = FALSE)

attr(operator, "name") = name
attr(operator, "description") = coalesce(description, "-")
attr(operator, "supported") = supported
attr(operator, "params") = params
operator = setAttribute(operator, "name", name)
operator = setAttribute(operator, "description", coalesce(description, "-"))
operator = setAttribute(operator, "supported", supported)
operator = setAttribute(operator, "params", params)

operator = addClasses(operator, c("ecr_operator"))
return(operator)
}

#' @title
#' Determine the name of a given operator.
#' @title Determine the name of a given operator.
#'
#' @param operator [\code{ecr_operator}]\cr
#' Operator object.
Expand All @@ -61,8 +61,7 @@ getOperatorName.ecr_operator = function(operator) {
attr(operator, "name")
}

#' @title
#' Check if given function is an ecr operator.
#' @title Check if given function is an ecr operator.
#'
#' @param obj [any]\cr
#' Arbitrary R object to check.
Expand Down Expand Up @@ -92,8 +91,7 @@ print.ecr_selector = function(x, ...) {
catf("Supported #objectives: %s", attr(x, "supported.objectives"))
}

#' @title
#' Returns the character vector of tags which describe a specific operator.
#' @title Returns the character vector of tags which describe a specific operator.
#'
#' @param operator [\code{ecr_operator}]\cr
#' Operator object.
Expand All @@ -109,8 +107,7 @@ getSupportedRepresentations.ecr_operator = function(operator) {
attr(operator, "supported")
}

#' @title
#' Check if ecr operator supports given representation.
#' @title Check if ecr operator supports given representation.
#'
#' @param operator [\code{ecr_operator}]\cr
#' Object of type \code{ecr_operator}.
Expand Down

0 comments on commit 16cfbab

Please sign in to comment.