00001
00020 #ifndef _POPULATION_H
00021
00022 #define _POPULATION_H 1
00023
00024 #include "individual.h"
00025 #include "domain.h"
00026 #include "initind.h"
00027 #include "random.h"
00028 #include "define.h"
00029 #include "popobserver.h"
00030 #include <deque>
00031
00032 using namespace std;
00033
00034 namespace realea {
00035
00044 class PopulationReal {
00045 public:
00052 PopulationReal(Random *random, unsigned int max, unsigned int pob);
00053 virtual ~PopulationReal(void);
00061 virtual void reset(DomainRealPtr domain, int init=-1);
00062
00066 void removeWorses(void);
00067
00071 void random(void);
00072
00076 void sort(void);
00077
00082 tIndividualReal *getInd(unsigned int pos);
00083
00090 void replace(int pos, const tIndividualReal *ind);
00091
00097 void append(tIndividualReal *ind);
00098 void append(tChromosomeReal &sol, tFitness fitness);
00102 void change(unsigned int pos, const tChromosomeReal &sol, tFitness fitness);
00103
00108 void replace(unsigned pos, tIndividualRealPtr newind);
00109
00114 unsigned getBest(void);
00115
00119 tFitness getMedian(void);
00123 tFitness getMean(void);
00128 void getPercentils(double *percen, unsigned num);
00136 vector<unsigned> getBests(unsigned num);
00137
00141 unsigned getWorst(void);
00145 unsigned size(void);
00149 unsigned ndim(void);
00156 void eval(IEvalInd *fitness, unsigned newevals=-1);
00157
00161 void setObserver(PopulationObserver *observer);
00162
00166 virtual tIndividualReal* getInstance(tChromosomeReal &crom, tFitness fitness);
00167
00171 virtual tIndividualReal* getInstance(tChromosomeReal &crom);
00172
00173
00174 private:
00180 void updateObservers(void);
00181
00187 void resetObservers(void);
00188
00192 bool thereNull(void);
00193
00200 void remove(unsigned begin, unsigned end);
00204 void removePending(void);
00205
00206
00207
00208 unsigned int m_aditionalsize,
00209 m_size;
00210 vector<tIndividualReal*> m_individuals;
00212 unsigned m_best;
00213 unsigned m_worst;
00214
00215
00216 bool m_knownbest;
00217 bool m_knownworst;
00218 InitIndividual *m_initInd;
00219 deque<PopulationObserver *>m_observers;
00221 protected:
00227 void notifyObservers(unsigned id);
00228
00229
00230 Random *m_random;
00231 };
00232
00233 typedef PopulationReal* PopulationRealPtr;
00234
00235 }
00236
00237 #endif