T
- the type of solution to be optimizedpublic class GeneticAlgorithmOptimizer<T extends GeneticAlgorithmSolution>
extends java.lang.Object
Constructor and Description |
---|
GeneticAlgorithmOptimizer(AbstractSolutionFactory<T> factory)
Creates an optimizer which generates a randomized initial population with
default population size, mutation, crossover, and elite rates.
|
GeneticAlgorithmOptimizer(int populationSize,
AbstractSolutionFactory<T> factory)
Creates an optimizer which generates a randomized initial population with
default mutation, crossover, and elite rates.
|
GeneticAlgorithmOptimizer(int populationSize,
double mutationRate,
double crossoverRate,
double elitePercentage,
AbstractSolutionFactory<T> factory)
Creates an optimizer which generates a randomized initial population.
|
GeneticAlgorithmOptimizer(java.util.List<T> population)
Creates an optimizer which runs starting from the initially seeded
population default mutation, crossover, and elite rates.
|
GeneticAlgorithmOptimizer(java.util.List<T> population,
double mutationRate,
double crossoverRate,
double elitePercentage)
Creates an optimizer which runs starting from the initially seeded
population.
|
Modifier and Type | Method and Description |
---|---|
void |
nextGeneration()
Proceeds to the next generation
|
java.util.List<T> |
population()
Returns the current population ordered by fitness.
|
void |
runFor(int generations)
Proceeds the specified number of generations
|
public GeneticAlgorithmOptimizer(AbstractSolutionFactory<T> factory)
factory
- the factory which produces random solutions for the initial
populationpublic GeneticAlgorithmOptimizer(int populationSize, AbstractSolutionFactory<T> factory)
populationSize
- the number of solutions in each generationfactory
- the factory which produces random solutions for the initial
populationpublic GeneticAlgorithmOptimizer(int populationSize, double mutationRate, double crossoverRate, double elitePercentage, AbstractSolutionFactory<T> factory)
populationSize
- the number of solutions in each generationmutationRate
- the chance for a new solution to randomly mutatecrossoverRate
- the chance for a new solution to be generated by combination
of two elite solutions, rather than cloned from oneelitePercentage
- the percentage of solutions in each generation to be
considered elite. The best elitePercentage solutions are
elite.factory
- the factory which produces random solutions for the initial
populationpublic GeneticAlgorithmOptimizer(java.util.List<T> population)
population
- the initial population to optimizepublic GeneticAlgorithmOptimizer(java.util.List<T> population, double mutationRate, double crossoverRate, double elitePercentage)
population
- the initial population to optimizemutationRate
- the chance for a new solution to randomly mutatecrossoverRate
- the chance for a new solution to be generated by combination
of two elite solutions, rather than cloned from oneelitePercentage
- the percentage of solutions in each generation to be
considered elite. The best elitePercentage solutions are
elite.public void nextGeneration()
public java.util.List<T> population()
public void runFor(int generations)
generations
- the number of generations to move forward