Skip to content

Instantly share code, notes, and snippets.

@cshepp
Created March 22, 2015 21:26
Show Gist options
  • Save cshepp/ee4df45b45b300616727 to your computer and use it in GitHub Desktop.
Save cshepp/ee4df45b45b300616727 to your computer and use it in GitHub Desktop.
(def num-participants 4) ;; how many solutions should take part in each tournament
(defn tournament-select [population]
"order the members of the population according
to their success in...battles to the death!"
(mapv (fn [x] (let [idxs (repeatedly num-participants #(rand-int (count population)))
participants (map #(population %) idxs)]
(first (sort-by calculate-fitness participants))))
(range (count population))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment