Class NeatSelectionPolicyHandler<T extends Number & Comparable<T>>
- Type Parameters:
T
- the fitness value type (typically Double)
- All Implemented Interfaces:
SelectionPolicyHandler<T>
NeatSelectionPolicyHandler implements the species-based selection mechanism that is fundamental to the NEAT algorithm. It organizes the population into species based on genetic compatibility, applies fitness sharing within species, and manages reproduction allocation across species to maintain population diversity and protect innovative topologies.
Key responsibilities:
- Species formation: Groups genetically similar individuals into species
- Fitness sharing: Adjusts individual fitness based on species membership
- Reproduction allocation: Distributes offspring across species based on average fitness
- Diversity preservation: Protects innovative topologies from elimination by established forms
NEAT species-based selection process:
- Compatibility calculation: Measure genetic distance between individuals
- Species assignment: Assign individuals to species based on compatibility thresholds
- Fitness adjustment: Apply fitness sharing within each species
- Species evaluation: Calculate average fitness for each species
- Reproduction allocation: Determine offspring count for each species
- Within-species selection: Select parents within each species for reproduction
Species management features:
- Dynamic speciation: Species boundaries adjust as population evolves
- Species extinction: Poor-performing species are eliminated
- Representative tracking: Maintains species representatives for compatibility testing
- Population diversity: Prevents single topology from dominating
Common usage patterns:
// Create NEAT selection policy handler
RandomGenerator randomGen = RandomGenerator.getDefault();
SpeciesIdGenerator speciesIdGen = new SpeciesIdGenerator();
NeatSelectionPolicyHandler<Double> handler = new NeatSelectionPolicyHandler<>(
randomGen, speciesIdGen
);
// Configure NEAT selection policy
NeatSelection<Double> neatSelection = NeatSelection.<Double>builder()
.compatibilityThreshold(3.0)
.speciesSelection(new TournamentSelection(3)) // Within-species selection
.build();
// Resolve selector for EA execution
Selector<Double> selector = handler.resolve(
executionContext, configuration, resolverRegistry, neatSelection
);
Integration with genetic operators:
- Crossover compatibility: Species ensure genetic compatibility for meaningful recombination
- Mutation guidance: Species composition influences structural mutation rates
- Innovation protection: New topologies get time to optimize within their species
- Diversity maintenance: Multiple species explore different regions of topology space
Performance considerations:
- Compatibility caching: Genetic distances cached for efficiency
- Species reuse: Species structures maintained across generations
- Parallel processing: Species-based selection enables concurrent evaluation
- Memory management: Efficient species membership tracking
Selection policy delegation:
- Within-species selection: Delegates to standard selection policies (tournament, roulette, etc.)
- Composable policies: Can combine with any standard selection mechanism
- Flexible configuration: Different species can use different selection strategies
- Performance optimization: Leverages existing high-performance selectors
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.logging.log4j.Logger
private final RandomGenerator
private final SpeciesIdGenerator
-
Constructor Summary
ConstructorsConstructorDescriptionNeatSelectionPolicyHandler
(RandomGenerator _randomGenerator, SpeciesIdGenerator _speciesIdGenerator) Constructs a new NEAT selection policy handler with the specified components. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canHandle
(SelectionPolicy selectionPolicy) Determines whether this handler can process the given selection policy.resolve
(AbstractEAExecutionContext<T> eaExecutionContext, AbstractEAConfiguration<T> eaConfiguration, SelectionPolicyHandlerResolver<T> selectionPolicyHandlerResolver, SelectionPolicy selectionPolicy) Resolves a NEAT selection policy into a concrete selector implementation.
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger logger -
randomGenerator
-
speciesIdGenerator
-
-
Constructor Details
-
NeatSelectionPolicyHandler
public NeatSelectionPolicyHandler(RandomGenerator _randomGenerator, SpeciesIdGenerator _speciesIdGenerator) Constructs a new NEAT selection policy handler with the specified components.The random generator is used for stochastic operations during species formation and selection. The species ID generator provides unique identifiers for newly created species throughout the evolutionary process.
- Parameters:
_randomGenerator
- random number generator for stochastic operations_speciesIdGenerator
- generator for unique species identifiers- Throws:
IllegalArgumentException
- if randomGenerator or speciesIdGenerator is null
-
-
Method Details
-
canHandle
Determines whether this handler can process the given selection policy.This handler specifically processes NeatSelection policies, which configure species-based selection with compatibility thresholds and within-species selection strategies.
- Specified by:
canHandle
in interfaceSelectionPolicyHandler<T extends Number & Comparable<T>>
- Parameters:
selectionPolicy
- the selection policy to check- Returns:
- true if the policy is a NeatSelection instance, false otherwise
- Throws:
IllegalArgumentException
- if selectionPolicy is null
-
resolve
public Selector<T> resolve(AbstractEAExecutionContext<T> eaExecutionContext, AbstractEAConfiguration<T> eaConfiguration, SelectionPolicyHandlerResolver<T> selectionPolicyHandlerResolver, SelectionPolicy selectionPolicy) Resolves a NEAT selection policy into a concrete selector implementation.This method creates a NeatSelectorImpl that implements the species-based selection mechanism. It resolves the within-species selection policy using the provided resolver and configures the selector with the necessary NEAT components.
Resolution process:
- Extract the within-species selection policy from the NEAT selection configuration
- Resolve the within-species selection policy to a concrete selector
- Create a NeatSelectorImpl with all necessary components
- Return the configured selector ready for use in evolution
- Specified by:
resolve
in interfaceSelectionPolicyHandler<T extends Number & Comparable<T>>
- Parameters:
eaExecutionContext
- the execution context for the evolutionary algorithmeaConfiguration
- the configuration for the evolutionary algorithmselectionPolicyHandlerResolver
- resolver for nested selection policiesselectionPolicy
- the NEAT selection policy to resolve- Returns:
- a configured selector implementing NEAT species-based selection
- Throws:
IllegalArgumentException
- if selectionPolicy is null or not a NeatSelection
-