diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Genome.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Genome.hs b/src/Genome.hs index 927005e..e0091b9 100644 --- a/src/Genome.hs +++ b/src/Genome.hs @@ -9,6 +9,7 @@ module Genome , mutateGenomeAddInternal , mutateGenomeRemoveInternal , mutateGenomeAddGene + , mutateGenomeRemoveGene ) where @@ -149,8 +150,6 @@ mutateGenomeAddGene g r = gene = Gene so si w in (g {genes = gene:(genes g)}, r''') - - randomSource :: RandomGen a => Genome -> a -> (NeuronIndex, a) randomSource g r = let @@ -164,3 +163,12 @@ randomSink g r = (idx, r') = randomR (0, numInternal g + numOutput g - 1) r result = if idx < numInternal g then Internal idx else Output $ idx - numInput g in (result, r') + + +-- remove a random gene +mutateGenomeRemoveGene :: RandomGen a => Genome -> a -> (Genome, a) +mutateGenomeRemoveGene g r = + let + (idx, r') = randomR (0, (length $ genes g) - 1) r + (front, _:back) = splitAt idx (genes g) + in (g {genes = front ++ back}, r') |