00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SIMPLEGA_H
00021 #define SIMPLEGA_H
00022
00023 #include "gaconfig.h"
00024 #include "core/geneticalgo.h"
00025 #include <QList>
00026
00027 namespace farsa {
00028
00029 class Evaluation;
00030 class Reproduction;
00031
00043 class FARSA_GA_API SimpleGA : public GeneticAlgo {
00044 public:
00046 SimpleGA();
00048 virtual ~SimpleGA();
00052 void setNumThreads( int numThreads );
00054 int numThreads();
00056 void setEvaluation( Evaluation* fitfunc );
00061 virtual Evaluation* evaluationPrototype();
00063 virtual QVector<Evaluation*> evaluationPool();
00065 void setReproduction( Reproduction* reproduct );
00067 Reproduction* reproduction();
00070 virtual void initialize();
00072 virtual void gaStep();
00074 virtual void finalize();
00075
00080 virtual void skipEvaluation();
00081
00089 virtual void configure( ConfigurationParameters& params, QString prefix );
00096 virtual void save( ConfigurationParameters& params, QString prefix );
00098 static void describe( QString type );
00099
00100 protected:
00102 Evaluation* fitfunc;
00104 Reproduction* reprod;
00106 typedef enum { initEvaluation, evaluating, nextGeneration_pass1, nextGeneration_pass2, endEvolution } GAPhases;
00108 GAPhases currPhase;
00110 bool isInitialized;
00112 bool isFinalized;
00113
00114 private:
00116 bool nextGeneration;
00117
00122 class evaluationThread {
00123 public:
00124
00125 evaluationThread( SimpleGA* p, Evaluation* eProto );
00126
00127 ~evaluationThread();
00128
00129 SimpleGA* parent;
00130
00131 Evaluation* eval;
00132
00133 int id;
00134
00135 bool blocked;
00136
00137 void runStep();
00138
00139 QVector<int> sequence;
00140
00141 int idSeq;
00142 };
00143
00145 QList<evaluationThread*> evalThreads;
00147 int numThreadv;
00149 static void runStepWrapper( SimpleGA::evaluationThread* e );
00150 };
00151
00152 }
00153
00154 #endif