:py:mod:`desdeo_emo.population`
===============================

.. py:module:: desdeo_emo.population

.. autoapi-nested-parse::

   This module provides classes and methods which implement populations in an EA.



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

   CreateIndividuals/index.rst
   Population/index.rst
   Population_old/index.rst
   SurrogatePopulation/index.rst


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

Classes
~~~~~~~

.. autoapisummary::

   desdeo_emo.population.Population
   desdeo_emo.population.SurrogatePopulation



Functions
~~~~~~~~~

.. autoapisummary::

   desdeo_emo.population.create_new_individuals



.. py:function:: create_new_individuals(design, problem, pop_size=None)

   Create new individuals to the population.

   The individuals can be created randomly, by LHS design, or can be passed by the
   user.

   Design does not apply in case of EvoNN and EvoDN2 problem, where neural networks
   are created as individuals.

   :param design: Describe the method of creation of new individuals.
                  "RandomDesign" creates individuals randomly.
                  "LHSDesign" creates individuals using Latin hypercube sampling.
                  "EvoNN" creates Artificial Neural Networks as individuals.
                  "EvoDN2" creates Deep Neural Networks.
   :type design: str, optional
   :param problem: An object of the class Problem
   :type problem: baseProblem
   :param pop_size: Number of individuals in the population. If none, some default population
                    size based on number of objectives is chosen.
   :type pop_size: int, optional

   :returns: **individuals** -- A list of individuals.
   :rtype: list


.. py:class:: Population(problem: desdeo_problem.MOProblem, pop_size: int, pop_params: Dict = None, use_surrogates: bool = False)

   Bases: :py:obj:`BasePopulation`

   Helper class that provides a standard way to create an ABC using
   inheritance.

   .. py:method:: add(offsprings: Union[List, numpy.ndarray], use_surrogates: bool = False)

      Evaluate and add offspring to the population.

      :param offsprings: List or array of individuals to be evaluated and added to the population.
      :type offsprings: Union[List, np.ndarray]
      :param use_surrogates: If true, use surrogate models rather than true function evaluations.
      :type use_surrogates: bool
      :param use_surrogates: If true, use surrogate models rather than true function evaluations.
      :type use_surrogates: bool

      :returns: Results of evaluation.
      :rtype: Results


   .. py:method:: keep(indices: List)

      Save the population members given by the list of indices for the next
          generation. Delete the rest.

      :param indices:
                      List of indices of the population members to be kept for the next
                          generation.
      :type indices: List


   .. py:method:: delete(indices: List)

      Delete the population members given by the list of indices for the next
          generation. Keep the rest.

      :param indices: List of indices of the population members to be deleted.
      :type indices: List


   .. py:method:: mate(mating_individuals: List = None) -> Union[List, numpy.ndarray]

      Perform crossover and mutation over the population members.

      :param mating_individuals:
                                 List of individuals taking part in recombination. By default None, which
                                     recombinated all individuals in random order.
      :type mating_individuals: List, optional
      :param params: Parameters for the mutation or crossover operator, by default None.
      :type params: Dict, optional

      :returns: The offspring population
      :rtype: Union[List, np.ndarray]


   .. py:method:: update_ideal()


   .. py:method:: replace(indices: List, individual: numpy.ndarray, evaluation: tuple)

      Replace the population members given by the list of indices by the given individual and its evaluation.
         Keep the rest of the population unchanged.

      :param indices: List of indices of the population members to be replaced.
      :type indices: List
      :param individual: Decision variables of the individual that will replace the positions given in the list.
      :type individual: np.ndarray
      :param evaluation: Result of the evaluation of the objective function, constraints, etc. obtained using the evaluate method.
      :type evaluation: tuple


   .. py:method:: repair(individual)

      Repair the variables of an individual which are not in the boundary defined by the problem
      :param individual: Decision variables of the individual.

      :rtype: The new decision vector with the variables in the boundary defined by the problem


   .. py:method:: reevaluate_fitness()


   .. py:method:: non_dominated_fitness()


   .. py:method:: non_dominated_objectives()



.. py:class:: SurrogatePopulation(problem, pop_size: int, initial_pop, xover, mutation, recombination)

   Bases: :py:obj:`desdeo_emo.population.Population.Population`, :py:obj:`desdeo_emo.population.Population.BasePopulation`

   Helper class that provides a standard way to create an ABC using
   inheritance.


