A population of individual solutions; this is the core of a Pareto-based memetic algorithm. More...
#include <Population.hpp>
Public Member Functions | |
Population (int nobj) | |
Create a population for individuals that have nobj objectives. | |
void | fromStream (istream &ist, const IndividualReader *rdr) |
Insert individuals from a stream, using a concrete reader. | |
void | toStream (ostream &ost) const |
Write all individuals to a stream. | |
double | getObjectiveValue (int individualIndex, int objectiveIndex) const |
Get one objective value from an indexed individual. | |
vector< double > | getTrace (int individualIndex) const |
Get the vector of traced values from an indexed individual. | |
int | getIndividualID (int individualIndex) const |
Get the unique ID of an individual. | |
void | setIndividualID (int individualIndex, int newID) |
Set the unique ID of an individual. | |
size_t | size () const |
Get the current size of the population. | |
void | adopt (unique_ptr< Individual > indiv) |
Insert a new individual, obtaining ownership. | |
void | clear () |
Clear contents; individuals become deleted. | |
void | adoptFrom (Population &p1) |
Insert new individuals whose ownership is taken from the other pop. | |
void | adoptFromTwo (Population &p1, Population &p2) |
Insert new individuals whose ownership is taken from two other pops. | |
void | deepCopyFrom (Population &p1) |
Insert new individuals that are cloned from the other pop. | |
void | evaluate () |
Command all individuals to evaluate their objectives. | |
void | mutate () |
Command all individuals to mutate, according to their (possibly individually evolving) rules. | |
void | improve (mt19937 *mt) |
Command all individuals to do local improvement, according to their own, possibly individually evolving or stochastic, rules. | |
int | binaryTournament (int ii1, int ii2, mt19937 *mt) |
Return the index of the winner of a binary tournament. | |
void | assignRankAndCrowdingDistance () |
Assign ranks and crowding distances to all individuals. | |
void | fillNondominatedSortFrom (Population &parent) |
Insert copies of individuals from a parent population, as per the nondominated fill of NSGA-II. | |
void | selectAndCrossFrom (Population &parent, mt19937 *mt) |
Protected Member Functions | |
void | quicksortFrontObj (int objcount, int *obj_array, int front_size) const |
void | quicksortDist (int *dist, int front_size) const |
void | crowdingFillFrom (Population &mixed, int count, int front_size, void *plstelite) |
void | assignCrowdingDistance (int *dist, int **obj_array, int front_size) |
void | assignCrowdingDistanceList (void *plst, int front_size) |
void | assignCrowdingDistanceIndices (int c1, int c2) |
int | binaryTournament (int a, int b, mt19937 *mt) const |
Protected Attributes | |
vector< unique_ptr< Individual > > | _individuals |
Pointers to individuals. | |
size_t | _nobj |
Number of objectives. |
A population of individual solutions; this is the core of a Pareto-based memetic algorithm.
The population is responsible for the storage of individuals, and dispatching the the operations that produce the next population. The population can also be used as an archive of any number of historical solutions.
Population::Population | ( | int | nobj | ) |
Create a population for individuals that have nobj objectives.
void Population::adopt | ( | unique_ptr< Individual > | indiv | ) |
Insert a new individual, obtaining ownership.
void Population::adoptFrom | ( | Population & | p1 | ) |
Insert new individuals whose ownership is taken from the other pop.
void Population::adoptFromTwo | ( | Population & | p1, | |
Population & | p2 | |||
) |
Insert new individuals whose ownership is taken from two other pops.
void Population::assignRankAndCrowdingDistance | ( | ) |
Assign ranks and crowding distances to all individuals.
int Population::binaryTournament | ( | int | ii1, | |
int | ii2, | |||
mt19937 * | mt | |||
) |
Return the index of the winner of a binary tournament.
Needs a random generator to resolve ties.
void Population::clear | ( | ) |
Clear contents; individuals become deleted.
void Population::deepCopyFrom | ( | Population & | p1 | ) |
Insert new individuals that are cloned from the other pop.
void Population::evaluate | ( | ) |
Command all individuals to evaluate their objectives.
void Population::fromStream | ( | istream & | ist, | |
const IndividualReader * | rdr | |||
) |
Insert individuals from a stream, using a concrete reader.
int Population::getIndividualID | ( | int | individualIndex | ) | const |
Get the unique ID of an individual.
double Population::getObjectiveValue | ( | int | individualIndex, | |
int | objectiveIndex | |||
) | const |
Get one objective value from an indexed individual.
vector< double > Population::getTrace | ( | int | individualIndex | ) | const |
Get the vector of traced values from an indexed individual.
void Population::improve | ( | mt19937 * | mt | ) |
Command all individuals to do local improvement, according to their own, possibly individually evolving or stochastic, rules.
A thread-specific random generator must always be given, because some operators may require randomization.
void Population::setIndividualID | ( | int | individualIndex, | |
int | newID | |||
) |
Set the unique ID of an individual.
size_t Population::size | ( | ) | const |
Get the current size of the population.
void Population::toStream | ( | ostream & | ost | ) | const |
Write all individuals to a stream.
vector<unique_ptr<Individual> > Population::_individuals [protected] |
Pointers to individuals.
FIXME: Expect some brainwork with the pointers and the issue of who should own each individual!
size_t Population::_nobj [protected] |
Number of objectives.
FIXME: Shouldn't require this in the general Population, but only in some friend class that operates on the population?