Learn R Programming

xegaGaGene (version 1.0.0.6)

xegaGaReplicate2Gene: Replicates a gene with a crossover operator with 2 kids.

Description

xegaGaReplicate2Gene() replicates a gene by 2 random experiments which determine if a mutation operator (boolean variable mut) and/or a crossover operator (boolean variable cross should be applied. For each of the 4 cases, the appropriate code is executed and the genes are generated.

Usage

xegaGaReplicate2Gene(pop, fit, lF)

Value

A list of either 1 or 2 binary genes.

Arguments

pop

A population of binary genes.

fit

Fitness vector.

lF

The local configuration of the genetic algorithm.

Details

xegaGaReplicate2Gene() implements the control flow by case distinction which depends 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. rate is given by lF$MutationRate() or lF$CrossRate().

  2. The truth values of cross and mut determine the code that is executed:

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

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

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

    4. (cross==FALSE) & (mut==FALSE) is implicit: Returns a gene list.

See Also

Other Replication: xegaGaReplicate2GenePipeline(), xegaGaReplicate2GenePipelineG(), xegaGaReplicateGene(), xegaGaReplicateGenePipeline(), xegaGaReplicateGenePipelineG()

Examples

Run this code
lFxegaGaGene$CrossGene<-xegaGaCross2Gene
lFxegaGaGene$MutationRate<-function(fit, lF) {0.001}
names(lFxegaGaGene)
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<-xegaGaReplicate2Gene(pop10, fit10, lFxegaGaGene)

Run the code above in your browser using DataLab