Package de.sfuhrm.genetic
Framework for a calculating genetic algorithm optimization.
Steps for usage
You are usually conducting work with these classes:- Instantiate your
AlgorithmDefinitionwith how to create, update and evaluate so-called hypothesis. - Create a
GeneticAlgorithmwith the help of aGeneticAlgorithmBuilder. - Call either
GeneticAlgorithm.findMaximum()for the generational loop to be executed for you (less control), orGeneticAlgorithm.calculateNextGeneration(java.util.List)for one generational step to be executed for you (more control). - Evaluate the results, and eventually adapt the parameters in the GeneticAlgorithmBuilder.
What's a hypothesis
A hypothesis is a model of a possible solution that can be any Java object. A hypothesis needs to be evaluated with afitness
towards the fitness in respect to the solution of the problem.
Examples:
- A hypothesis for solving a 9x9 Sudoku can be a two-dimensional 9x9 int array.
- A hypothesis for one Tic-Tac-Toe move can be a x/y coordinate pair of the next move.
Genetic operations in AlgorithmDefinition
The genetic operations are defined on hypothesis basically the following:-
Random initialization: A (usually valid) hypothesis is generated using random values for its components / genes. -
Mutation: A single gene/bit/character/cell of the hypothesis is flipped to another (usually valid) value. -
Cross-over: Two hypothesis are combined at a so-called cross-over point and are recombined to typically two off-springs. The critical part in the cross-over is that the two off-springs should be valid. This restricts the genetic representation of the hypothesis.
- Author:
- Stephan Fuhrmann
-
Interface Summary Interface Description AlgorithmDefinition<T> Hypothesis creation, manipulation and evaluation callbacks for the genetic algorithm. -
Class Summary Class Description GeneticAlgorithm<H> Central entry class for generic algorithm implementations.GeneticAlgorithmBuilder<H> A builder for GeneticAlgorithm instances.