GeneticAlgoithm
Implementation of the genetic algorithm
|
Class imlementing the Genetic Algorithm. More...
#include <GeneticAlgorithm.h>
Public Member Functions | |
GeneticAlgorithm () | |
~GeneticAlgorithm () | |
IModel * | optimize (IPopulation *population) |
void | initialize (IPopulation *population) |
bool | nextGeneration () |
int | getCurrentGeneration () |
void | setNGenerationsMax (int generationsMax) |
void | setPopulationSize (int populationSize) |
Private Attributes | |
int | m_generationsMax |
Stores the maximum number of generations. | |
int | m_populationSize |
Stores the desired population size. | |
int | m_currentGeneration |
Stores the number of the current generation. | |
IPopulation * | m_population |
Stores a pointer to the population being optimized. | |
Class imlementing the Genetic Algorithm.
There is no need to derive from this class: the implementation is built on top of the IModel, IFigureOfMerit and IPopulation interfaces.
The algorithm flow is as follows:
Definition at line 23 of file GeneticAlgorithm.h.
GeneticAlgorithm::GeneticAlgorithm | ( | ) |
Default Constructor
Definition at line 6 of file GeneticAlgorithm.cxx.
GeneticAlgorithm::~GeneticAlgorithm | ( | ) |
Destructor
Definition at line 12 of file GeneticAlgorithm.cxx.
IModel * GeneticAlgorithm::optimize | ( | IPopulation * | population | ) |
Finds the best solution given a population of models.
population | Population of models to optimize. |
Definition at line 20 of file GeneticAlgorithm.cxx.
void GeneticAlgorithm::initialize | ( | IPopulation * | population | ) |
Initialize the algorithm before the optimization loop starts.
This function is provided so that the user have the option to control the optimization loop and possibly execute some code before/after each iteration. This can be useful for example to implement tests that need to monitor the progress of the optimization.
population | Population of models to optimize. |
Definition at line 37 of file GeneticAlgorithm.cxx.
bool GeneticAlgorithm::nextGeneration | ( | ) |
Perform one iteration of the optimization loop: creates next generation of models.
This function is provided so that the user have the option to control the optimization loop and possibly execute some code before/after each iteration. This can be useful for example to implement tests that need to monitor the progress of the optimization.
true
if more generations are needed, false
if optimal solution has been reached. Definition at line 53 of file GeneticAlgorithm.cxx.
int GeneticAlgorithm::getCurrentGeneration | ( | ) |
Returns the current generation number.
Definition at line 75 of file GeneticAlgorithm.cxx.
void GeneticAlgorithm::setNGenerationsMax | ( | int | generationsMax | ) |
Sets the maximum number of generations before giving up.
Desired | maximum number of iterations. |
Definition at line 83 of file GeneticAlgorithm.cxx.
void GeneticAlgorithm::setPopulationSize | ( | int | populationSize | ) |
Sets the population size
Desired | population size. |
Definition at line 92 of file GeneticAlgorithm.cxx.