metaheuristic_designer.survivor_selection.survivor_selection_functions module#

generational(population_fitness, offspring_fitness, rng)[source]#

Full generational replacement: the entire next generation is formed exclusively by the offspring. No parent survives.

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population. Only its size is used.

offspring_fitnessVectorLike

Fitness values of the offspring population.

rngRNGLike

Random state (unused; kept for interface consistency).

Returns:
survivorsVectorLike

Indices of the selected individuals. Offspring indices are offset by len(population_fitness) so that the caller can distinguish them.

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

one_to_one(population_fitness, offspring_fitness, rng)[source]#

One-to-one competition: each offspring replaces its parent if it has a better (higher) fitness. Parent and offspring populations must have the same size.

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population.

offspring_fitnessVectorLike

Fitness values of the offspring, one per parent.

rngRNGLike

Random state (unused; kept for interface consistency).

Returns:
survivorsVectorLike

Indices of the selected individuals. Indices < n_parents point to parents; indices >= n_parents point to offspring.

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

prob_one_to_one(population_fitness, offspring_fitness, rng, p)[source]#

Probabilistic one-to-one competition. An offspring replaces its parent if it has a better fitness, OR with probability p regardless of fitness. Populations must be the same size.

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population.

offspring_fitnessVectorLike

Fitness values of the offspring, one per parent.

rngRNGLike

Seeded random state for the stochastic replacement decision.

pfloat

Probability of replacing a parent even if the offspring is worse.

Returns:
survivorsVectorLike

Indices of the selected individuals (parent indices offset when replaced).

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

  • p (float)

many_to_one(population_fitness, offspring_fitness, rng)[source]#

Many-to-one competition. Each parent competes against its own block of n_repetitions offspring (offspring size must be a multiple of parent size). The best individual among {parent, offspring_1, …, offspring_k} survives.

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population.

offspring_fitnessVectorLike

Fitness of all offspring, grouped in contiguous blocks of equal size (one block per parent).

rngRNGLike

Random state (unused; kept for interface consistency).

Returns:
survivorsVectorLike

Indices of the selected individuals, with offspring indices shifted by n_parents for each repetition appropriately.

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

prob_many_to_one(population_fitness, offspring_fitness, rng, p)[source]#

Probabilistic many-to-one competition. Like many_to_one, but with probability p the winner is replaced by a uniformly random competitor from the pool (parent + its offspring).

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population.

offspring_fitnessVectorLike

Fitness of all offspring, grouped in contiguous blocks per parent.

rngRNGLike

Seeded random state.

pfloat

Probability of ignoring the fitness-based winner and picking a random individual from the block.

Returns:
survivorsVectorLike

Indices of the selected individuals.

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

  • p (float)

elitism(population_fitness, offspring_fitness, rng, amount)[source]#

Standard elitism. The top amount parents (highest fitness) survive; the remaining slots are filled by the best offspring.

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population.

offspring_fitnessVectorLike

Fitness values of the offspring population.

rngRNGLike

Random state (unused; kept for interface consistency).

amountint

How many of the best parents are unconditionally preserved.

Returns:
survivorsVectorLike

Indices of the selected individuals. Parent indices appear as-is; offspring indices are shifted by the number of parents.

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

  • amount (int)

cond_elitism(population_fitness, offspring_fitness, rng, amount)[source]#

Conditional (fitness-based) elitism. A parent among the top amount is kept only if its fitness is strictly higher than the best offspring. Otherwise the elite slot is given to an offspring.

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness of the previous population.

offspring_fitnessVectorLike

Fitness of the new offspring.

rngRNGLike

Random state (unused; kept for interface consistency).

amountint

Maximum number of elite candidates considered.

Returns:
survivorsVectorLike

Indices of the selected individuals (parent indices not shifted, offspring indices shifted by n_parents).

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

  • amount (int)

keep_best(population_fitness, offspring_fitness, rng)[source]#

Combined selection: the best n_parents individuals from the union of parents and offspring survive. Indices are absolute positions in the concatenated array [parents, offspring].

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population.

offspring_fitnessVectorLike

Fitness values of the offspring population.

rngRNGLike

Random state (unused; kept for interface consistency).

Returns:
survivorsVectorLike

Indices into the concatenated fitness array (0..n_parents-1 for parents, n_parents.. for offspring).

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

keep_best_offspring(population_fitness, offspring_fitness, rng)[source]#

Offspring-only selection: the best n_parents offspring survive. Parents are completely discarded.

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population (only its length is used).

offspring_fitnessVectorLike

Fitness values of the offspring population.

rngRNGLike

Random state (unused; kept for interface consistency).

Returns:
survivorsVectorLike

Indices of the selected offspring, shifted by n_parents so that they are distinguishable from parent indices.

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

random_replacement(population_fitness, offspring_fitness, rng, p=0.5)[source]#

Randomly replaces the parents with some of the individuals.

Return type:

ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool]

Parameters:
population_fitnessVectorLike

Fitness values of the parent population (only its length is used).

offspring_fitnessVectorLike

Fitness values of the offspring population.

rngRNGLike

Random state (unused; kept for interface consistency).

Returns:
survivorsVectorLike

Indices of the selected offspring, shifted by n_parents so that they are distinguishable from parent indices.

Parameters:
  • population_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • offspring_fitness (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool])

  • rng (int | Generator)

  • p (float)