geneticalgo.h
1 /********************************************************************************
2  * FARSA Genetic Algorithm Library *
3  * Copyright (C) 2007-2009 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #ifndef GENETICALGO_H
21 #define GENETICALGO_H
22 
23 #include "gaconfig.h"
24 #include "parametersettable.h"
25 #include <QVector>
26 
27 namespace farsa {
28 
29 class Genotype;
30 class Genome;
31 class Evaluation;
32 
47 public:
49  GeneticAlgo( );
51  virtual ~GeneticAlgo();
56  virtual void initialize() = 0;
61  virtual void gaStep() = 0;
66  virtual void finalize() = 0;
71  void evolve( unsigned int generationToReach );
75  void evolve();
77  bool isEvolutionEnded();
79  bool isEvaluationDone();
81  void setGenome( Genome* gen );
83  Genome* genome();
85  const Genome* genome() const;
90  virtual Evaluation* evaluationPrototype() = 0;
94  virtual QVector<Evaluation*> evaluationPool() = 0;
100  void setGeneration( unsigned int gen );
102  unsigned int generation() const;
104  void setNumGenerations( int g );
106  int numGenerations();
111  virtual void skipEvaluation() = 0;
116  QVector< QVector<double> > bestFits() const;
118  QVector< QVector<double> > averageFits() const;
120  QVector<double> meanHammingDist() const;
122  QVector<double> varianceHammingDist() const;
124  QVector<double> standardDeviationHammingDist() const;
125 
126 protected:
133  void updateStats();
134 
139 
148 
152  unsigned int generationv;
154  unsigned int numGens;
155 
157  QVector< QVector<double> > bestfits;
159  QVector< QVector<double> > avgfits;
161  QVector<double> meanHdists;
163  QVector<double> varHdists;
165  QVector<double> stdHdists;
166 };
167 
168 } // end namespace farsa
169 
170 #endif