00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 // "moSteadyFitSolContinue.h" 00004 00005 // (c) OPAC Team (LIFL), Dolphin project (INRIA), 2003-2007 00006 00007 /* LICENCE TEXT 00008 00009 Contact: paradiseo-help@lists.gforge.inria.fr 00010 */ 00011 00012 #ifndef __moSteadyFitSolContinue_h 00013 #define __moSteadyFitSolContinue_h 00014 00015 #include "moSolContinue.h" 00016 00018 00021 template < class EOT > class moSteadyFitSolContinue:public moSolContinue < EOT > 00022 { 00023 00024 public: 00025 00027 typedef typename EOT::Fitness Fitness; 00028 00030 00035 moSteadyFitSolContinue (unsigned int __maxNumberOfIterations, unsigned int __maxNumberOfIterationWithoutImprovement, bool __maximization=true) 00036 : maxNumberOfIterations (__maxNumberOfIterations), maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement), 00037 maximization(__maximization), maxNumberOfIterationsReached(false), firstFitnessSaved(true), counter(0) 00038 {} 00039 00041 00047 bool operator () (const EOT & __sol) 00048 { 00049 if(!maxNumberOfIterationsReached) 00050 { 00051 maxNumberOfIterationsReached=((++counter)==maxNumberOfIterations); 00052 if(maxNumberOfIterationsReached) 00053 { 00054 std::cout << "moSteadyFitSolContinue: Done the minimum number of iterations [" << counter << "]." << std::endl; 00055 } 00056 return true; 00057 } 00058 00059 if(__sol.invalid()) 00060 { 00061 return true; 00062 } 00063 00064 if(firstFitnessSaved) 00065 { 00066 fitness=__sol.fitness(); 00067 counter=0; 00068 firstFitnessSaved=false; 00069 return true; 00070 } 00071 00072 counter++; 00073 00074 if( ((maximization) && (__sol.fitness() > fitness)) || 00075 ((!maximization) && (__sol.fitness() < fitness)) ) 00076 { 00077 fitness=__sol.fitness(); 00078 counter=0; 00079 } 00080 00081 if(counter==maxNumberOfIterationsWithoutImprovement) 00082 { 00083 std::cout << "moSteadyFitSolContinue: Done [" << counter << "] iterations without improvement." << std::endl; 00084 } 00085 return counter!=maxNumberOfIterationsWithoutImprovement; 00086 } 00087 00089 void init () 00090 {} 00091 00092 private: 00093 00095 unsigned int maxNumberOfIterations; 00096 00098 unsigned int maxNumberOfIterationsWithoutImprovement; 00099 00101 bool maxNumberOfIterationsReached; 00102 00104 bool firstFitnessSaved; 00105 00107 Fitness fitness; 00108 00110 00114 bool maximization; 00115 00117 unsigned int counter; 00118 }; 00119 00120 #endif
1.5.2