Only exchange in bmx with distance <= a limit, hardcoded to 4 for now

This commit is contained in:
Lee Spector 2023-12-10 14:37:45 -05:00
parent 49f6f6de72
commit a706babff1

View File

@ -170,11 +170,22 @@ The function `new-individual` returns a new individual produced by selection and
[plushy-a plushy-b rate] [plushy-a plushy-b rate]
(let [a-genes (utils/extract-genes plushy-a) (let [a-genes (utils/extract-genes plushy-a)
b-genes (utils/extract-genes plushy-b)] b-genes (utils/extract-genes plushy-b)]
(flatten (interpose :gap (flatten
(mapv (fn [g] (interpose
:gap
(mapv (fn [a-gene]
(if (< (rand) rate) (if (< (rand) rate)
(apply min-key #(metrics/unigram-bigram-distance g %) b-genes) (let [match-info (map (fn [b-gene]
g)) {: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))))) a-genes)))))
(defn new-individual (defn new-individual