T
- The type of entity that is to be evolved.public class IslandEvolution<T extends java.lang.Comparable<? super T>>
extends java.lang.Object
Constructor and Description |
---|
IslandEvolution(int islandCount,
Migration migration,
CandidateFactory<T> candidateFactory,
EvolutionaryOperator<T> evolutionScheme,
FitnessEvaluator<? super T> fitnessEvaluator,
SelectionStrategy<? super T> selectionStrategy,
java.util.Random rng)
Create an island system with the specified number of
identically-configured islands.
|
IslandEvolution(java.util.List<EvolutionEngine<T>> islands,
Migration migration,
boolean naturalFitness,
java.util.Random rng)
Create an island evolution system from a list of pre-configured islands.
|
Modifier and Type | Method and Description |
---|---|
void |
addEvolutionObserver(IslandEvolutionObserver<? super T> observer)
Adds an observer to the evolution.
|
T |
evolve(int populationSize,
int eliteCount,
int epochLength,
int migrantCount,
TerminationCondition... conditions)
Start the evolutionary process on each island and return the fittest
candidate so far at the point any of the termination conditions is
satisfied.
|
java.util.List<TerminationCondition> |
getSatisfiedTerminationConditions()
Returns a list of all
TerminationCondition s that are satisfied by
the current state of the island evolution. |
void |
removeEvolutionObserver(IslandEvolutionObserver<? super T> observer)
Remove the specified observer.
|
public IslandEvolution(int islandCount, Migration migration, CandidateFactory<T> candidateFactory, EvolutionaryOperator<T> evolutionScheme, FitnessEvaluator<? super T> fitnessEvaluator, SelectionStrategy<? super T> selectionStrategy, java.util.Random rng)
IslandEvolution(List, Migration, boolean, Random)
constructor,
which accepts a list of pre-created islands (each is an instance of
EvolutionEngine
).islandCount
- The number of separate islands that will be part of the
system.migration
- A migration strategy for moving individuals between islands at
the end of an epoch.candidateFactory
- Generates the initial population for each island.evolutionScheme
- The evolutionary operator, or combination of evolutionary
operators, used on each island.fitnessEvaluator
- The fitness function used on each island.selectionStrategy
- The selection strategy used on each island.rng
- A source of randomness, used by all islands.IslandEvolution(List, Migration, boolean, Random)
public IslandEvolution(java.util.List<EvolutionEngine<T>> islands, Migration migration, boolean naturalFitness, java.util.Random rng)
islands
- A list of pre-configured islands.migration
- A migration strategy for moving individuals between islands at
the end of an epoch.naturalFitness
- If true, indicates that higher fitness values mean fitter
individuals. If false, indicates that fitter individuals will
have lower scores.rng
- A source of randomness, used by all islands.IslandEvolution(int, Migration, CandidateFactory,
EvolutionaryOperator, FitnessEvaluator, SelectionStrategy, Random)
public T evolve(int populationSize, int eliteCount, int epochLength, int migrantCount, TerminationCondition... conditions)
Start the evolutionary process on each island and return the fittest candidate so far at the point any of the termination conditions is satisfied.
If you interrupt the request thread before this method returns, the
method will return prematurely (with the best individual found so far).
After returning in this way, the current thread's interrupted flag
will be set. It is preferable to use an appropritate
TerminationCondition
rather than interrupting the evolution in
this way.
populationSize
- The population size for each island. Therefore, if
you have 5 islands, setting this parameter to 200 will result
in 1000 individuals overall, 200 on each island.eliteCount
- The number of candidates preserved via elitism
on each island. In elitism, a sub-set of the
population with the best fitness scores are preserved
unchanged in the subsequent generation. Candidate solutions
that are preserved unchanged through elitism remain eligible
for selection for breeding the remainder of the next
generation. This value must be non-negative and less than the
population size. A value of zero means that no elitism will be
applied.epochLength
- The number of generations that make up an epoch. Islands
evolve independently for this number of generations and then
migration occurs at the end of the epoch and the next epoch
starts.migrantCount
- The number of individuals that will be migrated from each
island at the end of each epoch.conditions
- One or more conditions that may cause the evolution to
terminate.public java.util.List<TerminationCondition> getSatisfiedTerminationConditions()
Returns a list of all TerminationCondition
s that are satisfied by
the current state of the island evolution. Usually this list will contain
only one item, but it is possible that mutliple termination conditions
will become satisfied at the same time. In this case the condition
objects in the list will be in the same order that they were specified
when passed to the engine.
If the evolution has not yet terminated (either because it is still in progress or because it hasn't even been started) then an IllegalStateException will be thrown.
If the evolution terminated because the request thread was interrupted before any termination conditions were satisfied then this method will return an empty list.
java.lang.IllegalStateException
- If this method is invoked on an island system before
evolution is started or while it is still in progress.public void addEvolutionObserver(IslandEvolutionObserver<? super T> observer)
Adds an observer to the evolution. Observers will receives two types of updates: updates from each individual island at the end of each generation, and updates for the combined global population at the end of each epoch.
Updates are dispatched synchronously on the request thread. Observers should complete their processing and return in a timely manner to avoid holding up the evolution.
observer
- The callback that will be notified at the end of each
generation and epoch.removeEvolutionObserver(IslandEvolutionObserver)
public void removeEvolutionObserver(IslandEvolutionObserver<? super T> observer)
observer
- The observer to remove (if it is registered).addEvolutionObserver(IslandEvolutionObserver)