:py:mod:`desdeo_emo.EAs.BaseEA`
===============================

.. py:module:: desdeo_emo.EAs.BaseEA


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   desdeo_emo.EAs.BaseEA.BaseEA
   desdeo_emo.EAs.BaseEA.BaseDecompositionEA




.. py:exception:: eaError

   Bases: :py:obj:`Exception`

   Raised when an error related to EA occurs


.. py:class:: BaseEA(a_priori: bool = False, interact: bool = False, selection_operator: Type[desdeo_emo.selection.SelectionBase.SelectionBase] = None, n_iterations: int = 10, n_gen_per_iter: int = 100, total_function_evaluations: int = 0, use_surrogates: bool = False, keep_archive: bool = False, save_non_dominated: bool = False)

   This class provides the basic structure for Evolutionary algorithms.

   .. py:method:: allowable_interaction_types() -> dict
      :property:


   .. py:method:: start()

      Mimics the structure of the mcdm methods. Returns the request objects from self.retuests().


   .. py:method:: end()

      To be run at the end of the evolution process.


   .. py:method:: _next_gen()

      Run one generation of an EA. Change nothing about the parameters.


   .. py:method:: iterate(preference=None) -> Tuple

      Run one iteration of EA.

      One iteration consists of a constant or variable number of
      generations. This method leaves EA.params unchanged, except the current
      iteration count and gen count.


   .. py:method:: pre_iteration()

      Run this code before every iteration.


   .. py:method:: post_iteration()

      Run this code after every iteration.


   .. py:method:: continue_iteration()

      Checks whether the current iteration should be continued or not.


   .. py:method:: continue_evolution() -> bool

      Checks whether the current iteration should be continued or not.


   .. py:method:: check_FE_count() -> bool

      Checks whether termination criteria via function evaluation count has been
          met or not.

      :returns: True is function evaluation count limit NOT met.
      :rtype: bool


   .. py:method:: set_interaction_type(interaction_type: Union[None, str]) -> Union[None, str]


   .. py:method:: manage_preferences(preference=None)

      Forward the preference to the correct preference handling method.

      :param preference: _description_. Defaults to None.
      :type preference: _type_, optional

      :raises eaError: Preference handling not implemented.


   .. py:method:: requests() -> Tuple


   .. py:method:: non_dominated_archive(individuals: numpy.ndarray, results: desdeo_problem.EvaluationResults) -> None



.. py:class:: BaseDecompositionEA(problem: desdeo_problem.MOProblem = None, initial_population: desdeo_emo.population.Population.Population = None, population_size: int = None, population_params: Dict = None, lattice_resolution: int = None, interact: bool = False, n_iterations: int = 10, n_gen_per_iter: int = 100, use_surrogates: bool = False, total_function_evaluations: int = 0, keep_archive: bool = False, save_non_dominated: bool = False)

   Bases: :py:obj:`BaseEA`

   The Base class for decomposition based EAs.

   This class contains most of the code to set up the parameters and operators.
   It also contains the logic of a simple decomposition EA.

   :param problem: The problem class object specifying the details of the problem.
   :type problem: MOProblem
   :param selection_operator: The selection operator to be used by the EA, by default None.
   :type selection_operator: Type[SelectionBase], optional
   :param population_size: The desired population size, by default None, which sets up a default value
                           of population size depending upon the dimensionaly of the problem.
   :type population_size: int, optional
   :param population_params: The parameters for the population class, by default None. See
                             desdeo_emo.population.Population for more details.
   :type population_params: Dict, optional
   :param initial_population: An initial population class, by default None. Use this if you want to set up
                              a specific starting population, such as when the output of one EA is to be
                              used as the input of another.
   :type initial_population: Population, optional
   :param lattice_resolution: The number of divisions along individual axes in the objective space to be
                              used while creating the reference vector lattice by the simplex lattice
                              design. By default None
   :type lattice_resolution: int, optional
   :param a_priori: A bool variable defining whether a priori preference is to be used or not.
                    By default False
   :type a_priori: bool, optional
   :param interact: A bool variable defining whether interactive preference is to be used or
                    not. By default False
   :type interact: bool, optional
   :param n_iterations: The total number of iterations to be run, by default 10. This is not a hard
                        limit and is only used for an internal counter.
   :type n_iterations: int, optional
   :param n_gen_per_iter: The total number of generations in an iteration to be run, by default 100.
                          This is not a hard limit and is only used for an internal counter.
   :type n_gen_per_iter: int, optional
   :param total_function_evaluations: Set an upper limit to the total number of function evaluations. When set to
                                      zero, this argument is ignored and other termination criteria are used.
   :type total_function_evaluations: int, optional

   .. py:method:: _next_gen()

      Run one generation of decomposition based EA. Intended to be used by
      next_iteration.


   .. py:method:: pre_iteration()

      Run this code before every iteration.


   .. py:method:: _select() -> list

      Describe a selection mechanism. Return indices of selected
      individuals.

      :returns: List of indices of individuals to be selected.
      :rtype: list


   .. py:method:: request_plot() -> desdeo_tools.interaction.SimplePlotRequest


   .. py:method:: request_preferences() -> Type[desdeo_tools.interaction.request.BaseRequest]


   .. py:method:: requests() -> Tuple


   .. py:method:: end()

      Conducts non-dominated sorting at the end of the evolution process

      :returns:

                The first element is a 2-D array of the decision vectors of the non-dominated solutions.
                    The second element is a 2-D array of the corresponding objective values.
      :rtype: tuple



