Skip to content

Instantly share code, notes, and snippets.

@jfinkels
Created January 14, 2010 04:27
Show Gist options
  • Save jfinkels/276859 to your computer and use it in GitHub Desktop.
Save jfinkels/276859 to your computer and use it in GitHub Desktop.
List<MyIndividual> population = new Vector<MyIndividual>();
// initialize the population with random individuals
//
// ...
//
GeneticEvolutionContext<MyIndividual> context = new GAEvolutionContext<MyIndividual>(population);
context.setCrossoverFunction(new MyCrossoverFunction());
context.setFitnessFunction(new MyFitnessFunction());
context.setMutationFunction(new MyMutationFunction());
context.setSelectionFunction(new FitnessProportionateSelection<MyIndividual>());
int maxGenerations = 100;
MaxGenerationCompletionCondition<MyIndividual> condition = new MaxGenerationCompletionCondition<MyIndividual>();
condition.setMaxGenerations(maxGenerations);
try {
while (!condition.execute(context)) {
context.stepGeneration();
}
} catch (EvolutionException exception) {
// handle the exception
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment