Created
March 22, 2015 22:15
-
-
Save cshepp/f5ea5f241ffe5e3ab4b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def fitness-multiplier 100) | |
(defn roulette-select [population] | |
"randomly selects solutions - | |
probability of being selected is | |
weighted using fitness score" | |
(let [roulette-wheel (reduce #(conj %1 (+ (* (- 700 %2) fitness-multiplier) (last %1))) [0] (map calculate-fitness population)) | |
total (last roulette-wheel)] | |
(mapv (fn [x] (nth population (.indexOf roulette-wheel (first (filter #(< (rand-int total) %1) roulette-wheel))))) | |
(range (count population))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment