From 55644a9b6d08396a907d45c41154ebb26f580ffe Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Sun, 22 Nov 2020 21:06:39 -0500 Subject: [PATCH] Make crossover, uniform-addition, and uniform-deletion take argmap arguments --- .gitignore | 1 + src/propeller/variation.cljc | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index c8f7bb6..025bb9c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ pom.xml.asc *.iml .idea/ out +notes diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index 03e2837..c3d4213 100755 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -4,7 +4,7 @@ (defn crossover "Crosses over two individuals using uniform crossover. Pads shorter one." - [plushy-a plushy-b] + [plushy-a plushy-b argmap] (let [shorter (min-key count plushy-a plushy-b) longer (if (= shorter plushy-a) plushy-b @@ -19,7 +19,7 @@ (defn uniform-addition "Returns plushy with new instructions possibly added before or after each existing instruction." - [plushy instructions umad-rate] + [plushy instructions umad-rate argmap] (apply concat (map #(if (< (rand) umad-rate) (shuffle [% (utils/random-instruction instructions)]) @@ -28,7 +28,7 @@ (defn uniform-deletion "Randomly deletes instructions from plushy at some rate." - [plushy umad-rate] + [plushy umad-rate argmap] (remove (fn [_] (< (rand) (/ 1 (+ 1 (/ 1 umad-rate))))) plushy)) @@ -42,11 +42,14 @@ (cond (< prob (:crossover (:variation argmap))) (crossover (:plushy (selection/select-parent pop argmap)) - (:plushy (selection/select-parent pop argmap))) + (:plushy (selection/select-parent pop argmap)) + argmap) (< prob (+ (:crossover (:variation argmap)) (:umad (:variation argmap)))) (uniform-deletion (uniform-addition (:plushy (selection/select-parent pop argmap)) (:instructions argmap) - (:umad-rate argmap)) - (/ 1 (+ (/ 1 (:umad-rate argmap)) 1))) + (:umad-rate argmap) + argmap) + (/ 1 (+ (/ 1 (:umad-rate argmap)) 1)) + argmap) :else (:plushy (selection/select-parent pop argmap))))})