Class GenotypeGenerator<T extends Comparable<T>>
- Type Parameters:
T
- the type of fitness values in the evolutionary algorithm
GenotypeGenerator provides the infrastructure for creating random initial populations based on chromosome specifications defined in the EA configuration. It supports both automatic generation using chromosome factories and custom generation through user-provided suppliers, enabling flexible population initialization strategies.
The generator operates in two modes:
- Automatic generation: Uses registered chromosome factories to create random individuals
- Custom generation: Uses a user-provided supplier for specialized initialization
Key responsibilities include:
- Population initialization: Creating diverse initial populations for algorithm startup
- Factory coordination: Managing chromosome factories for different chromosome types
- Configuration compliance: Ensuring generated genotypes match EA configuration specifications
- Logging and monitoring: Providing visibility into population generation process
Automatic generation workflow:
- Resolve appropriate chromosome factories for each chromosome specification
- Generate random chromosomes using the resolved factories
- Assemble chromosomes into complete genotypes
- Repeat until the required population size is reached
Common usage patterns:
// Standard automatic generation
ChromosomeFactoryProvider factoryProvider = new ChromosomeFactoryProvider();
EAConfiguration<Double> config = createConfiguration();
GenotypeGenerator<Double> generator = new GenotypeGenerator<>(factoryProvider, config);
List<Genotype> initialPopulation = generator.generateGenotypes(100);
// With custom generation logic
EAConfiguration<Double> configWithCustomGen = EAConfigurationBuilder.<Double>builder()
.chromosomeSpecs(chromosomeSpec)
.genotypeGenerator(() -> createSpecializedGenotype())
.build();
GenotypeGenerator<Double> customGenerator = new GenotypeGenerator<>(factoryProvider, configWithCustomGen);
List<Genotype> customPopulation = customGenerator.generateGenotypes(50);
Performance considerations:
- Factory reuse: Resolves chromosome factories once per generation session
- Memory efficiency: Generates individuals on-demand without intermediate storage
- Logging overhead: Uses efficient logging for population generation tracking
- Validation: Performs minimal validation to maintain generation performance
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ChromosomeFactoryProvider
private final AbstractEAConfiguration
<T> static final org.apache.logging.log4j.Logger
-
Constructor Summary
ConstructorsConstructorDescriptionGenotypeGenerator
(ChromosomeFactoryProvider _chromosomeFactoryProvider, AbstractEAConfiguration<T> _eaConfiguration) Constructs a new genotype generator with the specified factory provider and EA configuration. -
Method Summary
Modifier and TypeMethodDescriptiongenerateGenotypes
(int numPopulation) Generates a specified number of random genotypes for initial population creation.
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger logger -
chromosomeFactoryProvider
-
eaConfiguration
-
populationGenerator
-
-
Constructor Details
-
GenotypeGenerator
public GenotypeGenerator(ChromosomeFactoryProvider _chromosomeFactoryProvider, AbstractEAConfiguration<T> _eaConfiguration) Constructs a new genotype generator with the specified factory provider and EA configuration.The generator will use the provided chromosome factory provider to resolve appropriate factories for each chromosome type specified in the configuration. If the configuration includes a custom genotype generator, it will be used instead of automatic generation.
- Parameters:
_chromosomeFactoryProvider
- the provider for chromosome factories_eaConfiguration
- the EA configuration containing chromosome specifications- Throws:
NullPointerException
- if any parameter is null
-
-
Method Details
-
generateGenotypes
Generates a specified number of random genotypes for initial population creation.This method creates a diverse initial population by either using a custom genotype generator (if specified in the configuration) or by automatically generating individuals using chromosome factories. Each generated genotype conforms to the chromosome specifications defined in the EA configuration.
Generation process:
- Check if custom genotype generator is available
- If custom generator exists, use it to create all individuals
- Otherwise, resolve chromosome factories and generate chromosomes automatically
- Assemble chromosomes into complete genotypes
- Parameters:
numPopulation
- the number of genotypes to generate (must be positive)- Returns:
- a list of randomly generated genotypes ready for evolution
- Throws:
IllegalArgumentException
- if numPopulation is not positiveRuntimeException
- if chromosome factory resolution or generation fails
-