Class Population

java.lang.Object
dealib.components.Population

public class Population extends Object
Population is a class representing the structure and functionalities of a Population in differential evolution.
Since:
1.0
Version:
1.0
Author:
Alicia Vazquez Ramos
  • Constructor Details

    • Population

      public Population(Execution exe)
      Default constructor.
      Parameters:
      exe - configuration of the current execution.
    • Population

      public Population(Execution exe, ArrayList<Individual> p)
      Constructor given a set of individuals.
      Parameters:
      exe - configuration of the current execution.
      p - population.
  • Method Details

    • getAllIndividuals

      public ArrayList<Individual> getAllIndividuals()
      Gets a list with all the individuals of the population.
      Returns:
      a list with all the individuals.
    • getAllOrderedIndividuals

      public ArrayList<Individual> getAllOrderedIndividuals()
      Gets a list with all the individuals of the population ordered by fitness.
      Returns:
      a list with all the individuals ordered by fitness.
    • getCurrentG

      public int getCurrentG()
      Gets current generation in the evolution of the population.
      Returns:
      the current generation.
    • getNextG

      public int getNextG()
      Gets the next generation in the evolution of the population.
      Returns:
      the next generation.
    • getNP

      public int getNP()
      Gets the number of individuals of the Population.
      Returns:
      current size of the Population.
    • getIndividual

      public Individual getIndividual(int index)
      Gets an Individual of the unordered population given an index.
      Parameters:
      index - the position of the required Individual in the unordered population.
      Returns:
      the Individual stored in the given position.
    • getIndexOfIndividual

      public int getIndexOfIndividual(Individual ind)
      Gets the index of a given Individual in the unordered population.
      Parameters:
      ind - Individual searched.
      Returns:
      the index of the Individual in the unordered population, -1 if not found.
    • getIndexOfOrderedIndividual

      public int getIndexOfOrderedIndividual(Individual ind)
      Gets the index of a given Individual in the ordered population.
      Parameters:
      ind - Individual searched.
      Returns:
      the index of the Individual in the ordered population, -1 if not found.
    • getKBestIndividual

      public Individual getKBestIndividual(int k)
      Gets the best k individual in the ordered population by fitness.
      Parameters:
      k - the kth individual.
      Returns:
      the Individual stored in the given position in the ordered population.
    • getBestIndividual

      public Individual getBestIndividual()
      Gets the best individual of the population.
      Returns:
      the best individual of the population.
    • getSubPopLB

      public int getSubPopLB()
      Gets the lower bound of the active subpopulation if mechanism for subpopulations is active.
      Returns:
      lower bound of active subpopulation.
    • getSubPopUB

      public int getSubPopUB()
      Gets the upper bound of the active subpopulation if mechanism for subpopulations is active.
      Returns:
      upper bound of active subpopulation.
    • getNRandDistinctIndividuals

      public Individual[] getNRandDistinctIndividuals(int numIndividuals)
      Gets N random individuals from the Population which are distinct among them.
      Parameters:
      numIndividuals - number of individuals to be generated.
      Returns:
      an array of individuals.
    • getNRandDistinctIndividuals

      public Individual[] getNRandDistinctIndividuals(int ind, int numIndividuals)
      Gets N random individuals from the Population which are distinct among them and disintct from the given the index of an Individual ind. If the subpopulations mechanism is active it searchs from the active subpopulation.
      Parameters:
      ind - index of the Individual to be distinct.
      numIndividuals - number of individuals to be generated.
      Returns:
      an array of individuals.
    • getNRandDistinctIndividuals

      public Individual[] getNRandDistinctIndividuals(Individual ind, int numIndividuals)
      Gets N random individuals from the Population which are distinct among them and disintct from the given Individual ind. If the subpopulations mechanism is active it searchs from the active subpopulation.
      Parameters:
      ind - Individual to be distinct.
      numIndividuals - number of individuals to be generated.
      Returns:
      an array of individuals.
    • isActiveSubPopulations

      public boolean isActiveSubPopulations()
      Checks if the mechanism for subpopulations is active or not.
      Returns:
      TRUE if it is active, FALSE otherwise.
    • setActiveSubPopulations

      public void setActiveSubPopulations(boolean b)
      Sets a new value for the mechanism of subpopulations: it can activated (TRUE) or deactivated (FALSE).
      Parameters:
      b - the new state for subpopulation mechanism.
    • setSubPopLB

      public void setSubPopLB(int lb)
      Lower bound of the active subpopulation if subpopulations mechanism is active.
      Parameters:
      lb - the lower bound of the active subpopulation.
    • setSubPopUB

      public void setSubPopUB(int ub)
      Upper bound of the active subpopulation if subpopulations mechanism is active.
      Parameters:
      ub - the upper bound of the active subpopulation.
    • setNextPopulation

      public void setNextPopulation(ArrayList<Individual> p)
      Sets a new Population and increments the generation value in its evolution.
      Parameters:
      p - new set of individuals of the next population.
    • incrPopulationG

      public void incrPopulationG()
      Increments the current generation in the evolution of the population.
    • addIndividual

      public void addIndividual(Individual ind)
      Adds a new Individual to the Population.
      Parameters:
      ind - new Individual.
    • replaceIndividual

      public void replaceIndividual(int i, Individual ind)
      Replaces an Individual at position i by the given Individual ind.
      Parameters:
      i - position where set the new individual ind
      ind - new individual for position i.
    • evaluatePopulation

      public void evaluatePopulation(Evaluator evaluator) throws IncompatibleConfigurationException
      Evaluates all the individuals of the Population given an Evaluator.
      Parameters:
      evaluator - the way each individual is going to be evaluated.
      Throws:
      IncompatibleConfigurationException - when the dimension of the problem does not fit with the dimensionality of the function used as evaluator.
    • reducePopulation

      public void reducePopulation(double factor)
      Reduces the Population given a reduction factor.
      Parameters:
      factor - reduction factor.
    • toString

      public String toString()
      Gets a string representing the visualization by console of the Population.
      Overrides:
      toString in class Object
      Returns:
      string representing the current state of the Population.