This function builds a simple wrapper around an evolutionary operator, i.e., mutator, recombinator or selector and defines its parameters. The result is a function that does not longer depend on the parameters. E.g., fun = setup(mutBitflip, p = 0.3) initializes a bitflip mutator with mutation probability 0.3. Thus, the following calls have the same behaviour: fun(c(1, 0, 0)) and mutBitflip(fun(c(1, 0, 0), p = 0.3). Basically, this type of preinitialization is only neccessary if operators with additional parameters shall be initialized in order to use the black-box ecr.

setup(operator, ...)

Arguments

operator

[ecr_operator] Evolutionary operator.

...

[any] Furhter parameters for operator.

Value

[function] Wrapper evolutionary operator with parameters x and ....

Examples

# initialize bitflip mutator with p = 0.3 bf = setup(mutBitflip, p = 0.3) # sample binary string x = sample(c(0, 1), 100, replace = TRUE) set.seed(1) # apply preinitialized function print(bf(x))
#> [1] 0 1 1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 1 0 0 0 #> [38] 0 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 1 1 1 1 1 1 0 #> [75] 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
set.seed(1) # apply raw function print(mutBitflip(x, p = 0.3))
#> [1] 0 1 1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 1 0 0 0 #> [38] 0 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 1 1 1 1 1 1 0 #> [75] 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
# overwrite preinitialized values with mutate ctrl = initECRControl(fitness.fun = function(x) sum(x), n.objectives = 1L) # here we define a mutation probability of 0.3 ctrl = registerECROperator(ctrl, "mutate", setup(mutBitflip, p = 0.3)) # here we overwrite with 1, i.e., each bit is flipped print(x)
#> [1] 1 1 1 0 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 1 0 1 0 0 0 0 #> [38] 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1 0 1 1 1 1 0 #> [75] 1 0 0 0 0 0 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0
print(mutate(ctrl, list(x), p.mut = 1, p = 1)[[1]])
#> [1] 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 1 0 1 0 1 0 1 1 1 1 #> [38] 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 #> [75] 0 1 1 1 1 1 0 1 0 0 0 1 0 1 0 0 0 0 1 1 1 1 1 1 1 1