From a706babff18bc4da2207ba9c01204014b07e0c5c Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Sun, 10 Dec 2023 14:37:45 -0500 Subject: [PATCH] Only exchange in bmx with distance <= a limit, hardcoded to 4 for now --- src/propeller/variation.cljc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index 61273ae..7d589fc 100644 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -170,12 +170,23 @@ The function `new-individual` returns a new individual produced by selection and [plushy-a plushy-b rate] (let [a-genes (utils/extract-genes plushy-a) b-genes (utils/extract-genes plushy-b)] - (flatten (interpose :gap - (mapv (fn [g] - (if (< (rand) rate) - (apply min-key #(metrics/unigram-bigram-distance g %) b-genes) - g)) - a-genes))))) + (flatten + (interpose + :gap + (mapv (fn [a-gene] + (if (< (rand) rate) + (let [match-info (map (fn [b-gene] + {:distance (metrics/unigram-bigram-distance a-gene b-gene) + :gene b-gene}) + b-genes) + candidates (filter (fn [info] + (<= (:distance info) 4)) + match-info)] + (if (empty? candidates) + a-gene + (:gene (apply min-key :distance candidates)))) + a-gene)) + a-genes))))) (defn new-individual "Returns a new individual produced by selection and variation of