gena.crossover {gena}R Documentation

Crossover

Description

Crossover method (algorithm) to be used in the genetic algorithm.

Usage

gena.crossover(
  parents,
  fitness = NULL,
  prob = 0.8,
  method = "local",
  par = NULL,
  iter = NULL
)

Arguments

parents

numeric matrix which rows are parents i.e. vectors of parameters values.

fitness

numeric vector which i-th element is the value of fn at point population[i, ].

prob

probability of crossover.

method

crossover method to be used for making children.

par

additional parameters to be passed depending on the method.

iter

iteration number of the genetic algorithm.

Details

Denote parents by C^{parent} which i-th row parents[i, ] is a chromosome c_{i}^{parent} i.e. the vector of parameter values of the function being optimized f(.) that is provided via fn argument of gena. The elements of chromosome c_{ij}^{parent} are genes representing parameters values.

Crossover algorithm determines the way parents produce children. During crossover each of randomly selected pairs of parents c_{i}^{parent}, c_{i + 1}^{parent} produce two children c_{i}^{child}, c_{i + 1}^{child}, where i is odd. Each pair of parents is selected with probability prob. If pair of parents have not been selected for crossover then corresponding children and parents are coincide i.e. c_{i}^{child}=c_{i}^{parent} and c_{i+1}^{child}=c_{i+1}^{parent}.

Argument method determines particular crossover algorithm to be applied. Denote by \tau the vector of parameters used by the algorithm. Note that \tau corresponds to par.

If method = "split" then each gene of the first child will be equiprobably picked from the first or from the second parent. So c_{ij}^{child} may be equal to c_{ij}^{parent} or c_{(i+1)j}^{parent} with equal probability. The second child is the reversal of the first one in a sense that if the first child gets particular gene of the first (second) parent then the second child gets this gene from the first (second) parent i.e. if c_{ij}^{child}=c_{ij}^{parent} then c_{(i+1)j}^{child}=c_{(i+1)j}^{parent}; if c_{ij}^{child}=c_{(i+1)j}^{parent} then c_{(i+1)j}^{child}=c_{ij}^{parent}.

If method = "arithmetic" then:

c_{i}^{child}=\tau_{1}c_{i}^{parent}+ \left(1-\tau_{1}\right)c_{i+1}^{parent}

c_{i+1}^{child}=\left(1-\tau_{1}\right)c_{i}^{parent}+ \tau_{1}c_{i+1}^{parent}

where \tau_{1} is par[1]. By default par[1] = 0.5.

If method = "local" then the procedure is the same as for "arithmetic" method but \tau_{1} is a uniform random value between 0 and 1.

If method = "flat" then c_{ij}^{child} is a uniform random number between c_{ij}^{parent} and c_{(i+1)j}^{parent}. Similarly for the second child c_{(i+1)j}^{child}.

For more information on crossover algorithms please see Kora, Yadlapalli (2017).

Value

The function returns a matrix which rows are children.

References

P. Kora, P. Yadlapalli. (2017). Crossover Operators in Genetic Algorithms: A Review. International Journal of Computer Applications, 162 (10), 34-36, <doi:10.5120/ijca2017913370>.

Examples

# Randomly initialize the parents
set.seed(123)
parents.n <- 10
parents <- gena.population(pop.n = parents.n,
                           lower = c(-5, -5), 
                           upper = c(5, 5))
                           
# Perform the crossover
children <- gena.crossover(parents = parents,
                           prob = 0.6,
                           method = "local")
print(children)

[Package gena version 1.0.0 Index]