00001 00020 #ifndef _INDIVIDUAL_H 00021 00022 #define _INDIVIDUAL_H 1 00023 00024 #include "real.h" 00025 #include "define.h" 00026 #include <map> 00027 #include <deque> 00028 #include <stdexcept> 00029 00030 using namespace std; 00031 00032 namespace realea { 00033 00034 class IndException: public runtime_error { 00035 private: 00036 string m_name; 00037 00038 public: 00039 IndException(string name) : runtime_error(name) { 00040 m_name = name; 00041 } 00042 00043 public: 00044 virtual ~IndException(void) throw () { } 00045 virtual const char *what(void) { 00046 return m_name.c_str(); 00047 } 00048 }; 00049 00050 00051 typedef pair<string, unsigned> tCounter; 00052 typedef deque< pair<string,unsigned> > tCounterList; 00053 00054 00055 00056 class tIndividualReal { 00057 00058 public: 00059 tIndividualReal (const tChromosomeReal &com); 00060 tIndividualReal (const tChromosomeReal &com, tFitness fitness); 00061 00062 00070 void change(const tChromosomeReal &sol, tFitness fitness); 00071 00076 const tChromosomeReal &sol(void) { 00077 return m_sol; 00078 } 00079 00084 tFitness perf(void); 00093 void incremCount(string ident); 00101 unsigned int getCount (string ident); 00105 bool isEval(void); 00106 00113 tFitness eval(IEval *funeval); 00114 00115 00122 tGen gen(unsigned pos); 00123 00127 bool isBetter(tIndividualReal *theother); 00128 00132 bool isWorse(tIndividualReal *theother); 00133 00137 static void setMinimize(void); 00141 static void setMaximize(void); 00142 00148 static bool isMinimize(void); 00149 00153 void setId(unsigned id); 00154 00155 unsigned getId(void); 00156 00160 virtual ~tIndividualReal(void); 00161 00165 static void sort(vector<tIndividualReal*> &individuals); 00166 00167 protected: 00168 tChromosomeReal m_sol; 00171 private: 00178 void setPerf(tFitness perf); 00179 00180 double m_id; 00182 tFitness m_perf; 00183 bool m_evaluated; 00184 deque< pair<string,unsigned> > pcounters; 00185 bool m_notid; 00186 }; 00187 00188 typedef tIndividualReal *tIndividualRealPtr; 00189 00193 class IEvalInd : public IEval { 00194 public: 00195 virtual unsigned eval(tIndividualReal *newind)=0; 00196 virtual tFitness eval(const tChromosomeReal &sol)=0; 00197 }; 00198 00199 00200 } 00201 #endif