ga/include/core/geneticalgo.h

00001 /********************************************************************************
00002  *  FARSA Genetic Algorithm Library                                             *
00003  *  Copyright (C) 2007-2009 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef GENETICALGO_H
00021 #define GENETICALGO_H
00022 
00023 #include "gaconfig.h"
00024 #include "parametersettable.h"
00025 #include <QVector>
00026 
00027 namespace farsa {
00028 
00029 class Genotype;
00030 class Genome;
00031 class Evaluation;
00032 
00046 class FARSA_GA_API GeneticAlgo : public ParameterSettableWithConfigureFunction {
00047 public:
00049     GeneticAlgo( );
00051     virtual ~GeneticAlgo();
00056     virtual void initialize() = 0;
00061     virtual void gaStep() = 0;
00066     virtual void finalize() = 0;
00071     void evolve( unsigned int generationToReach );
00075     void evolve();
00077     bool isEvolutionEnded();
00079     bool isEvaluationDone();
00081     void setGenome( Genome* gen );
00083     Genome* genome();
00085     const Genome* genome() const;
00090     virtual Evaluation* evaluationPrototype() = 0;
00094     virtual QVector<Evaluation*> evaluationPool() = 0;
00100     void setGeneration( unsigned int gen );
00102     unsigned int generation() const;
00104     void setNumGenerations( int g );
00106     int numGenerations();
00111     virtual void skipEvaluation() = 0;
00116     QVector< QVector<double> > bestFits() const;
00118     QVector< QVector<double> > averageFits() const;
00120     QVector<double> meanHammingDist() const;
00122     QVector<double> varianceHammingDist() const;
00124     QVector<double> standardDeviationHammingDist() const;
00125 
00126 protected:
00133     void updateStats();
00134 
00138     bool evolutionEnd;
00139 
00147     bool evaluationDone;
00148 
00150     Genome* genomev;
00152     unsigned int generationv;
00154     unsigned int numGens;
00155 
00157     QVector< QVector<double> > bestfits;
00159     QVector< QVector<double> > avgfits;
00161     QVector<double> meanHdists;
00163     QVector<double> varHdists;
00165     QVector<double> stdHdists;
00166 };
00167 
00168 } // end namespace farsa
00169 
00170 #endif