R/operator.EAMutatorInversion.R

Defines functions EAMutatorInversion

#' @title
#' Inversion mutator.
#'
#' @description
#' The Inversion mutation operator selects two positions within the chromosome at
#' random and inverts the elements inbetween.
#'
#' @param ind [\code{integer}]\cr
#'   Permutation of integers, i.e., vector of integer values.
#' @return [\code{integer}]
#' @family mutators
#' @export
EAMutatorInversion = function() {
  EAMutator$new(
    name = "Inversion mutation",
    representations = "permutation",
    params = list(),
    fun = function(ind) {
      n = length(ind)
      idx = sample(seq(n), size = 2L)
      ind[idx[1]:idx[2]] = ind[idx[2]:idx[1]]
      return(ind)
    }
  )
} # EAMutatorInversion
jakobbossek/ecr3 documentation built on Nov. 14, 2019, 7:47 p.m.