Class EASystem<T extends Comparable<T>>
- Type Parameters:
T
- the type of fitness values, must be comparable for selection and ranking
EASystem serves as the central coordinator that brings together all components of an evolutionary algorithm including genetic operators, selection strategies, evaluation functions, and termination criteria. It manages the evolutionary cycle and provides a unified interface for running optimizations.
The system coordinates the following evolutionary process:
- Initialization: Generate initial population of random genotypes
- Evaluation: Compute fitness values for all individuals
- Selection: Choose parents for reproduction based on fitness
- Reproduction: Create offspring through crossover and mutation
- Replacement: Integrate offspring into next generation
- Termination check: Determine if stopping criteria are met
- Iteration: Repeat until termination conditions are satisfied
Key responsibilities include:
- Population management: Maintaining population size and diversity
- Genetic operator coordination: Applying crossover, mutation, and selection
- Fitness evaluation orchestration: Managing parallel and synchronous evaluation
- Evolution monitoring: Providing hooks for logging and progress tracking
- Resource management: Efficient memory usage and computation distribution
Configuration components:
- EAConfiguration: Defines genetic representation and operator policies
- EAExecutionContext: Provides runtime services and factory implementations
- FitnessEvaluator: Computes quality measures for candidate solutions
- Termination criteria: Determines when to stop evolution
The system supports various evolutionary paradigms:
- Genetic Algorithms: Traditional binary and real-valued optimization
- Genetic Programming: Evolution of tree-structured programs
- Evolution Strategies: Real-valued optimization with adaptive parameters
- Multi-objective optimization: Pareto-based optimization with multiple objectives
Example usage:
// Configure the evolutionary algorithm
EAConfiguration<Double> config = EAConfigurationBuilder.<Double>builder()
.chromosomeSpecs(DoubleChromosomeSpec.of(10, -5.0, 5.0))
.parentSelectionPolicy(Tournament.of(3))
.mutationPolicy(RandomMutation.of(0.1))
.build();
// Set up execution context
EAExecutionContext<Double> context = EAExecutionContexts.forScalarFitness();
// Create fitness evaluator
Fitness<Double> fitness = genotype -> {
// Implement problem-specific fitness function
return computeFitness(genotype);
};
// Build and run the evolutionary system
EASystem<Double> system = EASystemFactory.from(config, context, fitness);
EvolutionResult<Double> result = system.evolve(
populationSize: 100,
termination: Terminations.generations(1000)
);
Thread safety: EASystem instances are generally not thread-safe and should not be shared between multiple threads without external synchronization. However, the system supports parallel fitness evaluation internally when configured appropriately.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<ChromosomeCombinator<T>> private final ChromosomeFactoryProvider
private final AbstractEAConfiguration
<T> private final AbstractEAExecutionContext
<T> private final FitnessEvaluator
<T> private final GenotypeGenerator
<T> static final org.apache.logging.log4j.Logger
private final double
private final int
private final ReplacementStrategyImplementor
<T> -
Constructor Summary
ConstructorsConstructorDescriptionEASystem
(AbstractEAConfiguration<T> _eaConfiguration, long _populationSize, List<ChromosomeCombinator<T>> _chromosomeCombinators, double _offspringRatio, Selector<T> _parentSelectionPolicyHandler, List<Mutator> _mutators, ReplacementStrategyImplementor<T> _replacementStrategyImplementor, AbstractEAExecutionContext<T> _eaExecutionContext, FitnessEvaluator<T> _fitnessEvaluator) -
Method Summary
Modifier and TypeMethodDescriptioncombineParents
(Population<T> parents, GenotypeCombinator genotypeCombinator) createBasicOffsprings
(Population<T> population, int offspringsNeeded) Create offsprings without mutationcreateOffsprings
(Population<T> population, int offspringsNeeded) Creates offspring from the given population through selection, crossover, and mutation.evaluateOnce
(long generation, List<Genotype> genotypes) Evaluates a collection of genotypes once without running the full evolutionary process.evolve()
Executes the complete evolutionary algorithm process until termination criteria are met.Gets the evolutionary algorithm configuration used by this system.long
Gets the target population size for each generation.mutateGenotypes
(List<Genotype> genotypes)
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger logger -
genotypeGenerator
-
fitnessEvaluator
-
eaConfiguration
-
eaExecutionContext
-
populationSize
private final int populationSize -
chromosomeCombinators
-
chromosomeFactoryProvider
-
replacementStrategyImplementor
private final ReplacementStrategyImplementor<T extends Comparable<T>> replacementStrategyImplementor -
mutators
-
offspringRatio
private final double offspringRatio -
parentSelector
-
-
Constructor Details
-
EASystem
public EASystem(AbstractEAConfiguration<T> _eaConfiguration, long _populationSize, List<ChromosomeCombinator<T>> _chromosomeCombinators, double _offspringRatio, Selector<T> _parentSelectionPolicyHandler, List<Mutator> _mutators, ReplacementStrategyImplementor<T> _replacementStrategyImplementor, AbstractEAExecutionContext<T> _eaExecutionContext, FitnessEvaluator<T> _fitnessEvaluator)
-
-
Method Details
-
evaluate
-
initializePopulation
-
mutateGenotypes
-
combineParents
-
createBasicOffsprings
Create offsprings without mutation- Parameters:
population
-offspringsNeeded
-- Returns:
-
getEAConfiguration
Gets the evolutionary algorithm configuration used by this system.- Returns:
- the EA configuration containing genetic operators, chromosome specs, and evolutionary parameters
-
getPopulationSize
public long getPopulationSize()Gets the target population size for each generation.- Returns:
- the population size as configured for this evolutionary system
-
createOffsprings
Creates offspring from the given population through selection, crossover, and mutation.This method orchestrates the reproductive process by:
- Selecting parents from the population using the configured selection strategy
- Applying crossover operations to generate basic offspring
- Applying mutation operators to introduce genetic variation
- Parameters:
population
- the current population to select parents fromoffspringsNeeded
- the number of offspring to generate- Returns:
- a list of mutated offspring genotypes
- Throws:
NullPointerException
- if population is nullIllegalArgumentException
- if offspringsNeeded is not positive
-
evolve
Executes the complete evolutionary algorithm process until termination criteria are met.This is the main entry point for running evolution. The method manages the entire evolutionary cycle including:
- Initial population generation and evaluation
- Iterative evolution through selection, reproduction, and replacement
- Progress monitoring via evolution listeners
- Termination condition checking
The evolution process continues until the configured termination criteria (e.g., maximum generations, target fitness, convergence) are satisfied.
- Returns:
- an EvolutionResult containing the final population, fitness values, generation count, and configuration details
- See Also:
-
evaluateOnce
Evaluates a collection of genotypes once without running the full evolutionary process.This method provides a way to evaluate genotypes using the configured fitness evaluator without executing the complete evolutionary algorithm. It handles the pre/post evaluation lifecycle and notifies evolution listeners of the results.
Useful for:
- Testing fitness functions with specific genotypes
- Evaluating externally generated populations
- Batch evaluation scenarios
- Parameters:
generation
- the generation number for logging and listener notificationgenotypes
- the list of genotypes to evaluate- Returns:
- a list of fitness values corresponding to the input genotypes
- Throws:
IllegalArgumentException
- if generation is negative or genotypes is emptyNullPointerException
- if genotypes is null
-