xegaGaReplicateGene {xegaGaGene} | R Documentation |
xegaGaReplicateGene
replicates a gene
by applying a gene reproduction pipeline
which uses crossover and
mutation.
The control flow may have the following steps:
A gene is selected from the population.
Check if the crossover operation should be applied.
(The check is TRUE
with a probability of crossrate
).
If the check is TRUE
:
Select a mating gene from the population.
Perform the crossover operation.
Apply mutation with a probability of mutrate
.
Return a list one gene.
Apply mutation with a probability of mutrate
.
Accept gene. For genetic algorithms: Identity.
Return a list with a single gene.
xegaGaReplicateGene(pop, fit, lF)
pop |
Population of binary genes. |
fit |
Fitness vector. |
lF |
Local configuration of the genetic algorithm. |
xegaGaReplicateGene
implements the control flow
by a dynamic definition of the operator pipeline depending
on the random choices for mutation and crossover:
A gene g
is selected and the boolean variables mut
and cross
are set to runif(1)<rate
.
The local function for the operator pipeline OPpip(g, lF)
is defined by the truth values of cross
and mut
:
(cross==FALSE) & (mut==FALSE)
:
Identity function.
(cross==TRUE) & (mut==TRUE)
:
Mate selection, crossover, mutation.
(cross==TRUE) & (mut==FALSE)
:
Mate selection, crossover.
(cross==FALSE) & (mut==TRUE)
:
Mutation.
Perform the operator pipeline and accept the result.
A list of one gene.
Other Replication:
xegaGaReplicate2Gene()
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)