Replacement¶
- evolib.operators.replacement.replace_generational(pop, offspring, max_age=0, fitness_maximization=False)[source]¶
Replace the population with offspring, preserving elites and optionally applying age-based filtering. Resulting population is sorted by fitness.
This function implements generational replacement with elitism and optional aging. The final population size will be at most pop.parent_pool_size.
- Parameters:
- Raises:
ValueError – On invalid configuration or population state.
- Return type:
None
- evolib.operators.replacement.replace_mu_comma_lambda(pop, offspring, fitness_maximization=False)[source]¶
(mu, lambda) replacement: ONLY offspring compete; keep best mu offspring, top num_elites parents are preserved. Parents do not compete and cannot survive solely due to elitism.
- Precondition:
Fitness of offspring has been evaluated.
Parents may have fitness values, but they are not considered here.
- evolib.operators.replacement.replace_mu_plus_lambda(pop, offspring, fitness_maximization=False)[source]¶
(μ + λ) replacement: parents and offspring compete together; keep best μ.
- Precondition:
Fitness of both parents and offspring has been evaluated (same environmental context).
- Effect:
No explicit ‘elitism’ branch needed; if a parent is truly elite, it simply ranks among the top μ and survives.
- evolib.operators.replacement.replace_random(pop, offspring)[source]¶
Replace random non-elite individuals in the population with new offspring.
Elites are preserved using pop.get_elites() and marked via is_elite = True.
- evolib.operators.replacement.replace_steady_state(pop, offspring, num_replace=0, fitness_maximization=False)[source]¶
Replace the worst individuals in the population with offspring, preserving elite individuals. Implements steady-state replacement.
- Parameters:
- Raises:
ValueError – If replacement configuration is invalid.
- Return type:
None
- evolib.operators.replacement.replace_truncation(pop, pool, fitness_maximization=False)[source]¶
Generic truncation replacement selecting the top μ individuals from a given pool. Pass a pool that already contains what should compete (e.g., parents+offspring for μ+λ, or offspring only for μ,λ).
- evolib.operators.replacement.replace_weighted_stochastic(pop, offspring, temperature=1.0, fitness_maximization=False)[source]¶
Replace individuals in the population using inverse-fitness-weighted softmax sampling, preserving elite individuals.
- Parameters:
- Raises:
ValueError – On invalid input or if not enough non-elites are available.
- Return type:
None