Created
March 22, 2015 21:10
-
-
Save cshepp/da6082d77bbe7520b54c 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
(defn calculate-fitness [genome] | |
"Returns the total distance travelled for a given solution" | |
(let [path (pathify genome) | |
distances (map get-distance path)] | |
(reduce + distances))) | |
(defn pathify [vec] | |
"turns a vector into a vector of transitions, | |
including last element back to the first | |
ex: [0 1 2] -> [[0 1] [1 2] [2 0]]" | |
(map (fn [i] | |
(subvec (into vec vec) i (+ 2 i))) | |
(range (count vec)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment