• Main Page
  • Namespaces
  • Classes
  • Files
  • Class List
  • Class Hierarchy
  • Class Members

Population Class Reference

This class represents a population of individuals. More...

#include <Population.h>

List of all members.

Public Member Functions

 Population (string name, int initialPopulationSize, int maximumPopulationSize, Random *random, MultiobjectiveProblem *problem)
 Constructor.
 ~Population (void)
 Destructor.
int getPopulationSize () const
 Gets the size of the population.
int getMaximumPopulationSize () const
 Gets the maximum size of the population.
Individual * getIth (int index) const
 Gets a reference to the i-th individual of the population.
Individual * getRandom () const
 Gets a reference to a randomly chosen individual of the population.
Individual * extractIth (int index)
 Extracts the i-th individual of the population. If it belongs to more than one population, its population counter is decremented.
void setIth (int index, Individual *ind)
 Sets the i-th individual of the population.
void deleteIth (int index)
 Deletes the i-th individual of the population if it belongs to one population. Otherwise, the population counter is decremented.
void addIndividual (Individual *individual)
 Add a new individual to the population.
void setFitness (int index, double *fitness)
 Sets the fitness of the i-th individual.
void removeAllIndividuals ()
 Deletes all the individuals of the population.
void reset ()
 Sets the number of individuals to 0. The individuals are not deleted.
void swap (int index1, int index2)
 Interchanges the position of two individuals in the population.
void sortByFitness (int functionIdentifier)
 Sort in ascending order by fitness value.
void sortByRankAndCrowding ()
 Sorting in ascending order by rank and crowding.
void sortByStrengthRawFitnessAndCrowding ()
 Sorting in ascending order by strength raw fitness and crowding.
void sortByStrengthFitness ()
 Sorting in ascending order by strength fitness.
void crowdingDistanceAssignment ()
 Calculates the crowding distance of the individuals.
void strengthAssignment ()
 Calculates the strength of the individuals according to the SPEA2 algorithm.
void strengthRawFitnessAssignment ()
 Calculates the raw fitness to the individuals according to their strength values. Requires the previous invocation of strengthAssignment().
void maxiMinDistanceAssignment ()
 Calculates the maxiMin distance of the individuals to the population. After the method, the individuals are sorted in descending order by distance.
void printFitness (char *fileName)
 Prints the fitness of the individuals in the population.
void printGenotype (char *fileName)
 Prints the genotype of the individuals in the population.
int removeDominatedIndividuals ()
 Remove the dominated individuals in the population.
Individual * tournamentSelection ()
 Randomly selects two individuals and applies tournament selection to chose one of them. Dominanced is considered to decide the winner.
Individual * strengthAndCrowdingTournamentSelection ()
 Randomly selects two individuals and applies tournament selection to chose one of them. Strength raw fitness and crowding distance are considered to decide the winner.
Individual * crowdedComparison (Individual *, Individual *)
 Crowded comparison operator according to the rank defined in NSGA-II.
Individual * rankingAndCrowdingTournamentSelection ()
 Randomly selects two individuals and applies tournament selection to chose one of them. Ranking and crowding distance are considered to decide the winner.
bool thereIsAnEqualFitnessIndividual (Individual *individual, int *position)
 Finds whether there is an indivual in the population with the same fitness.
bool individualIsInPopulation (Individual *individual, int *position)
 Finds whether there the individual is in the population.
int testIfIndividualDominates (Individual *individual)
 Checks if the individual is dominated by any member of the population.
void clustering (int clusters, Population **centroids)
 Apply a minimal spanning tree algorithm to perform a clustering of the individuals in the population.
void minimumDistanceToPopulation (Individual *individual)

Public Attributes

string name_
int populationSize_
int maximumPopulationSize_
Individual ** population_
Random * random_
MultiobjectiveProblem * problem_


Detailed Description

The population size can be dynamic: individuals can be deleted, and new individuals can be added. The number of elements is bounded.

Definition at line 25 of file Population.h.


Constructor & Destructor Documentation

Population::Population (  string  name,
int  initialPopulationSize,
int  maximumPopulationSize,
Random *  random,
MultiobjectiveProblem *  problem
) 
 

Parameters:
name Name of the population
initialPopulationSize The initial size of the population
maximumPopulationSize The maximun size of the population
random Pointer to the random number generator
problem The problem to solve
Constructor of the class

Definition at line 21 of file Population.cpp.

References maximumPopulationSize_, name_, population_, populationSize_, problem_, and random_.

Referenced by clustering(), maxiMinDistanceAssignment(), and removeDominatedIndividuals().

Population::~Population (  void   ) 
 

Destructor of the class

Definition at line 51 of file Population.cpp.

References population_, and populationSize_.


Member Function Documentation

void Population::addIndividual (  Individual *  individual  ) 
 

Parameters:
individual The individual to be added

Definition at line 167 of file Population.cpp.

References maximumPopulationSize_, name_, population_, and populationSize_.

Referenced by Ssmo::addImprovedIndividual(), AbYSS::addImprovedIndividual(), AbYSS::archiveSolution(), Ranking::copyFrontToPopulation(), maxiMinDistanceAssignment(), Ssmo2::referenceSetUpdate(), Ssmo1::referenceSetUpdate(), AbYSS::referenceSetUpdate(), removeDominatedIndividuals(), Ssmo2::removeIndividuals(), Ssmo1::removeIndividuals(), AbYSS::solutionCombination(), and AbYSS::start().

void Population::clustering (  int  clusters,
Population **  centroids
) 
 

Parameters:
clusters The number of clusters
centroids The centroids obtained after the clustering
This method is intended to be used with real variables. The centroids population is created inside the method.

Definition at line 797 of file Population.cpp.

References RealGene::allele_, getIth(), MAX_REAL, name_, MultiobjectiveProblem::numberOfVariables_, Population(), populationSize_, problem_, and random_.

Referenced by Ssmo2::referenceSetUpdate().

Individual * Population::crowdedComparison (  Individual *  individual1,
Individual *  individual2
) 
 

Parameters:
individual1 The first individual
individual2 The second individual
Returns:
The selected individual

Definition at line 594 of file Population.cpp.

References Individual::distance_, and Individual::rank_.

Referenced by rankingAndCrowdingTournamentSelection().

void Population::crowdingDistanceAssignment (   ) 
 

Definition at line 409 of file Population.cpp.

References Individual::distance_, Individual::fitness_, getIth(), getPopulationSize(), MAX_REAL, name_, MultiobjectiveProblem::numberOfFunctions_, and problem_.

Referenced by AbYSS::archiveSolution(), Ssmo1::referenceSetUpdate(), Ssmo2::removeDominatedIndividuals(), Ssmo1::removeDominatedIndividuals(), Ssmo2::removeIndividuals(), Ssmo1::removeIndividuals(), and AbYSS::removeIndividuals().

void Population::deleteIth (  int  index  ) 
 

Parameters:
index The index of the individual

Definition at line 186 of file Population.cpp.

References name_, Individual::numberOfPopulations_, population_, and populationSize_.

Referenced by AbYSS::archiveSolution(), and removeAllIndividuals().

Individual * Population::extractIth (  int  index  ) 
 

Parameters:
index The index of the individual
Returns:
The i-th individual reference

Definition at line 115 of file Population.cpp.

References name_, Individual::numberOfPopulations_, population_, and populationSize_.

Referenced by Ssmo2::referenceSetUpdate(), Ssmo1::referenceSetUpdate(), AbYSS::referenceSetUpdate(), removeDominatedIndividuals(), Ssmo2::removeIndividuals(), and Ssmo1::removeIndividuals().

Individual * Population::getIth (  int  index  )  const
 

Parameters:
index The index of the individual
Returns:
The i-th individual reference

Definition at line 79 of file Population.cpp.

References name_, population_, and populationSize_.

Referenced by AbYSS::archiveSolution(), K_Distance::calculateDistanceMatrix(), clustering(), crowdingDistanceAssignment(), Ssmo::distanceToPopulation(), AbYSS::distanceToPopulation(), maxiMinDistanceAssignment(), minimumDistanceToPopulation(), printFitness(), printGenotype(), rankingAndCrowdingTournamentSelection(), Ranking::rankPopulation(), Ssmo2::referenceSetUpdate(), Ssmo1::referenceSetUpdate(), AbYSS::referenceSetUpdate(), Nsga2::start(), strengthAndCrowdingTournamentSelection(), strengthRawFitnessAssignment(), Ssmo2::subsetGeneration(), Ssmo1::subsetGeneration(), AbYSS::subsetGeneration(), and tournamentSelection().

int Population::getMaximumPopulationSize (   )  const
 

Returns:
The maximum size of the population

Definition at line 70 of file Population.cpp.

References maximumPopulationSize_.

int Population::getPopulationSize (   )  const
 

Returns:
The size of the population

Definition at line 61 of file Population.cpp.

References populationSize_.

Referenced by Ssmo::addImprovedIndividual(), AbYSS::archiveSolution(), K_Distance::calculateDistanceMatrix(), K_Distance::calculateKDistance(), crowdingDistanceAssignment(), K_Distance::distanceComparison(), Ssmo::distanceToPopulation(), AbYSS::distanceToPopulation(), K_Distance::findMinimumDistanceIndividual(), maxiMinDistanceAssignment(), minimumDistanceToPopulation(), printFitness(), printGenotype(), Ssmo::printToFiles(), AbYSS::printToFiles(), Ssmo2::referenceSetUpdate(), Ssmo1::referenceSetUpdate(), AbYSS::referenceSetUpdate(), Ssmo2::removeDominatedIndividuals(), Ssmo1::removeDominatedIndividuals(), removeDominatedIndividuals(), Ssmo2::removeIndividuals(), Ssmo1::removeIndividuals(), AbYSS::removeIndividuals(), AbYSS::start(), strengthAssignment(), strengthRawFitnessAssignment(), Ssmo2::subsetGeneration(), Ssmo1::subsetGeneration(), AbYSS::subsetGeneration(), and testIfIndividualDominates().

Individual * Population::getRandom (   )  const
 

Returns:
The reference to the chosen individual

Definition at line 95 of file Population.cpp.

References name_, population_, populationSize_, random_, and Random::rnd().

bool Population::individualIsInPopulation (  Individual *  individual,
int *  position
) 
 

Parameters:
individual The individual to search
position The position of the found individual in the population
Returns:
True if the individual in the population, false otherwise
If the second parameter is not NULL it will contain the position of the individual in the population, if applicable

Definition at line 743 of file Population.cpp.

References population_, and populationSize_.

void Population::maxiMinDistanceAssignment (   ) 
 

Definition at line 448 of file Population.cpp.

References addIndividual(), Individual::distance_, getIth(), getPopulationSize(), MAX_REAL, MultiobjectiveProblem::numberOfFunctions_, Population(), and problem_.

void Population::minimumDistanceToPopulation (  Individual *  individual  ) 
 

Definition at line 498 of file Population.cpp.

References Individual::chromosome_, Individual::distance_, Chromosome::gene_, getIth(), getPopulationSize(), Gene::getRealAllele(), MultiobjectiveProblem::numberOfVariables_, and problem_.

void Population::printFitness (  char *  fileName  ) 
 

Parameters:
fileName The name of the ouput file

Definition at line 248 of file Population.cpp.

References getIth(), getPopulationSize(), MultiobjectiveProblem::numberOfFunctions_, and problem_.

Referenced by MoEA::printFunctionValuesToFile().

void Population::printGenotype (  char *  fileName  ) 
 

Parameters:
fileName The name of the ouput file

Definition at line 271 of file Population.cpp.

References getIth(), getPopulationSize(), MultiobjectiveProblem::numberOfVariables_, and problem_.

Referenced by MoEA::printVariablesToFile().

Individual * Population::rankingAndCrowdingTournamentSelection (   ) 
 

Returns:
The selected individual

Definition at line 656 of file Population.cpp.

References crowdedComparison(), getIth(), populationSize_, random_, and Random::rnd().

void Population::removeAllIndividuals (   ) 
 

Definition at line 213 of file Population.cpp.

References deleteIth(), and populationSize_.

Referenced by removeDominatedIndividuals(), Ssmo2::removeIndividuals(), and Ssmo1::removeIndividuals().

int Population::removeDominatedIndividuals (   ) 
 

Returns:
The number of removed individuals

Definition at line 613 of file Population.cpp.

References addIndividual(), Ranking::copyFrontToPopulation(), extractIth(), getPopulationSize(), maximumPopulationSize_, Ranking::nonDominatedFront_, Population(), populationSize_, problem_, random_, Ranking::rankPopulation(), and removeAllIndividuals().

void Population::reset (   ) 
 

Definition at line 228 of file Population.cpp.

References populationSize_.

Referenced by Ranking::rankPopulation().

void Population::setFitness (  int  index,
double *  fitness
) 
 

Parameters:
index The position of the individual
fitness The individual fitness

Definition at line 158 of file Population.cpp.

References population_, and Individual::setFitness().

void Population::setIth (  int  index,
Individual *  individual
) 
 

Parameters:
index The index of the individual
individual The individual to assign

Definition at line 142 of file Population.cpp.

References name_, population_, and populationSize_.

void Population::sortByFitness (  int  functionIdentifier  ) 
 

Parameters:
functionIdentifier The identifier of the funcion whose fitness is used for sorting

Definition at line 325 of file Population.cpp.

References MultiobjectiveProblem::numberOfFunctions_, population_, populationSize_, problem_, and swap().

Referenced by Ssmo::printToFiles(), Nsga2::printToFiles(), and AbYSS::printToFiles().

void Population::sortByRankAndCrowding (   ) 
 

Definition at line 390 of file Population.cpp.

References population_, populationSize_, and swap().

Referenced by Ssmo1::referenceSetUpdate(), Ssmo2::removeDominatedIndividuals(), Ssmo1::removeDominatedIndividuals(), Ssmo2::removeIndividuals(), Ssmo1::removeIndividuals(), and AbYSS::removeIndividuals().

void Population::sortByStrengthFitness (   ) 
 

Definition at line 373 of file Population.cpp.

References population_, populationSize_, and swap().

Referenced by AbYSS::referenceSetUpdate().

void Population::sortByStrengthRawFitnessAndCrowding (   ) 
 

Definition at line 351 of file Population.cpp.

References population_, populationSize_, and swap().

Individual * Population::strengthAndCrowdingTournamentSelection (   ) 
 

Returns:
The selected individual

Definition at line 296 of file Population.cpp.

References Individual::distance_, getIth(), populationSize_, random_, Random::rnd(), and Individual::strengthRawFitness_.

void Population::strengthAssignment (   ) 
 

Definition at line 528 of file Population.cpp.

References getPopulationSize().

Referenced by AbYSS::referenceSetUpdate().

void Population::strengthRawFitnessAssignment (   ) 
 

Definition at line 562 of file Population.cpp.

References getIth(), getPopulationSize(), and Individual::strengthRawFitness_.

Referenced by AbYSS::referenceSetUpdate().

void Population::swap (  int  index1,
int  index2
) 
 

Definition at line 236 of file Population.cpp.

References population_.

Referenced by sortByFitness(), sortByRankAndCrowding(), sortByStrengthFitness(), and sortByStrengthRawFitnessAndCrowding().

int Population::testIfIndividualDominates (  Individual *  individual  ) 
 

Parameters:
individual The individual to compare
Returns:
0 if the individual is non-dominated, -1 if it is dominated, 1 if it dominates all the members of the population

Definition at line 771 of file Population.cpp.

References Individual::dominanceTest(), and getPopulationSize().

bool Population::thereIsAnEqualFitnessIndividual (  Individual *  individual,
int *  position
) 
 

Parameters:
individual The individual to search
position The position of the found individual in the population
Returns:
True if there is an individual with identical fitness in the population, false otherwise
If the second parameter is not NULL it will contain the position of the individual in the population, if applicable

Definition at line 712 of file Population.cpp.

References Individual::identicalFitness(), population_, and populationSize_.

Referenced by Ssmo::addImprovedIndividual(), and AbYSS::addImprovedIndividual().

Individual * Population::tournamentSelection (   ) 
 

Returns:
The selected individual

Definition at line 675 of file Population.cpp.

References Individual::dominanceTest(), getIth(), Individual::numberOfViolatedConstraintsTest(), populationSize_, random_, Random::rnd(), and Random::rndreal().


Member Data Documentation

int Population::maximumPopulationSize_
 

Definition at line 29 of file Population.h.

Referenced by Ssmo::addImprovedIndividual(), addIndividual(), getMaximumPopulationSize(), K_Distance::K_Distance(), Population(), Ranking::Ranking(), removeDominatedIndividuals(), K_Distance::~K_Distance(), and Ranking::~Ranking().

string Population::name_
 

Definition at line 27 of file Population.h.

Referenced by addIndividual(), clustering(), crowdingDistanceAssignment(), deleteIth(), extractIth(), getIth(), getRandom(), Population(), Ranking::rankPopulation(), and setIth().

Individual** Population::population_
 

Definition at line 30 of file Population.h.

Referenced by addIndividual(), deleteIth(), extractIth(), getIth(), getRandom(), individualIsInPopulation(), Population(), setFitness(), setIth(), sortByFitness(), sortByRankAndCrowding(), sortByStrengthFitness(), sortByStrengthRawFitnessAndCrowding(), swap(), thereIsAnEqualFitnessIndividual(), and ~Population().

int Population::populationSize_
 

Definition at line 28 of file Population.h.

Referenced by addIndividual(), clustering(), deleteIth(), extractIth(), getIth(), getPopulationSize(), getRandom(), individualIsInPopulation(), Population(), rankingAndCrowdingTournamentSelection(), Ranking::rankPopulation(), removeAllIndividuals(), removeDominatedIndividuals(), reset(), setIth(), sortByFitness(), sortByRankAndCrowding(), sortByStrengthFitness(), sortByStrengthRawFitnessAndCrowding(), strengthAndCrowdingTournamentSelection(), thereIsAnEqualFitnessIndividual(), tournamentSelection(), and ~Population().

MultiobjectiveProblem* Population::problem_
 

Definition at line 33 of file Population.h.

Referenced by clustering(), crowdingDistanceAssignment(), K_Distance::K_Distance(), maxiMinDistanceAssignment(), minimumDistanceToPopulation(), Population(), printFitness(), printGenotype(), Ranking::Ranking(), removeDominatedIndividuals(), and sortByFitness().

Random* Population::random_
 

Definition at line 31 of file Population.h.

Referenced by clustering(), getRandom(), Population(), Ranking::Ranking(), rankingAndCrowdingTournamentSelection(), removeDominatedIndividuals(), strengthAndCrowdingTournamentSelection(), and tournamentSelection().


The documentation for this class was generated from the following files:
  • Population.h
  • Population.cpp

Our Software

orangebox Mallba

orangebox ssGA

orangebox JGDS

orangebox xxGA

orangebox JCell

orangebox MHTB

orangebox DEME

orangebox JMetal

orangebox More...

orangebox Go Back