Learn R Programming

xegaGaGene (version 1.0.0.4)

xegaGaReplicate2GenePipeline: Replicates a gene with a crossover operator with 2 kids by generating a list of function closures.

Description

xegaGaReplicate2GenePipeline() replicates a gene by 3 random experiments which determine if a mutation operator (boolean variable mut1 and mut2) and/or a crossover operator (boolean variable cross should be applied. For each of the 8 cases, the appropriate pipeline constructor is executed and the genetic operator pipeline(s) is (are) returned.

Usage

xegaGaReplicate2GenePipeline(pop, fit, lF)

Value

A list of either 1 or 2 function closures with the operator pipeline.

Arguments

pop

A population of binary genes.

fit

Fitness vector.

lF

The local configuration of the genetic algorithm.

Details

xegaGaReplicate2GenePipeline() implements the control flow by case distinction which depends on the random choices for mutation and crossover. The pipeline constructor chosen returns the function closure with the appropriate genetic operator pipeline.

  1. A gene g is selected and the boolean variables mut1, mut2, and cross are set to runif(1)<rate. rate is given by lF$MutationRate() or lF$CrossRate().

  2. The truth values of cross, mut1, and mut2 determine the genetic operator pipeline constructor that is executed:

    1. (cross==FALSE) & (mut1==FALSE) is implicit: Executes the pipeline constructor newPipeline.

    2. (cross==TRUE) & (mut1==TRUE) & (mut2==TRUE): Crossover, mutation on both kids. Executes the genetic operator pipeline constructor newCrossMut2Pipeline.

    3. (cross==TRUE) & (mut1==TRUE) & (mut2==FALSE): Crossover, mutation on first kid. Executes the genetic operator pipeline constructor newCross2Mut1Pipeline.

    4. (cross==TRUE) & (mut1==FALSE) & (mut2==TRUE): Crossover, mutation on second kid. Executes the genetic operator pipeline constructor newCross2Mut2Pipeline.

    5. (cross==TRUE) & (mut1==FALSE) & (mut2==FALSE): Crossover (2 kids). Executes the genetic operator pipeline constructor newCross2Pipeline.

    6. (cross==FALSE) & (mut1==TRUE): Mutation. Executes the genetic operator pipeline constructor newMutPipeline.

See Also

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

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<-xegaGaReplicate2GenePipeline(pop10, fit10, lFxegaGaGene)

Run the code above in your browser using DataLab