metaheuristic_designer.survivor_selection_base module#

Base class for the Survivor Selection module.

class SurvivorSelection(name=None, preserves_order=False, rng=None, **kwargs)[source]#

Bases: ParametrizableMixin, ABC

Abstract base for all survivor selection methods.

A survivor selection decides which individuals from the current population and the newly generated offspring will form the next generation. Subclasses must implement select().

Parameters:
namestr, optional

Display name for this selection method.

preserves_orderbool, optional

If True, the order of individuals is kept (useful for one-to-one competition schemes). Default False.

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])

  • preserves_order (bool)

  • rng (Optional[RNGLike])

Methods

__call__(population, offspring)

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, offspring)

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()).

abstract select(population, offspring)[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

Population containing only the selected survivors.

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 NullSurvivorSelection(name='Nothing', **kwargs)[source]#

Bases: SurvivorSelection

Null survivor selection, offspring replace parents entirely.

This is the identity element for generational replacement: all parents are discarded and all offspring survive. The population size must be maintained by the offspring.

Parameters:
namestr, optional

Display name. Default "Nothing".

**kwargs

Keyword arguments forwarded to SurvivorSelection.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:

name (Optional[str])

Methods

__call__(population, offspring)

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, offspring)

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, offspring)[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

Population containing only the selected survivors.

Parameters:
class SurvivorSelectionFromLambda(selection_fn, name=None, preserves_order=False, rng=None, **kwargs)[source]#

Bases: SurvivorSelection

Survivor selection that wraps a user-supplied function.

The function receives the parent population, the offspring population, a random state, and any stored keyword arguments, and must return an array of indices into the concatenated pool.

Parameters:
selection_fncallable

A function (parents, offspring, rng, **kwargs) -> indices.

namestr, optional

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

preserves_orderbool, optional

See SurvivorSelection.

rngRNGLike, optional

Random number generator.

**kwargs

Keyword arguments forwarded to SurvivorSelection.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:
  • selection_fn (Callable)

  • name (Optional[str])

  • preserves_order (bool)

  • rng (Optional[RNGLike])

Methods

__call__(population, offspring)

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, offspring)

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, offspring)[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

Population containing only the selected survivors.

Parameters: