metaheuristic_designer.strategies.classic package

Submodules

metaheuristic_designer.strategies.classic.CMA_ES module

CMA-ES (Covariance Matrix Adaptation Evolution Strategy) implementation.

Warning

The current implementation is architecturally a temporary solution. It will be refactored once the EDA (Distribution-based) interface is finalised.

class CMA_ES(initializer: Initializer, survivor_sel: SurvivorSelection | None = None, name: str = 'CMA-ES', offspring_size: int | SchedulableParameter | None = None, random_state=None, mean: ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | None = None, sigma: ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | None = None, **kwargs)[source]

Bases: SearchStrategy

Covariance Matrix Adaptation Evolution Strategy (CMA-ES).

This is a population-based algorithm that samples new solutions from a multivariate normal distribution whose mean and covariance are adapted each generation based on the best individuals.

Note

The architecture of this class is provisional. It currently overrides initialize() and perturb() directly. Once the distribution-based (EDA) abstraction is in place, CMA-ES will be rewritten to use that common interface.

Parameters:
  • initializer (Initializer) – Provides population size and genotype shape, but does not generate the initial solutions.

  • survivor_sel (SurvivorSelection, optional) – How survivors are selected. Defaults to the strategy’s default (generational).

  • name (str, optional) – Display name (default "CMA-ES").

  • offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation. If None, the initializer’s population size is used.

  • random_state (RNGLike, optional) – Random number generator.

  • mean (VectorLike, optional) – Initial mean vector. If not given, it is computed from the objective’s bounds (or randomly if no bounds exist).

  • sigma (VectorLike, optional) – Initial step size. If not given, a default is computed.

  • **kwargs – Forwarded to VariablePopulation.

initialize(objfunc: ObjectiveFunc) Population[source]

Create the initial population by sampling from the current distribution.

Parameters:

objfunc (ObjectiveFunc) – The objective function, used to infer bounds if mean or sigma are not provided.

Returns:

A freshly sampled population with unevaluated fitness.

Return type:

Population

perturb(parents: Population, **kwargs) Population[source]

Update the distribution parameters and generate offspring.

The parents (the best μ individuals from the previous generation) are used to update mean, sigma, covariance, and the evolution paths. A new offspring population is then sampled from the updated distribution.

Parameters:
  • parents (Population) – The selected parents (must be already evaluated).

  • **kwargs – Forwarded to the parent’s perturb().

Returns:

Offspring population of size offspring_size.

Return type:

Population

metaheuristic_designer.strategies.classic.DE module

Differential Evolution strategy.

class DE(initializer: Initializer, de_operator_name: str = 'DE/best/1', survivor_sel: SurvivorSelection | None = None, name: str = 'DE', random_state: int | Generator | None = None, F: float | SchedulableParameter = 0.8, Cr: float | SchedulableParameter = 0.9, p: float | SchedulableParameter = 0.1, **kwargs)[source]

Bases: StaticPopulation

Differential Evolution algorithm.

Uses a DE mutation operator (e.g., "DE/best/1") and one-to-one survivor selection by default. The population size stays constant, and every individual is perturbed each generation.

Parameters:
  • initializer (Initializer) – Population initializer.

  • de_operator_name (str, optional) – DE variant (default "DE/best/1").

  • survivor_sel (SurvivorSelection, optional) – Survivor selection; defaults to one-to-one competition.

  • name (str, optional) – Display name (default "DE").

  • random_state (RNGLike, optional) – Random number generator.

  • F (float or SchedulableParameter, optional) – Scale factor (default 0.8).

  • Cr (float or SchedulableParameter, optional) – Crossover probability (default 0.9).

  • p (float or SchedulableParameter, optional) – Elite fraction for /pbest/ variants (default 0.1).

  • **kwargs – Forwarded to StaticPopulation.

metaheuristic_designer.strategies.classic.ES module

Evolution Strategy.

class ES(initializer: Initializer, mutation_op: Operator, crossover_op: Operator | None = None, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, offspring_size: int | None = None, name: str = 'ES', **kwargs)[source]

Bases: VariablePopulation

Evolution Strategy (μ+λ or μ,λ).

Applies mutation (and optionally crossover) to the selected parents, then selects survivors. By default, no parent selection is performed (all individuals are used).

Parameters:
  • initializer (Initializer) – Population initializer.

  • mutation_op (Operator) – Mutation operator.

  • crossover_op (Operator, optional) – Crossover operator. If None, only mutation is applied.

  • parent_sel (ParentSelection, optional) – Parent selection (default: use the whole population).

  • survivor_sel (SurvivorSelection, optional) – Survivor selection (default: generational).

  • offspring_size (int, optional) – Number of offspring per generation.

  • name (str, optional) – Display name (default "ES").

  • **kwargs – Forwarded to VariablePopulation.

metaheuristic_designer.strategies.classic.GA module

Genetic Algorithm strategy.

class GA(initializer: Initializer, mutation_op: Operator, crossover_op: Operator, parent_sel: ParentSelection, survivor_sel: SurvivorSelection, name: str = 'GA', mutation_prob: float | SchedulableParameter = 0.1, crossover_prob: float | SchedulableParameter = 0.9, random_state: int | Generator | None = None, **kwargs)[source]

Bases: StaticPopulation

Genetic Algorithm.

Combines crossover (applied with probability crossover_prob) and mutation (applied per individual with probability mutation_prob) via a BranchOperator. The population size is constant.

Parameters:
  • initializer (Initializer) – Population initializer.

  • mutation_op (Operator) – Mutation operator (will be applied probabilistically).

  • crossover_op (Operator) – Crossover operator (applied pairwise).

  • parent_sel (ParentSelection) – Parent selection method.

  • survivor_sel (SurvivorSelection) – Survivor selection method.

  • name (str, optional) – Display name (default "GA").

  • mutation_prob (float or SchedulableParameter, optional) – Individual-level probability of mutation (default 0.1).

  • crossover_prob (float or SchedulableParameter, optional) – Pair-level probability of crossover (default 0.9). If the crossover operator supports it, this value is injected via update_kwargs.

  • random_state (RNGLike, optional) – Random number generator.

  • **kwargs – Forwarded to StaticPopulation.

metaheuristic_designer.strategies.classic.SA module

Simulated Annealing strategy.

class SA(initializer: Initializer, operator: Operator, name: str = 'SA', iterations: int | SchedulableParameter = 100, temperature_init: float | SchedulableParameter = 100, alpha: float | SchedulableParameter = 0.99, random_state: int | Generator | None = None, **kwargs)[source]

Bases: HillClimb

Simulated Annealing algorithm.

A single solution is perturbed each iteration. The new solution is accepted if it is better, or probabilistically if it is worse, according to an exponentially decaying temperature schedule.

Warning

The current handling of the annealing schedule is tightly coupled to the strategy. The survivor selection should be refactored to manage its own temperature and acceptance logic independently.

Parameters:
  • initializer (Initializer) – Population initializer (usually creates a single individual).

  • operator (Operator) – Perturbation operator.

  • name (str, optional) – Display name (default "SA").

  • iterations (int or SchedulableParameter, optional) – Number of iterations at constant temperature (default 100).

  • temperature_init (float or SchedulableParameter, optional) – Starting temperature (default 100).

  • alpha (float or SchedulableParameter, optional) – Cooling factor (default 0.99).

  • random_state (RNGLike, optional) – Random number generator.

  • **kwargs – Forwarded to HillClimb.

step(progress)[source]

Update internal parameters and forward progress to sub-components.

Parameters:

progress (float) – Current progress of the algorithm (0-1).

extra_step_info()[source]

Diplays temperature values and acceptance probability.

Module contents

Classic population-based strategies (GA, DE, ES, CMA-ES, SA, RandomSearch).

class CMA_ES(initializer: Initializer, survivor_sel: SurvivorSelection | None = None, name: str = 'CMA-ES', offspring_size: int | SchedulableParameter | None = None, random_state=None, mean: ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | None = None, sigma: ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | None = None, **kwargs)[source]

Bases: SearchStrategy

Covariance Matrix Adaptation Evolution Strategy (CMA-ES).

This is a population-based algorithm that samples new solutions from a multivariate normal distribution whose mean and covariance are adapted each generation based on the best individuals.

Note

The architecture of this class is provisional. It currently overrides initialize() and perturb() directly. Once the distribution-based (EDA) abstraction is in place, CMA-ES will be rewritten to use that common interface.

Parameters:
  • initializer (Initializer) – Provides population size and genotype shape, but does not generate the initial solutions.

  • survivor_sel (SurvivorSelection, optional) – How survivors are selected. Defaults to the strategy’s default (generational).

  • name (str, optional) – Display name (default "CMA-ES").

  • offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation. If None, the initializer’s population size is used.

  • random_state (RNGLike, optional) – Random number generator.

  • mean (VectorLike, optional) – Initial mean vector. If not given, it is computed from the objective’s bounds (or randomly if no bounds exist).

  • sigma (VectorLike, optional) – Initial step size. If not given, a default is computed.

  • **kwargs – Forwarded to VariablePopulation.

initialize(objfunc: ObjectiveFunc) Population[source]

Create the initial population by sampling from the current distribution.

Parameters:

objfunc (ObjectiveFunc) – The objective function, used to infer bounds if mean or sigma are not provided.

Returns:

A freshly sampled population with unevaluated fitness.

Return type:

Population

perturb(parents: Population, **kwargs) Population[source]

Update the distribution parameters and generate offspring.

The parents (the best μ individuals from the previous generation) are used to update mean, sigma, covariance, and the evolution paths. A new offspring population is then sampled from the updated distribution.

Parameters:
  • parents (Population) – The selected parents (must be already evaluated).

  • **kwargs – Forwarded to the parent’s perturb().

Returns:

Offspring population of size offspring_size.

Return type:

Population

class DE(initializer: Initializer, de_operator_name: str = 'DE/best/1', survivor_sel: SurvivorSelection | None = None, name: str = 'DE', random_state: int | Generator | None = None, F: float | SchedulableParameter = 0.8, Cr: float | SchedulableParameter = 0.9, p: float | SchedulableParameter = 0.1, **kwargs)[source]

Bases: StaticPopulation

Differential Evolution algorithm.

Uses a DE mutation operator (e.g., "DE/best/1") and one-to-one survivor selection by default. The population size stays constant, and every individual is perturbed each generation.

Parameters:
  • initializer (Initializer) – Population initializer.

  • de_operator_name (str, optional) – DE variant (default "DE/best/1").

  • survivor_sel (SurvivorSelection, optional) – Survivor selection; defaults to one-to-one competition.

  • name (str, optional) – Display name (default "DE").

  • random_state (RNGLike, optional) – Random number generator.

  • F (float or SchedulableParameter, optional) – Scale factor (default 0.8).

  • Cr (float or SchedulableParameter, optional) – Crossover probability (default 0.9).

  • p (float or SchedulableParameter, optional) – Elite fraction for /pbest/ variants (default 0.1).

  • **kwargs – Forwarded to StaticPopulation.

class ES(initializer: Initializer, mutation_op: Operator, crossover_op: Operator | None = None, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, offspring_size: int | None = None, name: str = 'ES', **kwargs)[source]

Bases: VariablePopulation

Evolution Strategy (μ+λ or μ,λ).

Applies mutation (and optionally crossover) to the selected parents, then selects survivors. By default, no parent selection is performed (all individuals are used).

Parameters:
  • initializer (Initializer) – Population initializer.

  • mutation_op (Operator) – Mutation operator.

  • crossover_op (Operator, optional) – Crossover operator. If None, only mutation is applied.

  • parent_sel (ParentSelection, optional) – Parent selection (default: use the whole population).

  • survivor_sel (SurvivorSelection, optional) – Survivor selection (default: generational).

  • offspring_size (int, optional) – Number of offspring per generation.

  • name (str, optional) – Display name (default "ES").

  • **kwargs – Forwarded to VariablePopulation.

class GA(initializer: Initializer, mutation_op: Operator, crossover_op: Operator, parent_sel: ParentSelection, survivor_sel: SurvivorSelection, name: str = 'GA', mutation_prob: float | SchedulableParameter = 0.1, crossover_prob: float | SchedulableParameter = 0.9, random_state: int | Generator | None = None, **kwargs)[source]

Bases: StaticPopulation

Genetic Algorithm.

Combines crossover (applied with probability crossover_prob) and mutation (applied per individual with probability mutation_prob) via a BranchOperator. The population size is constant.

Parameters:
  • initializer (Initializer) – Population initializer.

  • mutation_op (Operator) – Mutation operator (will be applied probabilistically).

  • crossover_op (Operator) – Crossover operator (applied pairwise).

  • parent_sel (ParentSelection) – Parent selection method.

  • survivor_sel (SurvivorSelection) – Survivor selection method.

  • name (str, optional) – Display name (default "GA").

  • mutation_prob (float or SchedulableParameter, optional) – Individual-level probability of mutation (default 0.1).

  • crossover_prob (float or SchedulableParameter, optional) – Pair-level probability of crossover (default 0.9). If the crossover operator supports it, this value is injected via update_kwargs.

  • random_state (RNGLike, optional) – Random number generator.

  • **kwargs – Forwarded to StaticPopulation.

class RandomSearch(initializer, name='RandomSearch', **kwargs)[source]

Bases: HillClimb

Random search algorithm.

Each iteration replaces the current population with completely new random individuals (via a random.random operator). No perturbation of existing solutions occurs.

Parameters:
  • initializer (Initializer) – Population initializer.

  • name (str, optional) – Display name (default "RandomSearch").

  • **kwargs – Forwarded to HillClimb.

class SA(initializer: Initializer, operator: Operator, name: str = 'SA', iterations: int | SchedulableParameter = 100, temperature_init: float | SchedulableParameter = 100, alpha: float | SchedulableParameter = 0.99, random_state: int | Generator | None = None, **kwargs)[source]

Bases: HillClimb

Simulated Annealing algorithm.

A single solution is perturbed each iteration. The new solution is accepted if it is better, or probabilistically if it is worse, according to an exponentially decaying temperature schedule.

Warning

The current handling of the annealing schedule is tightly coupled to the strategy. The survivor selection should be refactored to manage its own temperature and acceptance logic independently.

Parameters:
  • initializer (Initializer) – Population initializer (usually creates a single individual).

  • operator (Operator) – Perturbation operator.

  • name (str, optional) – Display name (default "SA").

  • iterations (int or SchedulableParameter, optional) – Number of iterations at constant temperature (default 100).

  • temperature_init (float or SchedulableParameter, optional) – Starting temperature (default 100).

  • alpha (float or SchedulableParameter, optional) – Cooling factor (default 0.99).

  • random_state (RNGLike, optional) – Random number generator.

  • **kwargs – Forwarded to HillClimb.

step(progress)[source]

Update internal parameters and forward progress to sub-components.

Parameters:

progress (float) – Current progress of the algorithm (0-1).

extra_step_info()[source]

Diplays temperature values and acceptance probability.