GeneticAlgoithm
Implementation of the genetic algorithm
GeneticAlgorithm.h
1 #ifndef GENETICALGORITHM_H
2 #define GENETICALGORITHM_H
3 
4 class IModel;
5 class IFigureOfMerit;
6 class IPopulation;
7 
8 /**
9  * @brief Class imlementing the Genetic Algorithm.
10  *
11  * There is no need to derive from this class: the implementation is built on top of the
12  * IModel, IFigureOfMerit and IPopulation interfaces.
13  *
14  * The algorithm flow is as follows:
15  * - Creates an initial population.
16  * - Rank the population.
17  * - Repeat the following until a solution is found or a maximum numeber of generations is reached:
18  * - Select parents among the fittest individuals.
19  * - Cross them over to form a new population.
20  * - Mutate some individuals.
21  * - Rank the new population.
22  */
24 
25 public:
26 
27  /** Default Constructor */
29 
30  /** Destructor */
32 
33  /** Finds the best solution given a population of models. */
34  IModel *optimize(IPopulation *population);
35 
36  /** Initialize the algorithm before the optimization loop starts. */
37  void initialize(IPopulation *population);
38 
39  /** Perform one iteration of the optimization loop: creates next generation of models. */
40  bool nextGeneration();
41 
42  /** Returns the current generation number. */
44 
45  /** Sets the maximum number of generations before giving up. */
46  void setNGenerationsMax(int generationsMax);
47 
48  /** Sets the population size */
49  void setPopulationSize(int populationSize);
50 
51 private:
52 
53  int m_generationsMax; //!< Stores the maximum number of generations.
54  int m_populationSize; //!< Stores the desired population size.
55  int m_currentGeneration; //!< Stores the number of the current generation.
56  IPopulation *m_population; //!< Stores a pointer to the population being optimized.
57 };
58 
59 #endif
Abstract class describing a population of models.
Definition: IPopulation.h:27
int m_generationsMax
Stores the maximum number of generations.
int m_populationSize
Stores the desired population size.
void initialize(IPopulation *population)
void setNGenerationsMax(int generationsMax)
Abstract class representing a figure of merit.
Class imlementing the Genetic Algorithm.
IModel * optimize(IPopulation *population)
IPopulation * m_population
Stores a pointer to the population being optimized.
void setPopulationSize(int populationSize)
int m_currentGeneration
Stores the number of the current generation.
Abstract class describing the interface for a model.
Definition: IModel.h:13