Class EvolutionUtils
- java.lang.Object
-
- org.uncommons.watchmaker.framework.EvolutionUtils
-
public final class EvolutionUtils extends Object
Utility methods used by different evolution implementations. This class exists to avoid duplication of this logic among multiple evolution implementations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> PopulationData<T>
getPopulationData(List<EvaluatedCandidate<T>> evaluatedPopulation, boolean naturalFitness, int eliteCount, int iterationNumber, long startTime)
Gets data about the current population, including the fittest candidate and statistics about the population as a whole.static <T> List<TerminationCondition>
shouldContinue(PopulationData<T> data, TerminationCondition... conditions)
Given data about the current population and a set of termination conditions, determines whether or not the evolution should continue.static <T> void
sortEvaluatedPopulation(List<EvaluatedCandidate<T>> evaluatedPopulation, boolean naturalFitness)
Sorts an evaluated population in descending order of fitness (descending order of fitness score for natural scores, ascending order of scores for non-natural scores).
-
-
-
Method Detail
-
shouldContinue
public static <T> List<TerminationCondition> shouldContinue(PopulationData<T> data, TerminationCondition... conditions)
Given data about the current population and a set of termination conditions, determines whether or not the evolution should continue.- Type Parameters:
T
- The type of entity that is being evolved.- Parameters:
data
- The current state of the population.conditions
- One or more termination conditions. The evolution should not continue if any of these is satisfied.- Returns:
- A list of satisfied termination conditions if the evolution has reached some pre-specified state, an empty list if the evolution should stop because of a thread interruption, or null if the evolution should continue.
-
sortEvaluatedPopulation
public static <T> void sortEvaluatedPopulation(List<EvaluatedCandidate<T>> evaluatedPopulation, boolean naturalFitness)
Sorts an evaluated population in descending order of fitness (descending order of fitness score for natural scores, ascending order of scores for non-natural scores).- Type Parameters:
T
- The type of entity that is being evolved.- Parameters:
evaluatedPopulation
- The population to be sorted (in-place).naturalFitness
- True if higher fitness scores mean fitter individuals, false otherwise.
-
getPopulationData
public static <T> PopulationData<T> getPopulationData(List<EvaluatedCandidate<T>> evaluatedPopulation, boolean naturalFitness, int eliteCount, int iterationNumber, long startTime)
Gets data about the current population, including the fittest candidate and statistics about the population as a whole.- Type Parameters:
T
- The type of entity that is being evolved.- Parameters:
evaluatedPopulation
- Population of candidate solutions with their associated fitness scores.naturalFitness
- True if higher fitness scores mean fitter individuals, false otherwise.eliteCount
- The number of candidates preserved via elitism.iterationNumber
- The zero-based index of the current generation/epoch.startTime
- The time at which the evolution began, expressed as a number of milliseconds since 00:00 on 1st January 1970.- Returns:
- Statistics about the current generation of evolved individuals.
-
-