Class AddConnectionPolicyHandler<T extends Comparable<T>>
- Type Parameters:
T
- the fitness value type (typically Double)
- All Implemented Interfaces:
MutationPolicyHandler<T>
AddConnectionPolicyHandler manages the structural mutation that adds new connections between existing nodes in NEAT neural networks. This is one of the fundamental structural mutations that enables NEAT to explore different network topologies by increasing connectivity complexity.
Add-connection mutation process:
- Node selection: Choose source and target nodes for the new connection
- Validity checking: Ensure connection doesn't already exist and doesn't create cycles
- Innovation assignment: Assign unique innovation number to the new connection
- Weight initialization: Set initial weight for the new connection
- Connection creation: Add enabled connection to the chromosome
Key characteristics:
- Structural evolution: Increases network connectivity without adding nodes
- Innovation tracking: New connections receive unique innovation numbers
- Topology exploration: Enables discovery of useful connection patterns
- Gradual complexity: Incrementally increases network complexity
Integration with NEAT algorithm:
- Innovation management: Coordinates with InnovationManager for tracking
- Chromosome mutation: Delegates to NeatChromosomeAddConnection handler
- Population evolution: Applied based on configured mutation probability
- Genetic diversity: Maintains structural diversity in the population
Common usage patterns:
// Create add-connection mutation policy
AddConnection addConnectionPolicy = AddConnection.of(0.1); // 10% mutation rate
// Create policy handler
RandomGenerator randomGen = RandomGenerator.getDefault();
AddConnectionPolicyHandler<Double> handler = new AddConnectionPolicyHandler<>(randomGen);
// Check if handler can process the policy
boolean canHandle = handler.canHandle(resolver, addConnectionPolicy);
// Create mutator for the policy
Mutator mutator = handler.createMutator(
executionContext, configuration, resolver, addConnectionPolicy
);
// Apply mutation to population
List<Individual<Double>> mutatedPopulation = mutator.mutate(
configuration, population
);
Mutation policy configuration:
- Population probability: Fraction of population to apply mutation to
- Individual probability: Probability of mutating each selected individual
- Connection constraints: Rules governing valid connection additions
- Weight initialization: Strategy for setting initial connection weights
Structural constraints:
- Duplicate prevention: Avoids creating connections that already exist
- Cycle detection: Prevents creation of cycles in feed-forward networks
- Node validity: Ensures source and target nodes exist in the network
- Self-connection handling: May prevent or allow self-connections based on policy
Performance considerations:
- Innovation caching: Leverages InnovationManager for efficient number assignment
- Connection checking: Efficient algorithms for duplicate and cycle detection
- Memory efficiency: Minimal allocation during mutation operations
- Concurrent safety: Thread-safe for parallel mutation application
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAddConnectionPolicyHandler
(RandomGenerator _randomGenerator) Constructs a new add-connection policy handler with the specified random generator. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canHandle
(MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, MutationPolicy mutationPolicy) Determines whether this handler can process the given mutation policy.createMutator
(AbstractEAExecutionContext<T> eaExecutionContext, AbstractEAConfiguration<T> eaConfiguration, MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, MutationPolicy mutationPolicy) Creates a concrete mutator for add-connection mutations.
-
Field Details
-
randomGenerator
-
-
Constructor Details
-
AddConnectionPolicyHandler
Constructs a new add-connection policy handler with the specified random generator.The random generator is used for stochastic decisions during mutation application, including selection of individuals to mutate and choices within the mutation process.
- Parameters:
_randomGenerator
- random number generator for stochastic mutation operations- Throws:
IllegalArgumentException
- if randomGenerator is null
-
-
Method Details
-
canHandle
public boolean canHandle(MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, MutationPolicy mutationPolicy) Determines whether this handler can process the given mutation policy.This handler specifically processes AddConnection mutation policies, which configure the parameters for adding new connections to NEAT neural networks.
- Specified by:
canHandle
in interfaceMutationPolicyHandler<T extends Comparable<T>>
- Parameters:
mutationPolicyHandlerResolver
- resolver for nested mutation policiesmutationPolicy
- the mutation policy to check- Returns:
- true if the policy is an AddConnection instance, false otherwise
- Throws:
IllegalArgumentException
- if any parameter is null
-
createMutator
public Mutator createMutator(AbstractEAExecutionContext<T> eaExecutionContext, AbstractEAConfiguration<T> eaConfiguration, MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, MutationPolicy mutationPolicy) Creates a concrete mutator for add-connection mutations.This method resolves the appropriate chromosome mutation handlers for NEAT chromosomes and creates a generic mutator that applies add-connection mutations according to the specified policy parameters.
Mutator creation process:
- Extract population mutation probability from the policy
- Resolve chromosome-specific mutation handlers
- Create generic mutator with resolved components
- Return configured mutator ready for population application
- Specified by:
createMutator
in interfaceMutationPolicyHandler<T extends Comparable<T>>
- Parameters:
eaExecutionContext
- execution context containing NEAT-specific componentseaConfiguration
- evolutionary algorithm configurationmutationPolicyHandlerResolver
- resolver for chromosome mutation handlersmutationPolicy
- the add-connection mutation policy- Returns:
- a configured mutator for applying add-connection mutations
- Throws:
IllegalArgumentException
- if any parameter is null
-