Selection

This module provides various parent selection strategies used in evolutionary algorithms.

Included methods: - Tournament Selection - Rank-Based Selection (linear and exponential) - Roulette Wheel Selection - Stochastic Universal Sampling (SUS) - Boltzmann (Softmax) Selection - Truncation Selection

All methods operate on a population of individuals with assigned fitness values and return copies of selected parents.

evolib.operators.selection.selection_boltzmann(pop, num_parents, temperature=1.0, fitness_maximization=False)[source]

Selects individuals using Boltzmann (Softmax) selection.

Parameters:
  • num_parents (int) – Number of individuals to select.

  • temperature (float) – Controls selection pressure (higher = more uniform).

  • fitness_maximization (bool) – If True, higher fitness is better.

Returns:

Selected individuals (copies).

Return type:

List[Any]

evolib.operators.selection.selection_random(pop, remove_selected=False)[source]

Performs random selection to select offspring from a population.

Parameter:

population: List of individuals, each with a fitness attribute. num_offspring: Number of offspring to select.

Return type:

List[Indiv]

Returns:

List of selected individuals (offspring).

evolib.operators.selection.selection_rank_based(pop, num_parents, *, mode='linear', remove_selected=False, exp_base=1.0, fitness_maximization=False)[source]

Performs rank-based selection using linear or exponential probability distribution.

Selection probabilities are based on fitness ranks: - Linear: p(i) = 2*(N-i)/(N*(N+1)), where i is the rank (0 = worst, N-1 = best). - Exponential: p(i) = base^i / sum(base^j), where base is a positive float.

Parameters:
  • num_parents (int) – Number of parents to select.

  • mode (str) – Selection mode: ‘linear’ or ‘exponential’. Default: ‘linear’.

  • remove_selected (bool) – If True, selected individuals are removed from future

  • Default (selection.) – False.

  • exp_base (float) – Base used in exponential probability calculation. Must be > 0.

  • fitness_maximization (bool) – If True, higher fitness is better.

  • Default – False (minimization).

Returns:

List of selected individuals (copies).

Return type:

List[Any]

Raises:
  • ValueError – If parameters are invalid (e.g., empty population,

  • invalid base or mode).

  • TypeError – If fitness values are invalid (None or NaN).

evolib.operators.selection.selection_roulette(pop, num_parents, fitness_maximization=False)[source]

Selects parents using fitness-proportional roulette wheel selection.

Parameters:
  • num_parents (int) – Number of individuals to select.

  • fitness_maximization (bool) – If True, higher fitness is better.

Returns:

List of selected individuals (copies).

Return type:

List[Any]

evolib.operators.selection.selection_sus(pop, num_parents, fitness_maximization=False)[source]

Selects individuals using Stochastic Universal Sampling (SUS).

Parameters:
  • num_parents (int) – Number of individuals to select.

  • fitness_maximization (bool) – If True, higher fitness is better.

Returns:

Selected individuals (copies).

Return type:

List[Any]

evolib.operators.selection.selection_tournament(pop, num_parents, tournament_size=3, remove_selected=False, fitness_maximization=False)[source]

Performs tournament selection to select parents from the population.

Parameters:
  • num_parents (int) – Number of parents to select.

  • tournament_size (int, optional) – Number of individuals in each tournament. Defaults to 3.

  • remove_selected (bool, optional) – If True, selected individuals are removed from future tournaments. Defaults to False.

  • minimize (bool, optional) – If True, select individuals with lowest fitness (minimization). If False, select highest fitness (maximization). Defaults to True.

Returns:

List of selected parents.

Return type:

list

Raises:

ValueError – If parameters are invalid (e.g., negative num_parents, invalid tournament_size, or empty population).

evolib.operators.selection.selection_truncation(pop, num_parents, fitness_maximization=False)[source]

Selects the top individuals (by fitness) deterministically.

Parameters:
  • num_parents (int) – Number of individuals to select.

  • fitness_maximization (bool) – If True, selects best fitness; else lowest.

Returns:

Selected individuals (copies).

Return type:

List[Any]