Class NeatCombinationHandler<T extends Comparable<T>>
- Type Parameters:
T
- the fitness value type (typically Double)
- All Implemented Interfaces:
ChromosomeCombinatorHandler<T>
NeatCombinationHandler manages the genetic recombination process for NEAT neural networks, implementing innovation-number-based gene alignment and parent comparison strategies. This handler resolves NEAT-specific combination policies into concrete chromosome combinators that understand neural network topology and can perform meaningful genetic crossover between different network structures.
Key responsibilities:
- Policy resolution: Converts NeatCombination policies into executable combinators
- Parent comparison: Manages strategies for determining genetic inheritance patterns
- Innovation alignment: Ensures proper gene alignment using innovation numbers
- Topology crossover: Handles recombination of different network topologies
NEAT genetic crossover features:
- Innovation-based alignment: Genes matched by innovation number for meaningful recombination
- Matching genes: Genes with same innovation number can be inherited from either parent
- Disjoint genes: Genes unique to one parent in middle innovation number ranges
- Excess genes: Genes beyond the highest innovation number of less fit parent
Parent comparison strategies:
- Fitness-based inheritance: More fit parent contributes disjoint and excess genes
- Equal fitness handling: Special rules when parents have equal fitness
- Random inheritance: Stochastic gene inheritance for matching genes
- Topology preservation: Ensures offspring have valid network topologies
Common usage patterns:
// Create NEAT combination handler
RandomGenerator randomGen = RandomGenerator.getDefault();
NeatCombinationHandler<Double> handler = new NeatCombinationHandler<>(randomGen);
// Check if handler can process combination policy
NeatCombination policy = NeatCombination.builder()
.parentComparisonPolicy(new FitnessComparison())
.build();
NeatChromosomeSpec spec = NeatChromosomeSpec.of(3, 2, -1.0f, 1.0f);
boolean canHandle = handler.canHandle(resolver, policy, spec);
// Resolve to concrete combinator
ChromosomeCombinator<Double> combinator = handler.resolve(resolver, policy, spec);
Integration with genetic algorithm framework:
- Handler registration: Registered in EA execution context for automatic resolution
- Policy-driven configuration: Behavior controlled by NeatCombination specifications
- Resolver integration: Works with chromosome combinator resolver system
- Type safety: Ensures compatibility between policies and chromosome specifications
Parent comparison handler management:
- Handler locator: Uses ParentComparisonHandlerLocator for strategy resolution
- Strategy flexibility: Supports different parent comparison approaches
- Extensibility: New comparison strategies can be easily added
- Policy validation: Ensures configured strategies are available
Performance considerations:
- Handler caching: Parent comparison handlers cached for reuse
- Innovation sorting: Leverages pre-sorted connection lists for efficiency
- Memory efficiency: Minimal memory allocation during crossover
- Parallel processing: Thread-safe operations for concurrent crossover
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ParentComparisonHandlerLocator
private final RandomGenerator
-
Constructor Summary
ConstructorsConstructorDescriptionNeatCombinationHandler
(RandomGenerator _randomGenerator) Constructs a new NEAT combination handler with the specified random generator. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canHandle
(ChromosomeCombinatorResolver<T> chromosomeCombinatorResolver, CombinationPolicy combinationPolicy, ChromosomeSpec chromosome) Determines whether this handler can process the given combination policy and chromosome specification.resolve
(ChromosomeCombinatorResolver<T> chromosomeCombinatorResolver, CombinationPolicy combinationPolicy, ChromosomeSpec chromosome) Resolves a NEAT combination policy into a concrete chromosome combinator.
-
Field Details
-
randomGenerator
-
parentComparisonHandlerLocator
-
-
Constructor Details
-
NeatCombinationHandler
Constructs a new NEAT combination handler with the specified random generator.The random generator is used for stochastic decisions during genetic crossover, such as choosing which parent contributes genes when multiple options are available. A parent comparison handler locator is automatically created to manage comparison strategies.
- Parameters:
_randomGenerator
- random number generator for stochastic crossover operations- Throws:
IllegalArgumentException
- if randomGenerator is null
-
-
Method Details
-
canHandle
public boolean canHandle(ChromosomeCombinatorResolver<T> chromosomeCombinatorResolver, CombinationPolicy combinationPolicy, ChromosomeSpec chromosome) Determines whether this handler can process the given combination policy and chromosome specification.This handler specifically processes NeatCombination policies applied to NeatChromosomeSpec specifications, ensuring type compatibility for NEAT neural network genetic crossover.
- Specified by:
canHandle
in interfaceChromosomeCombinatorHandler<T extends Comparable<T>>
- Parameters:
chromosomeCombinatorResolver
- resolver for nested combination policiescombinationPolicy
- the combination policy to checkchromosome
- the chromosome specification to check- Returns:
- true if policy is NeatCombination and chromosome is NeatChromosomeSpec, false otherwise
- Throws:
IllegalArgumentException
- if any parameter is null
-
resolve
public ChromosomeCombinator<T> resolve(ChromosomeCombinatorResolver<T> chromosomeCombinatorResolver, CombinationPolicy combinationPolicy, ChromosomeSpec chromosome) Resolves a NEAT combination policy into a concrete chromosome combinator.This method creates a NeatChromosomeCombinator configured with the appropriate parent comparison strategy. The parent comparison policy is resolved using the handler locator to determine how genetic inheritance should be managed during crossover.
Resolution process:
- Extract parent comparison policy from the NEAT combination configuration
- Locate appropriate parent comparison handler for the policy
- Create NeatChromosomeCombinator with resolved components
- Return configured combinator ready for genetic crossover
- Specified by:
resolve
in interfaceChromosomeCombinatorHandler<T extends Comparable<T>>
- Parameters:
chromosomeCombinatorResolver
- resolver for nested combination policiescombinationPolicy
- the NEAT combination policy to resolvechromosome
- the NEAT chromosome specification- Returns:
- a configured chromosome combinator for NEAT genetic crossover
- Throws:
IllegalArgumentException
- if any parameter is null or of wrong typeIllegalStateException
- if no parent comparison handler found for the policy
-