From d28e8e243d3d6563c0f1036aa0b74e0d0c77c80a Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 29 Nov 2023 16:45:14 -0600 Subject: implement mutateGenomeRemoveGene --- src/Genome.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/Genome.hs') 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') -- cgit v1.2.1