16 Genetic Algorithms16.1 OverviewThe genetics package provides a framework and implementations for genetic algorithms. 16.2 GA Framework
GeneticAlgorithm provides an execution framework for Genetic Algorithms (GA).
Populations, consisting of
Chromosomes are evolved by the
The GA itself is implemented by the public Population evolve(Population initial, StoppingCondition condition) { Population current = initial; while (!condition.isSatisfied(current)) { current = nextGeneration(current); } return current; } nextGeneration method implements the following algorithm:
16.3 ImplementationHere is an example GA execution: // initialize a new genetic algorithm GeneticAlgorithm ga = new GeneticAlgorithm( new OnePointCrossover<Integer>(), 1, new RandomKeyMutation(), 0.10, new TournamentSelection(TOURNAMENT_ARITY) ); // initial population Population initial = getInitialPopulation(); // stopping condition StoppingCondition stopCond = new FixedGenerationCount(NUM_GENERATIONS); // run the algorithm Population finalPopulation = ga.evolve(initial, stopCond); // best chromosome from the final population Chromosome bestFinal = finalPopulation.getFittestChromosome(); GeneticAlgorithm constructor above are:
The algorithm starts with an initial population of Chromosomes. and executes until
the specified StoppingCondition
is reached. In the example above, a
FixedGenerationCount
stopping condition is used, which means the algorithm proceeds through a fixed number of generations.
|