pagmo::
population
¶Population class.
This class represents a population of individuals, i.e. potential candidate solutions to a given problem. In PaGMO an individual is determined
Public Types
size_type
¶A shortcut to std::vector<vector_double>::size_type
.
Public Functions
population
()¶Default constructor.
Constructs an empty population with a pagmo::null_problem. The random seed is initialised to zero.
population
(T &&x, size_type pop_size = 0u, unsigned int seed = pagmo::random_device::next ())¶Constructor from a problem of type T
.
Constructs a population with pop_size
individuals associated to the problem x
and setting the population random seed to seed
. In order for the construction to be succesfull, x
must be such that a pagmo::problem can be constructed from it.
x
- the user problem the population refers to
pop_size
- population size (i.e. number of individuals therein)
seed
- seed of the random number generator used, for example, to create new random individuals within the bounds
unspecified
- any exception thrown by decision_vector() or by push_back()
population
(const population&)¶Defaulted copy constructor.
population
(population&&)¶Defaulted move constructor.
operator=
(const population &other)¶Copy assignment operator.
Copy assignment is implemented via copy+move.
this
.other
- assignment argument.
unspecified
- any exception thrown by the copy constructor.
operator=
(population&&)¶Defaulted move assignment operator.
~population
()¶Trivial destructor.
The destructor will run sanity checks in debug mode.
push_back
(const vector_double &x)¶Adds one decision vector (chromosome) to the population.
Appends a new chromosome x
to the population, evaluating its fitness and creating a new unique identifier for the newly born individual.
In case of exceptions, the population will not be altered.
x
- decision vector to be added to the population.
unspecified
- any exception thrown by memory errors in standard containers or by problem::fitness(). Wrong dimensions for the input decision vector or the output fitness will trigger an exception.
decision_vector
() const¶Creates a random decision vector.
Creates a random decision vector within the problem’s bounds. It calls internally pagmo::decision_vector().
unspecified
- all exceptions thrown by pagmo::decision_vector()
best_idx
(const vector_double &tol) const¶Index of best individual (accounting for a vector tolerance)
If the problem is single-objective and unconstrained, the best is simply the individual with the smallest fitness. If the problem is, instead, single objective, but with constraints, the best will be defined using the criteria specified in pagmo::sort_population_con(). If the problem is multi-objective one single best is not well defined. In this case the user can still obtain a strict ordering of the population individuals by calling the pagmo::sort_population_mo() function.
tol
- vector of tolerances to be applied to each constraints
std::invalid_argument
- if the problem is multiobjective and thus a best individual is not well defined
best_idx
(double tol = 0.) const¶Index of best individual (accounting for a scalar tolerance)
tol
- scalar tolerance to be considered for each constraint
worst_idx
(const vector_double &tol) const¶Index of worst individual (accounting for a vector tolerance)
If the problem is single-objective and unconstrained, the worst is simply the individual with the largest fitness. If the problem is, instead, single objective, but with constraints, the best individual will be defined using the criteria specified in pagmo::sort_population_con(). If the problem is multi-objective one single worst is not defined. In this case the user can still obtain a strict ordering of the population individuals by calling the pagmo::sort_population_mo() function.
tol
- vector of tolerances to be applied to each constraints
std::invalid_argument
- if the problem is multiobjective and thus a best individual is not well defined
worst_idx
(double tol = 0.) const¶Index of worst individual (accounting for a scalar tolerance)
tol
- scalar tolerance to be considered for each constraint
set_xf
(size_type i, const vector_double &x, const vector_double &f)¶Sets the \(i\)-th individual decision vector, and fitness.
Sets simultaneously the \(i\)-th individual decision vector and fitness thus avoiding to trigger a fitness function evaluation.
f
makes sense as pagmo will only check its dimension.i
- individual’s index in the population
x
- a decision vector (chromosome)
f
- a fitness vector
std::invalid_argument
- if i
is invalid (i.e. larger or equal to the population size)
std::invalid_argument
- if x
has not the correct dimension
std::invalid_argument
- if f
has not the correct dimension
set_x
(size_type i, const vector_double &x)¶Sets the \(i\)-th individual’s chromosome.
Sets the chromosome of the \(i\)-th individual to the value x
and changes its fitness accordingly. The individual’s ID remains the same.
i
- individual’s index in the population
x
- decision vector
unspecified
- any exception thrown by set_xf
set_problem_seed
(unsigned int seed)¶Setter for the problem seed.
get_problem
() const¶Getter for the pagmo::problem.
get_f
() const¶Getter for the fitness vectors.
get_x
() const¶Getter for the decision vectors.
get_ID
() const¶Getter for the individual IDs.
get_seed
() const¶Getter for the seed of the population random engine.
serialize
(Archive &ar)¶Serialization.
Friends
operator<<
(std::ostream &os, const population &p)¶Streaming operator for the class pagmo::population.