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 
45 public:
47  GeneticAlgo( );
49  virtual ~GeneticAlgo();
54  virtual void initialize() = 0;
59  virtual void gaStep() = 0;
64  virtual void finalize() = 0;
69  void evolve( unsigned int generationToReach );
73  void evolve();
75  bool isEvolutionEnded();
77  bool isEvaluationDone();
79  void setGenome( Genome* gen );
81  Genome* genome();
83  const Genome* genome() const;
88  virtual Evaluation* evaluationPrototype() = 0;
92  virtual QVector<Evaluation*> evaluationPool() = 0;
98  void setGeneration( unsigned int gen );
100  unsigned int generation() const;
102  void setNumGenerations( int g );
104  int numGenerations();
109  virtual void skipEvaluation() = 0;
114  QVector< QVector<double> > bestFits() const;
116  QVector< QVector<double> > averageFits() const;
118  QVector<double> meanHammingDist() const;
120  QVector<double> varianceHammingDist() const;
122  QVector<double> standardDeviationHammingDist() const;
123 
124 protected:
131  void updateStats();
132 
137 
146 
150  unsigned int generationv;
152  unsigned int numGens;
153 
155  QVector< QVector<double> > bestfits;
157  QVector< QVector<double> > avgfits;
159  QVector<double> meanHdists;
161  QVector<double> varHdists;
163  QVector<double> stdHdists;
164 };
165 
166 } // end namespace farsa
167 
168 #endif