Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created December 10, 2022 12:40
Show Gist options
  • Save deleteman/14aab316bfbc0c72c5ec1f2703683e90 to your computer and use it in GitHub Desktop.
Save deleteman/14aab316bfbc0c72c5ec1f2703683e90 to your computer and use it in GitHub Desktop.
// run the genetic algorithm for a specified number of iterations
for (let i = 0; i < MAX_ITERATIONS; i++) {
population = evolve(population);
}
// sort the population by fitness
population.sort((a, b) => calculateFitness(a) - calculateFitness(b));
// print the best individual
console.log(population[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment