metaheuristic_designer.operator module#
Base class for the Operator module.
This module implements procedures to modify the current solutions so that we explore the search space.
- class Operator(name=None, encoding=None, preserves_order=False, rng=None, **kwargs)[source]#
Bases:
ParametrizableMixin,ABCAbstract base for all perturbation operators.
An
Operatormodifies a population (typically by applying mutation, crossover, or a composite of several steps). Subclasses must implementevolve().- Parameters:
- namestr, optional
Display name for this operator.
- encodingEncoding, optional
Post-processing applied to the genotype matrix after the operator runs. Defaults to
DefaultEncoding.- preserves_orderbool, optional
If
True, the operator keeps individuals in the same order (useful for one-to-one survivor selection). DefaultFalse.- rngRNGLike, optional
Random number generator.
- **kwargs
Additional keyword arguments stored as schedulable parameters.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
name (Optional[str])
encoding (Optional[Encoding])
preserves_order (bool)
rng (Optional[RNGLike])
Methods
__call__(population)Shorthand for
evolve().evolve(population)Evolves an population using a given strategy.
Return the current parameter dictionary (thin wrapper around
get_params()).get_params()Return a copy of the current parameter dictionary.
Gets the current state of the algorithm as a dictionary.
store_kwargs([progress])Store keyword arguments and evaluate them at the given progress.
update([progress])Updates the internal parameters.
update_kwargs([progress])Add or replace parameters and immediately evaluate them.
- gather_params()[source]#
Return the current parameter dictionary (thin wrapper around
get_params()).
- abstract evolve(population)[source]#
Evolves an population using a given strategy.
- Return type:
- Parameters:
- population: Population
The population that will be used.
- Returns:
- new_population: Population
The modified population.
- Parameters:
population (Population)
- class NullOperator(name=None)[source]#
Bases:
OperatorOperator class that returns the individual without changes. Surprisingly useful.
Since it’s a no-op, it has the preserves_order flag set to True.
- Parameters:
- name: str, optional
Name that is associated with the operator.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
name (Optional[str])
Methods
__call__(population)Shorthand for
evolve().evolve(population)Evolves an population using a given strategy.
gather_params()Return the current parameter dictionary (thin wrapper around
get_params()).get_params()Return a copy of the current parameter dictionary.
get_state()Gets the current state of the algorithm as a dictionary.
store_kwargs([progress])Store keyword arguments and evaluate them at the given progress.
update([progress])Updates the internal parameters.
update_kwargs([progress])Add or replace parameters and immediately evaluate them.
- evolve(population)[source]#
Evolves an population using a given strategy.
- Return type:
- Parameters:
- population: Population
The population that will be used.
- Returns:
- new_population: Population
The modified population.
- Parameters:
population (Population)
- class OperatorFromLambda(operator_fn, name=None, encoding=None, preserves_order=False, rng=None, **kwargs)[source]#
Bases:
OperatorOperator that wraps a user‑supplied function.
The function receives a
Population, anInitializer, a random state, and any stored keyword arguments, and must return a modifiedPopulation.- Parameters:
- operator_fncallable
A function
(population, initializer, rng, **kwargs) -> Population.- namestr, optional
Display name (defaults to the function’s
__name__).- encodingEncoding, optional
See
Operator.- preserves_orderbool, optional
See
Operator.- rngRNGLike, optional
See
Operator.- **kwargs
Keyword arguments forwarded to
Operatorand also passed to operator_fn on each call.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
operator_fn (Callable)
name (Optional[str])
encoding (Optional[Encoding])
preserves_order (bool)
rng (Optional[RNGLike])
Methods
__call__(population)Shorthand for
evolve().evolve(population)Evolves an population using a given strategy.
gather_params()Return the current parameter dictionary (thin wrapper around
get_params()).get_params()Return a copy of the current parameter dictionary.
get_state()Gets the current state of the algorithm as a dictionary.
store_kwargs([progress])Store keyword arguments and evaluate them at the given progress.
update([progress])Updates the internal parameters.
update_kwargs([progress])Add or replace parameters and immediately evaluate them.
- evolve(population)[source]#
Evolves an population using a given strategy.
- Return type:
- Parameters:
- population: Population
The population that will be used.
- Returns:
- new_population: Population
The modified population.
- Parameters:
population (Population)