Strategy¶
strategy.py – Core evolution loop strategies for evolutionary algorithms.
This module provides predefined evolution strategies such as (μ + λ) and (μ, λ) in a modular form. Each function encapsulates one full generation cycle: - offspring creation - mutation - fitness evaluation - replacement - statistics update
These functions assume that Pop has: - a configured mutation strategy - a registered fitness function via set_functions()
Functions: - evolve_mu_plus_lambda: Classical (μ + λ) strategy with elitism. - evolve_mu_comma_lambda: Classical (μ, λ) strategy without elitism.
All strategies are compatible with strategy_registry and pop.run_one_generation().
- evolib.operators.strategy.evolve_flexible(pop)[source]¶
Modular evolution step using externally configured operators: - selection - crossover (optional) - mutation - replacement
Assumes that Pop has: - a configured selection_fn - a valid fitness_function - a pre-built _replacement_fn (e.g., from ReplacementStrategy)
- Return type:
None
- evolib.operators.strategy.evolve_mu_comma_lambda(pop)[source]¶
Only offspring compete for survival; parents are replaced.
If num_elites > 0, top elite parents are preserved and their fitness is re- evaluated before offspring generation.
- Return type:
None
- evolib.operators.strategy.evolve_mu_plus_lambda(pop)[source]¶
Elites and selected parents generate offspring, then mu best individuals are selected from parents + offspring.
- Return type:
None
- evolib.operators.strategy.evolve_steady_state(pop)[source]¶
Steady-State Evolution Strategy.
In each generation, only a subset of individuals is replaced with offspring, while the rest of the population (including elites) is retained.
Workflow: - Select parents - Generate offspring via cloning and crossover (if enabled) - Mutate offspring based on the current mutation strategy - Evaluate fitness of offspring - Replace the worst individuals (excluding elites) with offspring
Notes: - The number of replaced individuals per generation is defined by pop.lambda_ - Elites (top pop.num_elites individuals) are preserved - All individuals age automatically via pop.update_statistics()
- Raises:
ValueError – If population is uninitialized or fitness function is missing
- Return type:
None