Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9587477e89
Fetching contributors…

Cannot retrieve contributors at this time

97 lines (88 sloc) 3.293 kb
{-|
This module contains wrappers around the purely functional gene operations
in "GEP.GeneOperations" in order to string the random number generation
state through via the "GEP.Rmonad". These helper functions are responsible
for sampling the random number generator to determine the parameters for
applying the genetic operators.
The reasoning behind using a specialized Random monad instead of the
system generator provided by IO is that this allows independent
generators to be used should we support multiple threads of execution.
Parallel random number generation requires distinct generators, not a
shared one.
Author: mjsottile\@computer.org
-}
module GEP.MonadicGeneOperations where
import GEP.Rmonad
import GEP.GeneOperations
import GEP.Types
import GEP.Params
{-|
IS Transposition helper
-}
isTransposer :: Genome ->
SimParams ->
Chromosome ->
GEPMonad Chromosome
isTransposer genome params who =
do takelen <- nextR (maxISLen params)
takepos <- nextR ((geneLength genome)-takelen)
whichgene <- nextR (numGenes genome)
putpos <- nextR ((headLength genome)-1)
return $ transposeIS who genome (whichgene-1) takepos takelen (putpos+1)
{-|
RIS Transposition helper
-}
risTransposer :: Genome ->
SimParams ->
Chromosome ->
GEPMonad Chromosome
risTransposer genome params who =
do takelen <- nextR (maxRISLen params)
takepos <- nextR ((headLength genome)-1)
genenum <- nextR (numGenes genome)
return $ transposeRIS who genome genenum (takepos+1) takelen
{-|
Gene transposition helper
-}
geneTransposer :: Genome ->
Chromosome ->
GEPMonad Chromosome
geneTransposer genome who =
do whichGene <- nextR (numGenes genome)
return $ transposeGene who genome whichGene
{-|
One-point crossover helper. Takes a genome, a pair of individuals,
and selects the crossover point before generating the new pair of
resulting individuals after crossover.
-}
x1PHelper :: Genome ->
(Chromosome,Chromosome) ->
GEPMonad (Chromosome,Chromosome)
x1PHelper g pair =
do xoverPos <- nextR (geneLength g)
return $ crossover1pt pair xoverPos
{-|
Two-point crossover helper. Takes a genome, a pair of individuals,
and selects the crossover points before generating the new pair of
resulting individuals after crossover.
-}
x2PHelper :: Genome ->
(Chromosome,Chromosome) ->
GEPMonad (Chromosome,Chromosome)
x2PHelper g pair =
do xoverPos1 <- nextR (geneLength g)
xoverPos2 <- nextRDifferent (geneLength g) xoverPos1
return $ crossover2pt pair (min xoverPos1 xoverPos2)
(max xoverPos1 xoverPos2)
{-|
Gene crossover helper. Takes a genome, a pair of individuals, and
selects the crossover gene before generating the new pair of
individuals resulting after crossover.
-}
xGHelper :: Genome ->
(Chromosome, Chromosome) ->
GEPMonad (Chromosome,Chromosome)
xGHelper g pair | (numGenes g) == 1 = return pair
xGHelper g pair | otherwise = do
xoverGene <- nextR (numGenes g)
return $ crossoverGene pair xoverGene (geneLength g)
Jump to Line
Something went wrong with that request. Please try again.