Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

gaenvrnmt.cc

Go to the documentation of this file.
00001 
00025 #include <ctype.h>
00026 #include <magic/mmath.h>
00027 #include <magic/mstream.h>
00028 #include <magic/mclass.h>
00029 
00030 #include "nhp/genetics.h"
00031 #include "nhp/individual.h"
00032 #include "nhp/gaenvrnmt.h"
00033 
00034 impl_abstract (EAEnvironment, {Object});
00035 
00036 
00037 
00039 //                                                                          //
00040 //    ----   _   -----             o                                        //
00041 //   |      / \  |       _                      _          ___    _    |    //
00042 //   | --- /   \ |---  |/ \  |   | | |/\  __  |/ \  |/|/| /   ) |/ \  -+-   //
00043 //   |   \ |---| |     |   |  \ /  | |   /  \ |   | | | | |---  |   |  |    //
00044 //   |___/ |   | |____ |   |   V   | |   \__/ |   | | | |  \__  |   |   \   //
00045 //                                                                          //
00047 
00048 EAEnvironment::EAEnvironment ()
00049 {
00050     mNEvals         = 1;
00051     mNoise          = 0.0;
00052     bestfitn        = 1E+30;
00053     mBestFitness    = 1E+30;
00054     mTotEvals       = 0;
00055     mpBest          = NULL;
00056     mCycles         = 0;
00057 }
00058 
00069 double EAEnvironment::evaluate (const Individual& ind)
00070 {
00071     // Evaluate the fitness
00072     double fitness = evaluateg (ind);
00073 
00074     // Record the best _objective_ fitness. Note that this is done
00075     // before adding the artificial noise, so this is really the true
00076     // fitness.
00077     if (fitness < bestfitn)
00078         bestfitn = fitness;
00079 
00080     // Add some artificial noise. The if statement is here because we don't
00081     // want to compate to 0.0.
00082     if (mNoise > 0.0001)
00083         fitness += gaussrnd (mNoise);
00084 
00085     // Record the best _subjective_ fitness
00086     if (fitness < mBestFitness) {
00087         mBestFitness = fitness;
00088         mpBest       = const_cast <Individual*> (&ind);
00089     }
00090 
00091     mTotEvals++;
00092 
00093     return fitness;
00094 }
00095 
00096 void EAEnvironment::check () const
00097 {
00098     ASSERT (mNEvals>=1 && mNEvals<100000);
00099     ASSERT (mTotEvals>=0 && mTotEvals<1000000);
00100     ASSERT (mCycles>=0 && mCycles<100000);
00101     ASSERT (mNoise>=0.0 && mNoise<10000.0);
00102 }
00103 

Generated on Thu Feb 10 20:12:00 2005 for NeHeP by doxygen1.2.18