Learn R Programming

xegaGaGene (version 1.0.0.4)

xegaGaReplicateGene: Replicates a gene with a crossover operator which returns a single gene.

Description

xegaGaReplicateGene() replicates a gene by applying a gene reproduction pipeline which uses crossover and mutation and finishes with an acceptance rule. The control flow starts by selecting a gene from the population followed by the case distinction:

  • Check if the mutation operation should be applied. (mut is TRUE with a probability of lF$MutationRate()).

  • Check if the crossover operation should be applied. (cross is TRUE with a probability of lF$CrossRate()).

The state distinction determines which genetic operations are performed.

Usage

xegaGaReplicateGene(pop, fit, lF)

Value

A list of one gene.

Arguments

pop

Population of binary genes.

fit

Fitness vector.

lF

Local configuration of the genetic algorithm.

Details

xegaGaReplicateGene() implements the control flow by a dynamic definition of the operator pipeline depending on the random choices for mutation and crossover:

  1. A gene g is selected and the boolean variables mut and cross are set to runif(1)<rate.

  2. The local function for the operator pipeline OPpip(g, lF) is defined by the truth values of cross and mut:

    1. (cross==FALSE) & (mut==FALSE): Identity function.

    2. (cross==TRUE) & (mut==TRUE): Mate selection, crossover, mutation.

    3. (cross==TRUE) & (mut==FALSE): Mate selection, crossover.

    4. (cross==FALSE) & (mut==TRUE): Mutation.

  3. Perform the operator pipeline and accept the result. The acceptance step allows the combination of a genetic algorithm with other heuristic algorithms like simulated annealing by executing an acceptance rule. For the genetic algorithm, the identity function is used.

See Also

Other Replication: xegaGaReplicate2Gene(), xegaGaReplicate2GenePipeline(), xegaGaReplicateGenePipeline()

Examples

Run this code
lFxegaGaGene$CrossGene<-xegaGaCrossGene
lFxegaGaGene$MutationRate<-function(fit, lF) {0.001}
lFxegaGaGene$Accept<-function(OperatorPipeline, gene, lF) {gene}
pop10<-lapply(rep(0,10), function(x) xegaGaInitGene(lFxegaGaGene))
epop10<-lapply(pop10, lFxegaGaGene$EvalGene, lF=lFxegaGaGene)
fit10<-unlist(lapply(epop10, function(x) {x$fit}))
newgenes<-xegaGaReplicateGene(pop10, fit10, lFxegaGaGene)

Run the code above in your browser using DataLab