00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _eoSteadyFitContinue_h
00026 #define _eoSteadyFitContinue_h
00027
00028 #include <eoContinue.h>
00029
00034 template< class EOT>
00035 class eoSteadyFitContinue: public eoContinue<EOT>
00036 {
00037 public:
00038 typedef typename EOT::Fitness Fitness;
00039
00041 eoSteadyFitContinue( unsigned long _minGens, unsigned long _steadyGens)
00042 : repMinGenerations( _minGens ), repSteadyGenerations( _steadyGens),
00043 steadyState(false), thisGenerationPlaceHolder(0),
00044 thisGeneration(thisGenerationPlaceHolder){};
00045
00047 eoSteadyFitContinue( unsigned long _minGens, unsigned long _steadyGen,
00048 unsigned long& _currentGen)
00049 : repMinGenerations( _minGens ), repSteadyGenerations( _steadyGen),
00050 steadyState(_currentGen>_minGens), thisGenerationPlaceHolder(0),
00051 thisGeneration(_currentGen){};
00052
00055 virtual bool operator() ( const eoPop<EOT>& _vEO ) {
00056 thisGeneration++;
00057
00058 Fitness bestCurrentFitness = _vEO.nth_element_fitness(0);
00059
00060 if (steadyState) {
00061 if (bestCurrentFitness > bestSoFar) {
00062 bestSoFar = bestCurrentFitness;
00063 lastImprovement = thisGeneration;
00064 } else {
00065 if (thisGeneration - lastImprovement > repSteadyGenerations) {
00066 std::cout << "STOP in eoSteadyFitContinue: Done " << repSteadyGenerations
00067 << " generations without improvement\n";
00068 return false;
00069 }
00070 }
00071 } else {
00072 if (thisGeneration > repMinGenerations) {
00073 steadyState = true;
00074 bestSoFar = bestCurrentFitness;
00075 lastImprovement = thisGeneration;
00076 std::cout << "eoSteadyFitContinue: Done the minimum number of generations\n";
00077 }
00078 }
00079 return true;
00080 }
00081
00084 virtual void totalGenerations( unsigned long _mg, unsigned long _sg ) {
00085 repMinGenerations = _mg;
00086 repSteadyGenerations = _sg;
00087 reset();
00088 };
00089
00091 virtual void reset () {
00092 steadyState=false;
00093 thisGeneration = 0;
00094 }
00095
00097 virtual unsigned long minGenerations( )
00098 { return repMinGenerations; };
00099 virtual unsigned long steadyGenerations( )
00100 { return repSteadyGenerations; };
00101
00102 virtual std::string className(void) const { return "eoSteadyFitContinue"; }
00103 private:
00104 unsigned long repMinGenerations;
00105 unsigned long repSteadyGenerations;
00106 bool steadyState;
00107 unsigned long thisGenerationPlaceHolder;
00108 unsigned long& thisGeneration;
00109 unsigned int lastImprovement;
00110 Fitness bestSoFar;
00111 };
00112
00113 #endif
00114