PaGMO
1.1.5
|
The Simple Genetic Algorithm (SGA) More...
#include <sga.h>
Data Structures | |
struct | crossover |
Crossover operator info. More... | |
struct | mutation |
Mutation operator info. More... | |
struct | selection |
Selection info. More... | |
Public Member Functions | |
sga (int gen=1, const double &cr=.95, const double &m=.02, int elitism=1, mutation::type mut=mutation::GAUSSIAN, double width=0.1, selection::type sel=selection::ROULETTE, crossover::type cro=crossover::EXPONENTIAL) | |
Constructor. More... | |
base_ptr | clone () const |
Clone method. | |
void | evolve (population &) const |
Evolve implementation. More... | |
std::string | get_name () const |
Algorithm name. | |
Public Member Functions inherited from pagmo::algorithm::base | |
base () | |
Default constructor. More... | |
virtual | ~base () |
Trivial destructor. More... | |
std::string | human_readable () const |
Return human readable representation of the algorithm. More... | |
void | set_screen_output (const bool p) |
Setter-Getter for protected m_screen_output data. More... | |
bool | get_screen_output () const |
Gets screen output. More... | |
void | reset_rngs (const unsigned int) const |
Resets the seed of the internal rngs using a user-provided seed. More... | |
Protected Member Functions | |
std::string | human_readable_extra () const |
Extra human readable algorithm info. More... | |
Friends | |
class | boost::serialization::access |
Additional Inherited Members | |
Protected Attributes inherited from pagmo::algorithm::base | |
bool | m_screen_output |
Indicates to the derived class whether to print stuff on screen. | |
rng_double | m_drng |
Random number generator for double-precision floating point values. | |
rng_uint32 | m_urng |
Random number generator for unsigned integer values. | |
unsigned int | m_fevals |
A counter for the number of function evaluations. | |
The Simple Genetic Algorithm (SGA)
Genetic algorithms are very popular algorithms used widely by people of very different backgrounds. As a consequence there are a large number of different implementations and toolboxes that are available and can be used to construct a genetic algorithm. We decided not to choose one of these and, instead, to provide only a basic implementation of the algorithm implementing a floating point encoding (not binary) and some common mutation and crossover strategies, hence the name Simple Genetic Algorithm.
Mutation is gaussian or random, crossover exponential or binomial and selection is tournament or best20 (i.e. 20% best of the population is selcted and reproduced 5 times).
The algorithm works on single objective, box constrained problems. The mutation operator acts differently on continuous and discrete variables.
pagmo::algorithm::sga::sga | ( | int | gen = 1 , |
const double & | cr = .95 , |
||
const double & | m = .02 , |
||
int | elitism = 1 , |
||
mutation::type | mut = mutation::GAUSSIAN , |
||
double | width = 0.1 , |
||
selection::type | sel = selection::ROULETTE , |
||
crossover::type | cro = crossover::EXPONENTIAL |
||
) |
Constructor.
Allows to specify in detail all the parameters of the algorithm.
[in] | gen | Number of generations to evolve. |
[in] | cr | Crossover probability (of each allele if binomial crossover) |
[in] | m | Mutation probability (of each allele) |
[in] | elitism | The best individual is reinserted in the population each elitism generations |
[in] | mut | Mutation type. One of sga::mutation::GAUSSIAN, sga::mutation::RANDOM |
[in] | width | Mutation width. When gaussian mutation is selected is the width of the mutation |
[in] | sel | Selection type. One of sga::selection::BEST20, sga::selection::ROULETTE |
[in] | cro | Crossover type. One of sga::crossover::BINOMIAL, sga::crossover::EXPONENTIAL |
value_error | if gen is negative, crossover probability is not , mutation probability is not , elitism is <=0 |
|
virtual |
Evolve implementation.
Run the simple genetic algorithm for the number of generations specified in the constructors. At each improvment velocity is also updated.
[in,out] | pop | input/output pagmo::population to be evolved. |
We now set the cleared pop. cur_x is the best_x, re-evaluated with new seed.
Implements pagmo::algorithm::base.
|
protectedvirtual |
Extra human readable algorithm info.
Will return a formatted string displaying the parameters of the algorithm.
Reimplemented from pagmo::algorithm::base.