00001 00002 /* 00003 Strategian Tien perusta kouluni näkökulmasta selitetään Maan 00004 kirjassa. On vaikeaa ymmärtää todellinen Tie vain miekkailun 00005 avulla. Tiedä pienimmät asiat ja suurimmat asiat, matalimmat asiat 00006 ja syvimmät asiat. Kuin se olisi suora tie kirjoitettuna maahan, 00007 ensimmäistä kirjaa kutsutaan Maan kirjaksi. 00008 */ 00009 00010 #ifndef __GAENVRNMNT_H__ 00011 #define __GAENVRNMNT_H__ 00012 00013 #include <magic/mobject.h> 00014 00015 using namespace MagiC; 00016 00019 /* 00020 template <class TYPE> 00021 class Ref : public Object { 00022 protected: 00023 TYPE* obj; 00024 public: 00025 Ref (TYPE* o) {obj = o;} 00026 Ref (Ref<TYPE>& o) {obj = o.obj; o.obj=NULL;} 00027 ~Ref () {delete obj;} 00028 operator = (TYPE* n) {delete obj; obj=n;} 00029 // operator const TYPE& () const {return *obj;} 00030 operator TYPE& () {return *obj;} 00031 TYPE* operator -> () {return obj;} 00032 TYPE* getptr () {return obj;} 00033 // TYPE* operator & () {return obj;} 00034 // const TYPE* operator & () const {return obj;} 00035 }; 00036 */ 00037 00038 // Externals 00039 class Genome; 00040 class Individual; 00041 00058 class EAEnvironment : public Object { 00059 decl_dynamic (EAEnvironment); 00060 public: 00061 00062 EAEnvironment (); 00063 00071 void setevals (int n) {mNEvals = n;} 00072 00076 int evals () const {return mNEvals;} 00077 00082 int total_evals () const {return mTotEvals;} 00083 00088 void addnoise (double stddev) {mNoise = stddev;} 00089 00090 double evaluate (const Individual& indiv); 00091 00095 void logDir (const String& dir) {mLogDir = dir;} 00096 00100 void cycleReport (OStream& log, OStream& out) {mCycles++; cycle_report(log,out);} 00101 00102 // Virtual methods 00103 00106 virtual void addFeaturesTo (Genome& genome) const {;} 00107 00110 virtual void init_cycle () {mBestFitness = 99999999.0; mpBest = NULL;} 00111 00113 virtual void check () const; 00114 00115 // Lowest non-subjective fitness; unlike the fitness returned by 00116 // the evaluate-method, this does NOT include the artificial noise 00117 // factor. 00118 double bestfitn; 00119 00120 protected: 00126 virtual double evaluateg (const Individual& ind) {MUST_OVERLOAD; return 0.0;} 00127 00130 virtual void cycle_report (OStream& log, OStream& out) {;} 00131 00134 int mNEvals; 00135 00138 int mTotEvals; 00139 00143 int mCycles; 00144 00149 double mNoise; 00150 00153 Individual* mpBest; 00154 00158 double mBestFitness; 00159 00162 String mLogDir; 00163 }; 00164 00165 #endif 00166