Skip to content

Instantly share code, notes, and snippets.

@Yuemashi
Created July 8, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuemashi/b1d7b6ee2a71281deb2853af81bb58b6 to your computer and use it in GitHub Desktop.
Save Yuemashi/b1d7b6ee2a71281deb2853af81bb58b6 to your computer and use it in GitHub Desktop.
crossover = -> parents, position {
[] << parents[0].take(position) + parents[1].drop(position) <<
parents[1].take(position) + parents[0].drop(position) }
mutate = -> individual, position, genotypeDefinition {
individual[position] = genotypeDefinition.curry(1)
individual.flatten }
selection = -> population {
(population + population).sort_by{ |n| -fitness[n]}.take(population.length) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment