00001 #ifndef SIGEL_GP_SIG_GPPOPULATION_H 00002 #define SIGEL_GP_SIG_GPPOPULATION_H 00003 00004 #include "SIGEL_GP/SIG_GPIndividual.h" 00005 #include "SIGEL_Tools/SIG_Randomizer.h" 00006 #include"../SIGEL_GP/SIG_GPParameter.h" 00007 #include"SIGEL_Robot/SIG_LanguageParameters.h" 00008 00009 00010 #include <qstring.h> 00011 #include <qvector.h> 00012 #include <qtextstream.h> 00013 #include <qprogressdialog.h> 00014 00015 namespace SIGEL_GP 00016 { 00026 class SIG_GPPopulation 00027 { 00028 00033 private: 00034 QVector<SIG_GPIndividual> pool; 00035 00041 private: 00042 SIGEL_Tools::SIG_Randomizer *randomizer; 00043 00050 public: 00051 QString nextIdentifier; 00052 00060 public: 00061 int poolGeneration; 00062 00072 public: 00073 SIG_GPPopulation(); 00074 00075 00089 public: 00090 SIG_GPPopulation(int size); 00091 00104 public: 00105 SIG_GPPopulation(int size, 00106 SIGEL_Tools::SIG_Randomizer &r, 00107 SIGEL_GP::SIG_GPParameter& param, 00108 SIGEL_Robot::SIG_LanguageParameters& languageP); 00109 00120 public: 00121 SIG_GPPopulation(QString data); 00122 00131 public: 00132 ~SIG_GPPopulation(); 00133 00142 public: 00143 void sort(); 00144 00155 public: 00156 SIG_GPIndividual& getIndividual(int poolpos); 00157 00171 public: 00172 void setIndividual(SIG_GPIndividual& indi, int poolpos); 00173 00174 00175 00182 public: 00183 int getSize(); 00184 00196 public: 00197 QString getNextIdentifier(); 00198 00210 public: 00211 void setNextIdentifier(QString identifier); 00212 00219 public: 00220 int getPoolGeneration(); 00221 00230 public: 00231 void loadPool(QTextStream & pool); 00232 00241 public: 00242 void savePool(QTextStream & pool); 00243 00252 public: 00253 SIG_GPPopulation(int size, SIGEL_Tools::SIG_Randomizer &r); 00254 00262 public: 00263 SIGEL_GP::SIG_GPIndividual *getIndividualPointer(int poolpos); 00264 00272 public: 00273 void deleteIndividual(int poolpos); 00274 00281 public: 00282 void setPoolGeneration(int pGen); 00283 00290 public: 00291 void setRandomizer(SIGEL_Tools::SIG_Randomizer *r); 00292 00300 public: 00301 SIGEL_Tools::SIG_Randomizer getRandomizer(); 00302 00307 public: 00308 SIGEL_Tools::SIG_Randomizer *getRandomizerPointer(); 00309 00319 public: 00320 void readFromFile(QTextStream &file); 00321 00322 00337 public: 00338 void writeToFile(QTextStream &file); 00339 00354 public: 00355 void addRandomIndividuals(int quantity, 00356 SIGEL_GP::SIG_GPParameter& param, 00357 SIGEL_Robot::SIG_LanguageParameters& languageP); 00358 00365 public: 00366 double getBestFitness(bool high); 00367 00368 public: 00369 double getWorstFitness(bool high); 00370 00371 public: 00372 double getAverageFitness(); 00373 00374 public: 00375 void resetPool(); 00376 00382 public: 00383 void importNewIndividual( QString& filename ); 00384 }; 00385 } 00386 #endif // SIGEL_GP_SIG_GPPOPULATION_H 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396