|
OptiPy
|
Abstract base class for Differential Evolution mutation strategies. More...
#include <Mutation.h>
Public Member Functions | |
| virtual | ~Mutation ()=default |
| Virtual destructor for safe polymorphic deletion. | |
| virtual std::vector< double > | mutate (const std::vector< std::vector< double > > &population, size_t targetIndex, double F, const std::vector< double > &bestVector, MersenneTwister &mt, double lowerBound, double upperBound)=0 |
| Generates a mutant vector using the mutation strategy. | |
Protected Member Functions | |
Shared Utilities | |
| std::vector< size_t > | getSubset (size_t populationSize, size_t subsetSize, size_t source, MersenneTwister &mt) |
| Selects a random subset of population indices, excluding a source index. | |
Abstract base class for Differential Evolution mutation strategies.
Mutation defines the interface and shared utilities for all DE mutation operators. Each concrete mutation strategy (Rand1, Best1, Rand2, Best2, RandBest1) implements the mutate() method to generate a mutant vector from a population based on a selected mutation formula.
Mutation Role in DE:
In Differential Evolution, mutation is the primary source of variation:
Mutation Formula Notation:
Standard DE mutation formulas follow the pattern: DE/base/N, where:
Common formulas:
Scaling Factor F:
The differential weight F (typically in range 0.0 to 2.0) controls the amplitude of variation. Key considerations:
Individual Selection:
The getSubset() helper selects random distinct individuals from the population (excluding the target individual). This ensures the mutant is derived from different genetic material than the target.
|
inlineprotected |
Selects a random subset of population indices, excluding a source index.
This is a shared utility used by all mutation strategies to randomly select distinct individuals from the population. The selection uses a partial Fisher-Yates shuffle for efficiency and guarantees no duplicates.
Algorithm:
Complexity:
Time: O(populationSize + subsetSize) for setup and shuffle Space: O(populationSize) for temporary index vector
Parameters:
| [in] | populationSize | Total number of individuals in the population. Range: subsetSize + 1 to infinity. |
| [in] | subsetSize | Number of distinct indices to select. Range: [1, populationSize - 1]. Must be less than populationSize (to exclude source). |
| [in] | source | Index to exclude from the selection. This individual is not included in the returned subset. Range: [0, populationSize - 1]. |
| [in,out] | mt | Mersenne Twister random number generator. Passed by reference; state is modified. Used to generate random swap positions. |
Return Value:
Guarantees:
Usage in Mutation Strategies:
Mutation formulas require 2-5 distinct random individuals:
Example:
Preconditions:
Implementation Note:
The partial Fisher-Yates algorithm is used instead of full shuffle or repeated sampling for O(populationSize + subsetSize) complexity without the risk of duplicate rejection sampling.
|
pure virtual |
Generates a mutant vector using the mutation strategy.
Pure virtual method that each concrete mutation strategy implements to produce a mutant vector. The mutant combines selected population individuals according to the strategy's formula.
Algorithm Pattern:
All mutation strategies follow this general workflow:
Parameters:
| [in] | population | The complete population of candidate solutions. Each element is a vector of dimension equal to the optimization problem. Size: popSize × dimension. |
| [in] | targetIndex | Index of the target individual in the population. This individual is excluded from random selection (cannot use its own genetic material for mutation). Range: [0, popSize-1]. |
| [in] | F | Differential weight (mutation scaling factor). Controls the amplitude of variation in the mutation formula. Typical range: (0, 2], common values: 0.5-1.0.
|
| [in] | bestVector | The best (lowest fitness) individual found so far. Used in "best" strategies (Best1, Best2, RandBest1). For "rand" strategies, may be ignored. Dimension: same as population elements. |
| [in,out] | mt | Mersenne Twister random number generator. Used to randomly select individuals and generate variations. Passed by reference; state is modified during execution. |
| [in] | lowerBound | Lower bound of the feasible domain. All dimensions share this uniform bound. Used to clamp mutant values to valid range. |
| [in] | upperBound | Upper bound of the feasible domain. All dimensions share this uniform bound. Used to clamp mutant values to valid range. |
Return Value:
Postconditions:
The returned mutant vector satisfies:
Strategy-Specific Behavior:
Different concrete strategies implement different formulas:
Complexity:
Time: O(dimension) - linear in the problem dimension Space: O(dimension) - for the returned mutant vector
Usage Example: