Utility classes

class pagmo::not_population_based

Base class for non population based solvers.

This class contains common methods useful in the implementation of user-defined algorithms that are not population based and establishes a common interface to a population

Currently, this class implements policies for the selection and replacement of a single individual in a population, which are meant to be used in the implementation of the evolve() method of the user-defined algorithm (see, e.g., pagmo::nlopt::evolve()).

Subclassed by pagmo::compass_search, pagmo::ipopt, pagmo::nlopt, pagmo::simulated_annealing

Public Functions

not_population_based()

Default constructor.

The default constructor sets the selection and replacement policies to "best", and it initialises the RNG of the "random" selection/replacements policies via random_device::next().

void set_random_sr_seed(unsigned)

Set the seed for the "random" selection/replacement policies.

Parameters

seed – the value that will be used to seed the random number generator used by the "random" selection/replacement policies.

void set_selection(const std::string&)

Set the individual selection policy.

This method will set the policy that is used to select the individual that will be optimised when calling the evolve() method of the algorithm.

The input string must be one of "best", "worst" and "random":

  • "best" will select the best individual in the population,

  • "worst" will select the worst individual in the population,

  • "random" will randomly choose one individual in the population.

set_random_sr_seed() can be used to seed the random number generator used by the "random" policy.

Instead of a selection policy, a specific individual in the population can be selected via set_selection(population::size_type).

Parameters

select – the selection policy.

Throws

std::invalid_argument – if select is not one of "best", "worst" or "random".

inline void set_selection(population::size_type n)

Set the individual selection index.

This method will set the index of the individual that is selected for optimisation in the evolve() method of the algorithm.

Parameters

n – the index in the population of the individual to be selected for optimisation.

boost::any get_selection() const

Get the individual selection policy or index.

This method will return a boost::any containing either the individual selection policy (as an std::string) or the individual selection index (as a population::size_type). The selection policy or index is set via set_selection(const std::string &) and set_selection(population::size_type).

Returns

the individual selection policy or index.

void set_replacement(const std::string&)

Set the individual replacement policy.

This method will set the policy that is used in the evolve() method of the algorithm to select the individual that will be replaced by the optimised individual.

The input string must be one of "best", "worst" and "random":

  • "best" will select the best individual in the population,

  • "worst" will select the worst individual in the population,

  • "random" will randomly choose one individual in the population.

set_random_sr_seed() can be used to seed the random number generator used by the "random" policy.

Instead of a replacement policy, a specific individual in the population can be selected via set_replacement(population::size_type).

Parameters

replace – the replacement policy.

Throws

std::invalid_argument – if replace is not one of "best", "worst" or "random".

inline void set_replacement(population::size_type n)

Set the individual replacement index.

This method will set the index of the individual that is replaced after the optimisation in the evolve() method of the algorithm.

Parameters

n – the index in the population of the individual to be replaced after the optimisation.

boost::any get_replacement() const

Get the individual replacement policy or index.

This method will return a boost::any containing either the individual replacement policy (as an std::string) or the individual replacement index (as a population::size_type). The replacement policy or index is set via set_replacement(const std::string &) and set_replacement(population::size_type).

Returns

the individual replacement policy or index.

Protected Functions

std::pair<vector_double, vector_double> select_individual(const population&) const

Select individual.

This method will select a single individual from the input population pop, returning its decision vector and fitness as a pair. The selection is done according to the currently active selection policy:

Note that selecting a best or worst individual is meaningful only in single-objective problems.

Parameters

pop – the input population.

Throws
Returns

a pair containing the decision and fitness vectors of the selected individual.

void replace_individual(population&, const vector_double&, const vector_double&) const

Replace individual.

This method will replace a single individual in the input population pop, setting its decision vector to x and its fitness vector to f. The selection is done according to the currently active selection policy:

Note that selecting a best or worst individual is meaningful only in single-objective problems.

Parameters
  • pop – the input population.

  • x – the decision vector of the new individual.

  • f – the fitness vector of the new individual.

Throws

Protected Attributes

boost::any m_select

Individual selection policy.

This boost::any instance must contain either an std::string or a population::size_type, otherwise the behaviour will be undefined.

boost::any m_replace

Individual replacement policy.

This boost::any instance must contain either an std::string or a population::size_type, otherwise the behaviour will be undefined.

unsigned m_rselect_seed

Seed for the "random" selection/replacement policies.

mutable detail::random_engine_type m_e

Random engine for the "random" selection/replacement policies.