#' @title
#' Bitplip mutator.
#'
#' @description
#' This operator works only on binary representation and flips \eqn{k} randomly
#' selected bits.
#'
#' @references
#' [1] Eiben, A. E. & Smith, James E. (2015). Introduction to Evolutionary
#' Computing (2nd ed.). Springer Publishing Company, Incorporated. 52.
#'
#' @param ind [\code{binary}]\cr
#' Binary vector, i.e., vector with elements 0 and 1 only.
#' @param k [\code{integer(1)}]\cr
#' Number of bits to flip.
#' Default is \code{1}.
#' @return [\code{binary}]
#' @family mutators
#' @export
EAMutatorKBitflip = function(k = 1L) {
EAMutator$new(
name = "K-bitflip mutation",
representations = "binary",
params = list(k = 1L),
fun = function(ind, k = 1L) {
.Call(`_ecr3_EAMutatorKBitflipC`, ind, k)
# n = length(ind)
# #checkmate::assertInt(k, lower = 1L, upper = n)
# mut.idx = sample(seq_len(n), size = k, replace = FALSE)
# ind[mut.idx] = 1 - ind[mut.idx]
# return(ind)
}
)
} # EAMutatorKBitflip
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.