metaheuristic_designer.parent_selection_base module#

Base class for the Parent Selection module.

class ParentSelection(name=None, amount=None, rng=None, **kwargs)[source]#

Bases: ParametrizableMixin, ABC

Abstract base for all parent selection methods.

A parent selection chooses which individuals from the current population will be used to generate offspring. Subclasses must implement select(), which returns a new Population containing only the selected individuals.

Parameters:
namestr, optional

Display name for this selection method.

amountint, optional

Default number of individuals to select. Can be overridden at call time.

rngRNGLike, optional

Random number generator.

**kwargs

Additional keyword arguments stored as schedulable parameters.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:
  • name (Optional[str])

  • amount (Optional[int])

  • rng (Optional[RNGLike])

Methods

__call__(population[, amount])

Shorthand for select().

gather_params()

Return the current parameter dictionary (thin wrapper around get_params()).

get_params()

Return a copy of the current parameter dictionary.

get_state()

Return a dictionary with the selection method's configuration.

select(population[, amount])

Takes a population with its offspring and returns the individuals that survive to produce the next generation.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Re-evaluate all stored parameters at the current progress.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

gather_params()[source]#

Return the current parameter dictionary (thin wrapper around get_params()).

Return type:

dict

abstract select(population, amount=None)[source]#

Takes a population with its offspring and returns the individuals that survive to produce the next generation.

Return type:

Population

Parameters:
population: Population

Population of individuals that will be selected.

offspring: Population

Newly generated individuals to be selected.

Returns:
selected: Population

List of selected individuals.

Parameters:
get_state()[source]#

Return a dictionary with the selection method’s configuration.

Return type:

dict

Returns:
dict

Keys include class_name, name, and all current parameters.

class NullParentSelection(name='Nothing', **kwargs)[source]#

Bases: ParentSelection

Null parent selection, returns the whole population unchanged.

This is the identity element: no individuals are filtered out. Useful when the algorithm does not require a parent selection step (e.g., random search or certain evolution strategies).

Parameters:
namestr, optional

Display name. Default "Nothing".

**kwargs

Keyword arguments forwarded to ParentSelection.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:

name (Optional[str])

Methods

__call__(population[, amount])

Shorthand for select().

gather_params()

Return the current parameter dictionary (thin wrapper around get_params()).

get_params()

Return a copy of the current parameter dictionary.

get_state()

Return a dictionary with the selection method's configuration.

select(population[, amount])

Takes a population with its offspring and returns the individuals that survive to produce the next generation.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Re-evaluate all stored parameters at the current progress.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

select(population, amount=None)[source]#

Takes a population with its offspring and returns the individuals that survive to produce the next generation.

Return type:

Population

Parameters:
population: Population

Population of individuals that will be selected.

offspring: Population

Newly generated individuals to be selected.

Returns:
selected: Population

List of selected individuals.

Parameters:
class ParentSelectionFromLambda(selection_fn, name=None, amount=None, rng=None, **kwargs)[source]#

Bases: ParentSelection

Parent selection that wraps a user-supplied function.

The function receives the population, the number of individuals to select, a random state, and any stored keyword arguments, and must return an array of selected indices.

Parameters:
selection_fncallable

A function (population, amount, rng, **kwargs) -> indices.

namestr, optional

Display name (defaults to the function’s __name__).

amountint, optional

Default number of individuals to select.

rngRNGLike, optional

Random number generator.

**kwargs

Keyword arguments forwarded to ParentSelection.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:
  • selection_fn (Callable)

  • name (Optional[str])

  • amount (Optional[int])

  • rng (Optional[RNGLike])

Methods

__call__(population[, amount])

Shorthand for select().

gather_params()

Return the current parameter dictionary (thin wrapper around get_params()).

get_params()

Return a copy of the current parameter dictionary.

get_state()

Return a dictionary with the selection method's configuration.

select(population[, amount])

Takes a population with its offspring and returns the individuals that survive to produce the next generation.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Re-evaluate all stored parameters at the current progress.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

select(population, amount=None)[source]#

Takes a population with its offspring and returns the individuals that survive to produce the next generation.

Return type:

Population

Parameters:
population: Population

Population of individuals that will be selected.

offspring: Population

Newly generated individuals to be selected.

Returns:
selected: Population

List of selected individuals.

Parameters: