Implement :bmx-same-gene-count to select only second parents with same number of genes as first

This commit is contained in:
Lee Spector 2023-12-21 19:08:11 -05:00
parent 1e29f88405
commit d9e5523c99

View File

@ -232,13 +232,17 @@ The function `new-individual` returns a new individual produced by selection and
; ;
:bmx ;; best match crossover :bmx ;; best match crossover
(let [parent1 (selection/select-parent pop argmap) (let [parent1 (selection/select-parent pop argmap)
parent2 (if (:bmx-complementary? argmap) parent2 (let [pool (if (:bmx-same-gene-count argmap)
(selection/select-parent (let [n (utils/count-genes (:plushy parent1))]
pop (filter #(= n (utils/count-genes (:plushy %))) pop))
(assoc argmap pop)]
:initial-cases (if (:bmx-complementary? argmap)
(reverse (:selection-cases parent1)))) (selection/select-parent
(selection/select-parent pop argmap)) pool
(assoc argmap
:initial-cases
(reverse (:selection-cases parent1))))
(selection/select-parent pool argmap)))
plushy1 (:plushy parent1) plushy1 (:plushy parent1)
plushy2 (:plushy parent2) plushy2 (:plushy parent2)
bmx-exchange-rate (utils/onenum (or (:bmx-exchange-rate argmap) 0.5)) bmx-exchange-rate (utils/onenum (or (:bmx-exchange-rate argmap) 0.5))
@ -259,12 +263,16 @@ The function `new-individual` returns a new individual produced by selection and
(let [umad-rate (utils/onenum (:umad-rate argmap)) (let [umad-rate (utils/onenum (:umad-rate argmap))
gap-change-prob (utils/onenum (:bmx-gap-change-probability argmap))] gap-change-prob (utils/onenum (:bmx-gap-change-probability argmap))]
(-> (let [parent1 (selection/select-parent pop argmap) (-> (let [parent1 (selection/select-parent pop argmap)
parent2 (if (:bmx-complementary? argmap) parent2 (let [pool (if (:bmx-same-gene-count argmap)
(selection/select-parent pop (let [n (utils/count-genes (:plushy parent1))]
(assoc argmap (filter #(= n (utils/count-genes (:plushy %))) pop))
:initial-cases pop)]
(reverse (:selection-cases parent1)))) (if (:bmx-complementary? argmap)
(selection/select-parent pop argmap)) (selection/select-parent pool
(assoc argmap
:initial-cases
(reverse (:selection-cases parent1))))
(selection/select-parent pool argmap)))
plushy1 (:plushy parent1) plushy1 (:plushy parent1)
plushy2 (:plushy parent2) plushy2 (:plushy parent2)
bmx-exchange-rate (utils/onenum (or (:bmx-exchange-rate argmap) 0.5)) bmx-exchange-rate (utils/onenum (or (:bmx-exchange-rate argmap) 0.5))