Created
July 8, 2016 14:14
-
-
Save Yuemashi/b5908a1ded4949709d7ae55c412fba88 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
nextGeneration = -> population { | |
population = selection[population] | |
elite = population.take(1).flatten | |
nextPop = [] | |
(0..population.length / 2 - 1) | |
.each{crossover[ | |
[] << population[rand(population.length - 1)] << population[rand(population.length - 1)], | |
rand(population[1].length - 1)] | |
.map{|g| nextPop << g}} | |
nextPop = nextPop | |
.map{|n| (0..n.length - 1) | |
.map{|p| rand(0.0..1.0) < 0.05 ? Genotype[1] : n[p] }.flatten } | |
nextPop.sort_by { |n| -fitness[n]}.take(nextPop.length - 1) << elite } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment