Package de.sfuhrm.genetic
Class GeneticAlgorithm<H>
- java.lang.Object
-
- de.sfuhrm.genetic.GeneticAlgorithm<H>
-
- Type Parameters:
H- The hypothesis class to use.
public class GeneticAlgorithm<H> extends Object
Central entry class for generic algorithm implementations. There are two approaches you can take:- High-level approach: Call the of the
findMaximum()method. It will iterate multiple generations until thefinish-conditionis met. - Low-Level approach: Iterate yourself and calculate
each generation yourself using the
calculateNextGeneration(List)method. This way you can do your own analysis on the state of the population.
- Author:
- Stephan Fuhrmann
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<H>calculateNextGeneration(List<H> currentGeneration)Calculate one generation step.Optional<H>findMaximum()Perform the genetic optimization.
-
-
-
Method Detail
-
calculateNextGeneration
public List<H> calculateNextGeneration(List<H> currentGeneration)
Calculate one generation step. Takes a current generation and calculates the next generation out of it.- Parameters:
currentGeneration- the current generation of hypothesis handles.- Returns:
- the population of the next generation. This will contain some
individuals from the
currentGenerationinput. - Since:
- 3.0.0
-
findMaximum
public Optional<H> findMaximum()
Perform the genetic optimization. The algorithm will search for an optimal hypothesis untilAlgorithmDefinition.loop(Object)returnsfalse. New hypothesis are created using thehypothesisSupplier.- Returns:
- the maximum
AlgorithmDefinition.calculateFitness(Object)element, if any. - See Also:
AlgorithmDefinition.loop(Object)
-
-