Skip to content

Commit

Permalink
Only exchange in bmx with distance <= a limit, hardcoded to 4 for now
Browse files Browse the repository at this point in the history
  • Loading branch information
lspector committed Dec 10, 2023
1 parent 49f6f6d commit a706bab
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/propeller/variation.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a706bab

Please sign in to comment.