Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created January 6, 2011 01:30
Show Gist options
  • Save fearofcode/767365 to your computer and use it in GitHub Desktop.
Save fearofcode/767365 to your computer and use it in GitHub Desktop.
main loop of simple genetic algorithm (real-to-real function optimizer)
public double[] runGenerations(int generations, int tournamentSize) {
int generation = 1;
while(generation <= generations) {
computeFitness();
double[][] parents = selectParentsByTournament(tournamentSize);
double[][] children = breedChildrenFromParents(parents);
for(double[] child : children) {
insertChild(child);
}
generation++;
}
return fittestIndividual();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment