summaryrefslogtreecommitdiff
path: root/src/Genome.hs
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-29 16:45:14 -0600
committersanine <sanine.not@pm.me>2023-11-29 16:45:14 -0600
commitd28e8e243d3d6563c0f1036aa0b74e0d0c77c80a (patch)
treec09770815f64468c65bfb99823bb223879a3b5bb /src/Genome.hs
parent4c63f3d4dba0c7164cce9559f09dc82612cdee36 (diff)
implement mutateGenomeRemoveGene
Diffstat (limited to 'src/Genome.hs')
-rw-r--r--src/Genome.hs12
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')