GPLIB++
ParetoGA.h
Go to the documentation of this file.
1 #ifndef CPARETOGA_H
2 #define CPARETOGA_H
3 
4 #include "GeneralGA.h"
5 #include <iostream>
6 #include <vector>
7 #include "VecMat.h"
8 
9 namespace gplib
10  {
11  /** \addtogroup gainv Genetic algorithm optimization */
12  /* @{ */
13  //! Implements a genetic algorithm based on the concept of pareto-optimality, best suited for multi-objective problems
14  /*! The class ParetoGA implements a variant of NSGA-II by Deb et al.:
15  * Deb, K., Pratap. A, Agarwal, S., and Meyarivan, T. (2002). A fast and elitist multi-objective genetic algorithm: NSGA-II. IEEE Transaction on Evolutionary Computation, 6(2), 181-197.
16  */
17  class ParetoGA: public GeneralGA
18  {
19  private:
20  typedef ublas::matrix_row<gplib::rmat>::const_iterator tMisfitIterator;
21  void CalcCrowdingDistance(gplib::rmat &LocalMisFit,
22  GeneralPopulation &LocalPopulation);
23  std::vector<std::vector<int> > Ranks;
24  int MaxRanks;
25  protected:
26  //! The function Elitism ensures that the best models are preserved after mutation and crossover
27  void virtual Elitism(const int iterationnumber);
28  public:
29  //! Return the size of the pareto-optimal front
30  unsigned int virtual GetNBestmodels()
31  {
32  return Ranks.front().size();
33  }
34  //! Get the indices of the models within the Pareto front
35  std::vector<int> virtual GetBestModelIndices()
36  {
37  return Ranks.front();
38  }
39  //! Calculate the probabilities of reproduction by ranking the population
40  void virtual CalcProbabilities(const int iterationnumber,
41  gplib::rmat &LocalMisFit, GeneralPopulation &LocalPopulation);
42  //! Write the population by ranks to the stream output
43  void PrintRanks(std::ostream &output);
44  //! Write the models in the pareto-optimal front to stream output
45  void PrintFront(std::ostream &output);
46  //! The constructor needs other classes that determine the behaviour of the GA
47  ParetoGA(GeneralPropagation* const LocalPropagation,
48  GeneralPopulation* const LocalPopulation,
49  GeneralTranscribe* const LocalTranscribe,
50  const tObjectiveVector &IndObjective, const int nthreads = 1) :
51  GeneralGA(LocalPropagation, LocalPopulation, LocalTranscribe,
52  IndObjective, nthreads)
53  {
54  }
55  virtual ~ParetoGA();
56  };
57  /* @} */
58  }
59 #endif // CPARETOGA_H
The base class for the population of a genetic algorithm, implements storage and access functions...
virtual void Elitism(const int iterationnumber)
The function Elitism ensures that the best models are preserved after mutation and crossover...
Definition: ParetoGA.cpp:162
virtual ~ParetoGA()
Definition: ParetoGA.cpp:239
The base class for genetic algorithm propagation methods.
ParetoGA(GeneralPropagation *const LocalPropagation, GeneralPopulation *const LocalPopulation, GeneralTranscribe *const LocalTranscribe, const tObjectiveVector &IndObjective, const int nthreads=1)
The constructor needs other classes that determine the behaviour of the GA.
Definition: ParetoGA.h:47
unsigned virtual int GetNBestmodels()
Return the size of the pareto-optimal front.
Definition: ParetoGA.h:30
void PrintRanks(std::ostream &output)
Write the population by ranks to the stream output.
Definition: ParetoGA.cpp:208
virtual void CalcProbabilities(const int iterationnumber, gplib::rmat &LocalMisFit, GeneralPopulation &LocalPopulation)
Calculate the probabilities of reproduction by ranking the population.
Definition: ParetoGA.cpp:89
General Transcribe base class for genetic algorithm parameter transcription.
void PrintFront(std::ostream &output)
Write the models in the pareto-optimal front to stream output.
Definition: ParetoGA.cpp:226
General genetic algorithm class.
Definition: GeneralGA.h:25
Implements a genetic algorithm based on the concept of pareto-optimality, best suited for multi-objec...
Definition: ParetoGA.h:17
std::vector< boost::shared_ptr< GeneralObjective > > tObjectiveVector
Definition: GeneralGA.h:31
virtual std::vector< int > GetBestModelIndices()
Get the indices of the models within the Pareto front.
Definition: ParetoGA.h:35