Values between two individuals are exchanged. This is relatively useless as an operator by itself, but is used
in combination with RecombinatorCmpMaybe to get a recombinator that is crossing over individuals
uniformly at random. Because this is such a frequently-used operation, the RecombinatorCrossoverUniform pseudo-class
exists as a shortcut.
None.
This Recombinator can be created with the short access form rec()
(recs() to get a list), or through the the dictionary
dict_recombinators in the following way:
Other recombinators:
OperatorCombination,
Recombinator,
RecombinatorPair,
dict_recombinators_cmpmaybe,
dict_recombinators_convex,
dict_recombinators_cvxpair,
dict_recombinators_maybe,
dict_recombinators_null,
dict_recombinators_proxy,
dict_recombinators_sbx,
dict_recombinators_sequential,
dict_recombinators_xonary,
dict_recombinators_xounif
miesmuschel::MiesOperator -> miesmuschel::Recombinator -> miesmuschel::RecombinatorPair -> RecombinatorSwap
new()Initialize the RecombinatorCrossoverSwap object.
RecombinatorSwap$new(keep_complement = TRUE)set.seed(1)
rs = rec("swap")
p = ps(x = p_int(-5, 5), y = p_dbl(-5, 5), z = p_dbl(-5, 5))
data = data.frame(x = 0:5, y = 0:5, z = 0:5)
rs$prime(p)
rs$operate(data)
#> x y z
#> 1 1 1 1
#> 2 0 0 0
#> 3 3 3 3
#> 4 2 2 2
#> 5 5 5 5
#> 6 4 4 4
rx = rec("cmpmaybe", rec("swap"), p = 0.5) # the same as 'rec("xounif")'
rx$prime(p)
rx$operate(data)
#> x y z
#> 1 1 1 0
#> 2 0 0 1
#> 3 2 3 2
#> 4 3 2 3
#> 5 4 4 4
#> 6 5 5 5