From 224d33c19d7f20822697631cb26b96160f551e6f Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Sun, 22 Nov 2020 21:32:49 -0500 Subject: [PATCH] Add diploid-flip genetic operator --- src/propeller/variation.cljc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index cdf0d9a..de99084 100755 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -67,6 +67,14 @@ (/ 1 (+ 1 (/ 1 umad-rate))))) (partition 2 plushy)))) +(defn diploid-flip + "Randomly flips pairs in a diploid plushy at some rate." + [plushy flip-rate] + (flatten (map #(if (< (rand) flip-rate) + (reverse %) + %) + (partition 2 plushy)))) + (defn new-individual "Returns a new individual produced by selection and variation of individuals in the population."