Selection

class jmetal.operator.selection.BestSolutionSelection[source]

Bases: Selection[List[S], S]

execute(front: List[S]) S[source]
get_name() str[source]
class jmetal.operator.selection.BinaryTournament2Selection(comparator_list: List[Comparator])[source]

Bases: Selection[List[S], S]

Performs binary tournament selection with multiple comparators.

This selection operator uses a list of comparators in sequence to determine the winner between two randomly selected solutions. The first comparator that can determine a winner is used. If all comparators result in a tie, a random solution is chosen.

Args:

comparator_list: List of comparators to use in sequence.

execute(front: List[S]) S[source]

Execute the binary tournament selection with multiple comparators.

Args:

front: List of solutions to select from.

Returns:

The selected solution.

Raises:

ValueError: If front is None, empty, or contains only one solution.

get_name() str[source]
class jmetal.operator.selection.BinaryTournamentSelection(comparator: ~jmetal.util.comparator.Comparator = <jmetal.util.comparator.DominanceComparator object>)[source]

Bases: Selection[List[S], S]

Performs binary tournament selection between two random solutions.

This selection operator randomly selects two solutions from the population and returns the better one according to the provided comparator. If the comparator returns 0 (tie), a random solution is chosen.

Args:

comparator: Comparator used to compare solutions (default: DominanceComparator)

execute(front: List[S]) S[source]

Execute the binary tournament selection.

Args:

front: List of solutions to select from.

Returns:

The selected solution.

Raises:

ValueError: If front is None or empty.

get_name() str[source]
class jmetal.operator.selection.DifferentialEvolutionSelection(index_to_exclude: int = None)[source]

Bases: Selection[List[S], List[S]]

Performs selection for differential evolution algorithms.

This selection operator is specifically designed for differential evolution algorithms. It selects three distinct solutions from the population, with an optional index to exclude (typically the current solution’s index to avoid self-selection).

Args:
index_to_exclude: Optional index of a solution to exclude from selection.

This is useful to avoid selecting the same solution as the base vector.

execute(front: List[S]) List[S][source]

Select three distinct solutions for differential evolution.

Args:

front: List of solutions to select from.

Returns:

A list containing three distinct solutions from the front.

Raises:

ValueError: If front is None, empty, or has fewer than 4 solutions.

get_name() str[source]

Get the name of the selection operator.

Returns:

A string representing the name of the selection operator.

set_index_to_exclude(index: int) None[source]

Set the index of the solution to exclude from selection.

Args:

index: Index of the solution to exclude. Can be None to disable exclusion.

class jmetal.operator.selection.NaryRandomSolutionSelection(number_of_solutions_to_be_returned: int = 1)[source]

Bases: Selection[List[S], S]

Performs random selection of multiple solutions from a population.

This selection operator randomly selects a specified number of distinct solutions from the population with uniform probability. The selection is done without replacement, meaning each solution can be selected at most once.

Args:
number_of_solutions_to_be_returned: Number of distinct solutions to select (default: 1).

Must be a positive integer.

execute(front: List[S]) List[S][source]

Randomly select multiple solutions from the front.

Args:

front: List of solutions to select from.

Returns:

A list of randomly selected solutions from the front.

Raises:

ValueError: If front is None, empty, or has fewer solutions than requested.

get_name() str[source]

Get the name of the selection operator.

Returns:

A string representing the name of the selection operator.

class jmetal.operator.selection.RandomSelection[source]

Bases: Selection[List[S], S]

Performs random selection of a solution from a population.

This selection operator randomly selects a single solution from the provided population with uniform probability. It’s a simple selection method that doesn’t consider solution quality.

execute(front: List[S]) S[source]

Randomly select a solution from the front.

Args:

front: List of solutions to select from.

Returns:

A randomly selected solution from the front.

Raises:

ValueError: If front is None or empty.

get_name() str[source]
class jmetal.operator.selection.RankingAndCrowdingDistanceSelection(max_population_size: int, dominance_comparator: ~jmetal.util.comparator.Comparator = <jmetal.util.comparator.DominanceComparator object>)[source]

Bases: Selection[List[S], List[S]]

Performs selection based on non-dominated ranking and crowding distance.

This selection operator first ranks the solutions using non-dominated sorting and then applies crowding distance to maintain diversity within each rank. It’s commonly used in NSGA-II and other multi-objective evolutionary algorithms.

Args:

max_population_size: Maximum number of solutions to select. dominance_comparator: Comparator used for non-dominated sorting.

Defaults to DominanceComparator().

execute(front: List[S]) List[S][source]

Select solutions using non-dominated ranking and crowding distance.

Args:

front: List of solutions to select from.

Returns:

A list of selected solutions, with size up to max_population_size.

Raises:

ValueError: If front is None, empty, or max_population_size is invalid.

get_name() str[source]

Get the name of the selection operator.

Returns:

A string representing the name of the selection operator.

class jmetal.operator.selection.RankingAndFitnessSelection(max_population_size: int, reference_point: ~jmetal.operator.selection.S, dominance_comparator: ~jmetal.util.comparator.Comparator = <jmetal.util.comparator.DominanceComparator object>)[source]

Bases: Selection[List[S], List[S]]

Performs selection based on non-dominated ranking and hypervolume contribution.

This selection operator first ranks the solutions using non-dominated sorting and then applies hypervolume contribution to maintain diversity within each rank. It’s commonly used in multi-objective evolutionary algorithms that aim to maximize the hypervolume indicator.

Args:

max_population_size: Maximum number of solutions to select. reference_point: Reference point used for hypervolume calculation.

Should be dominated by all solutions.

dominance_comparator: Comparator used for non-dominated sorting.

Defaults to DominanceComparator().

compute_hypervol_fitness_values(population: List[S], reference_point: S, k: int) List[S][source]

Compute hypervolume-based fitness values for a population.

This method computes the hypervolume contribution of each solution in the population and stores it in the solution’s attributes as ‘fitness’.

Args:

population: List of solutions to evaluate. reference_point: Reference point for hypervolume calculation. k: Number of points to consider for hypervolume approximation.

If negative, uses the entire population size.

Returns:

The input population with updated fitness values in their attributes.

execute(front: List[S]) List[S][source]

Select solutions using non-dominated ranking and hypervolume contribution.

This method first performs non-dominated sorting of the input front. It then fills the new population with solutions from the best ranks, using hypervolume contribution to select solutions when a rank needs to be split.

Args:

front: List of solutions to select from.

Returns:

A list of selected solutions, with size equal to max_population_size.

Raises:

ValueError: If front is None or empty.

get_name() str[source]

Get the name of the selection operator.

Returns:

A string representing the name of the selection operator.

hypesub(l: int, A: List[List[float]], actDim: int, bounds: List[float], pvec: List[int], alpha: List[float], k: int) List[float][source]

Recursively compute hypervolume contributions.

This is a helper method for hypervolume calculation. It’s an implementation of the Hype algorithm for hypervolume approximation.

Args:

l: Number of points. A: List of objective vectors. actDim: Current dimension being processed. bounds: Reference point coordinates. pvec: Indices of points in A. alpha: Weighting factors for hypervolume contribution. k: Number of points to consider.

Returns:

List of hypervolume contributions for each point.

class jmetal.operator.selection.RouletteWheelSelection(objective_index: int = 0)[source]

Bases: Selection[List[S], S]

Performs roulette wheel selection.

This selection operator selects solutions based on their fitness values using a roulette wheel mechanism. It can handle both single and multi-objective optimization by using the first objective value for selection. For multi-objective optimization, consider using a proper fitness assignment strategy first.

Note: This implementation assumes all objective values are non-negative. If negative values are present, a proper normalization should be applied first.

execute(front: List[S]) S[source]

Select a solution using roulette wheel selection.

Args:

front: List of solutions to select from.

Returns:

The selected solution.

Raises:

ValueError: If the front is None, empty, or contains invalid fitness values.

get_name() str[source]
class jmetal.operator.selection.S

alias of TypeVar(‘S’, bound=Solution)