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.

Configuration Parameters

None.

Supported Operand Types

Supported Param classes are: ParamLgl, ParamInt, ParamDbl, ParamFct

Dictionary

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:

# preferred:
rec("swap")
recs("swap")  # takes vector IDs, returns list of Recombinators

# long form:
dict_recombinators$get("swap")

Methods

Inherited methods


Method new()

Initialize the RecombinatorCrossoverSwap object.

Usage

RecombinatorSwap$new(keep_complement = TRUE)

Arguments

keep_complement

(logical(1))
Whether the operation should keep both resulting individuals (TRUE), or only the first and discard the complement (FALSE). Default TRUE. The $keep_complement field will reflect this value.


Method clone()

The objects of this class are cloneable with this method.

Usage

RecombinatorSwap$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

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