:py:mod:`desdeo_emo.selection`
==============================

.. py:module:: desdeo_emo.selection

.. autoapi-nested-parse::

   This module provides implementations of various selection operators.



Submodules
----------
.. toctree::
   :titlesonly:
   :maxdepth: 1

   APD_Select/index.rst
   APD_Select_constraints/index.rst
   IOPIS_APD/index.rst
   IOPIS_NSGAIII/index.rst
   MOEAD_select/index.rst
   NSGAIII_select/index.rst
   SelectionBase/index.rst
   TournamentSelection/index.rst
   oAPD/index.rst
   robust_APD/index.rst


Package Contents
----------------

Classes
~~~~~~~

.. autoapisummary::

   desdeo_emo.selection.APD_Select
   desdeo_emo.selection.NSGAIII_select
   desdeo_emo.selection.TournamentSelection
   desdeo_emo.selection.MOEAD_select




.. py:class:: APD_Select(pop: desdeo_emo.population.Population.Population, time_penalty_function: Callable, alpha: float = 2, selection_type: str = None)

   Bases: :py:obj:`desdeo_emo.selection.SelectionBase.InteractiveDecompositionSelectionBase`

   The selection operator for the RVEA algorithm. Read the following paper for more
   details.
   R. Cheng, Y. Jin, M. Olhofer and B. Sendhoff, A Reference Vector Guided
   Evolutionary Algorithm for Many-objective Optimization, IEEE Transactions on
   Evolutionary Computation, 2016

   :param pop: The population instance
   :type pop: Population
   :param time_penalty_function: A function that returns the time component in the penalty function.
   :type time_penalty_function: Callable
   :param alpha: The RVEA alpha parameter, by default 2
   :type alpha: float, optional

   .. py:method:: do(pop: desdeo_emo.population.Population.Population) -> List[int]

      Select individuals for mating on basis of Angle penalized distance.

      :param pop: The current population.
      :type pop: Population

      :returns: List of indices of the selected individuals
      :rtype: List[int]


   .. py:method:: _partial_penalty_factor() -> float

      Calculate and return the partial penalty factor for APD calculation.
          This calculation does not include the angle related terms, hence the name.
          If the calculated penalty is outside [0, 1], it will round it up/down to 0/1

      :returns: The partial penalty value
      :rtype: float



.. py:class:: NSGAIII_select(pop: desdeo_emo.population.Population.Population, n_survive: int = None, selection_type: str = None)

   Bases: :py:obj:`desdeo_emo.selection.SelectionBase.InteractiveDecompositionSelectionBase`

   The NSGA-III selection operator. Code is heavily based on the version of nsga3 in
       the pymoo package by msu-coinlab.

   :param pop: [description]
   :type pop: Population
   :param n_survive: [description], by default None
   :type n_survive: int, optional

   .. py:method:: do(pop: desdeo_emo.population.Population.Population) -> List[int]

      Select individuals for mating for NSGA-III.

      :param pop: The current population.
      :type pop: Population

      :returns: List of indices of the selected individuals
      :rtype: List[int]


   .. py:method:: get_extreme_points_c(F, ideal_point, extreme_points=None)

      Taken from pymoo


   .. py:method:: get_nadir_point(extreme_points, ideal_point, worst_point, worst_of_front, worst_of_population)


   .. py:method:: niching(F, n_remaining, niche_count, niche_of_individuals, dist_to_niche)


   .. py:method:: associate_to_niches(F, ref_dirs, ideal_point, nadir_point, utopian_epsilon=0.0)


   .. py:method:: calc_niche_count(n_niches, niche_of_individuals)


   .. py:method:: calc_perpendicular_distance(N, ref_dirs)


   .. py:method:: _calculate_fitness(pop) -> numpy.ndarray



.. py:class:: TournamentSelection(pop, tournament_size)

   Bases: :py:obj:`desdeo_emo.selection.SelectionBase.SelectionBase`

   Tournament selection operator.

   :param pop: The population of individuals
   :type pop: Population
   :param tournament_size: Size of the tournament.
   :type tournament_size: int

   .. py:method:: do(pop, fitness) -> List[int]

      Performs tournament selections and returns the parents.
      :param pop: The current population.
      :type pop: Population

      :returns: List of indices of the selected individuals
      :rtype: List[int]


   .. py:method:: _tour_select()

      Tournament selection. Choose number of individuals to participate
      and select the one with the best fitness.

      :param fitness: An array of each individual's fitness.
      :type fitness: array_like
      :param tournament_size: Number of participants in the tournament.
      :type tournament_size: int

      :returns: The index of the best individual.
      :rtype: int



.. py:class:: MOEAD_select(pop: desdeo_emo.population.Population.Population, SF_type: desdeo_tools.scalarization.MOEADSF.MOEADSFBase, n_neighbors: int, selection_type: str = None)

   Bases: :py:obj:`desdeo_emo.selection.SelectionBase.InteractiveDecompositionSelectionBase`

   The MOEAD selection operator.

   :param pop: The population of individuals
   :type pop: Population
   :param SF_type: The scalarizing function employed to evaluate the solutions
   :type SF_type: MOEADSFBase

   .. py:method:: do(pop: desdeo_emo.population.Population.Population, current_neighborhood: int) -> List[int]

      Select the individuals that are kept in the neighborhood.

      :param pop: The current population.
      :type pop: Population
      :param vectors: Class instance containing reference vectors.
      :type vectors: ReferenceVectors
      :param ideal_point: Ideal vector found so far
      :param current_neighborhood: Neighborhood to be updated
      :param offspring_fx: Offspring solution to be compared with the rest of the neighborhood

      :returns: List of indices of the selected individuals
      :rtype: List[int]


   .. py:method:: _evaluate_SF(neighborhood, weights, ideal_point)


   .. py:method:: choose_parents(current_neighborhood: int, n_parents: int) -> List[int]


   .. py:method:: adapt_RVs(fitness: numpy.ndarray) -> None



