Crossover¶
Collection of crossover operators for evolutionary algorithms.
Includes implementations of arithmetic, blend (BLX-Alpha), simulated binary (SBX), intermediate, heuristic, and differential crossover. Designed for use with real-valued vectors and adaptable to various evolutionary strategies.
- evolib.operators.crossover.crossover_arithmetic(parent1_para, parent2_para, num_children=2)[source]¶
Perform arithmetic crossover between two parent vectors.
Each child’s genes are a weighted average of the corresponding genes of the parents, using a randomly chosen mixing coefficient alpha ∈ [0, 1].
- Parameters:
parent1_para (
ndarray) – Parameter vector of the first parent.parent2_para (
ndarray) – Parameter vector of the second parent.num_children (
int) – Number of children to return (1 or 2). Default is 2.
- Returns:
One or two offspring vectors.
- Return type:
Union[ndarray,Tuple[ndarray,ndarray]]- Raises:
ValueError – If parent vectors have different lengths or num_children is invalid.
- evolib.operators.crossover.crossover_blend_alpha(parent1_para, parent2_para, alpha=0.5, num_children=2)[source]¶
Perform Blend-Alpha Crossover (BLX-Alpha) on two parent vectors.
This operator creates one or two offspring by sampling each gene from an extended interval around the parent genes.
- Parameters:
parent1_para (
ndarray) – Parameter vector of the first parent.parent2_para (
ndarray) – Parameter vector of the second parent.alpha (
float) – Expansion factor for the sampling interval. Default is 0.5.num_children (
int) – Number of children to generate (1 or 2). Default is 2.
- Returns:
One or two offspring vectors.
- Return type:
Union[ndarray,Tuple[ndarray,ndarray]]- Raises:
ValueError – If parent vectors have different lengths or num_children
is invalid. –
- evolib.operators.crossover.crossover_intermediate(parent1, parent2, blend_range=0.25)[source]¶
Perform intermediate crossover with extended alpha range on two parent vectors.
Each offspring gene is calculated using a random alpha ∈ [-d, 1 + d], creating solutions inside and outside the segment between parents.
- Parameters:
parent1 (
ndarray) – First parent vector.parent2 (
ndarray) – Second parent vector.d (float) – Extension factor for sampling interval beyond [0, 1].
0.25. (Default is)
- Returns:
Two offspring vectors.
- Return type:
Tuple[ndarray,ndarray]- Raises:
ValueError – If parent vectors have different lengths.
- evolib.operators.crossover.crossover_offspring(pop, offspring)[source]¶
Perform crossover for each pair of offspring individuals.
Delegates the actual crossover logic to the individuals’ parameter representations (ParaBase subclasses). Works for both single-module (e.g. Vector, EvoNet) and multi-module (ParaComposite) individuals.
- Return type:
None
Notes
Offspring are assumed to be copied before this call.
Individuals are paired (0,1), (2,3), …
This method does not return; offspring are modified in place.
- evolib.operators.crossover.crossover_simulated_binary(parent1, parent2, eta=20)[source]¶
Perform Simulated Binary Crossover (SBX) on two parent vectors.
SBX creates offspring that simulate the effect of single-point binary crossover in real-valued search spaces, controlled by a distribution index η.
- Parameters:
parent1 (
ndarray) – First parent vector.parent2 (
ndarray) – Second parent vector.eta (
float) – Distribution index (controls spread; higher = closer to parents).
- Returns:
Two offspring vectors.
- Return type:
Tuple[ndarray,ndarray]- Raises:
ValueError – If parent vectors have different lengths.