00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 // "moNoFitImprSolContinue.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 __moNoFitImprSolContinue_h 00013 #define __moNoFitImprSolContinue_h 00014 00015 #include "moSolContinue.h" 00016 00018 00021 template < class EOT > class moNoFitImprSolContinue:public moSolContinue < EOT > 00022 { 00023 00024 public: 00025 00027 typedef typename EOT::Fitness Fitness; 00028 00030 00034 moNoFitImprSolContinue (unsigned int __maxNumberOfIterationWithoutImprovement, bool __maximization=true) 00035 : maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement),maximization(__maximization), 00036 firstFitnessSaved(true), counter(0) 00037 {} 00038 00040 00045 bool operator () (const EOT & __sol) 00046 { 00047 if(__sol.invalid()) 00048 { 00049 return true; 00050 } 00051 00052 if(firstFitnessSaved) 00053 { 00054 fitness=__sol.fitness(); 00055 counter=0; 00056 firstFitnessSaved=false; 00057 return true; 00058 } 00059 00060 counter++; 00061 00062 if( ((maximization) && (__sol.fitness() > fitness)) || 00063 ((!maximization) && (__sol.fitness() < fitness)) ) 00064 { 00065 fitness=__sol.fitness(); 00066 counter=0; 00067 } 00068 00069 if(counter==maxNumberOfIterationsWithoutImprovement) 00070 { 00071 std::cout << "moNoFitImrpSolContinue: Done [" << counter << "] iterations without improvement." << std::endl; 00072 } 00073 return counter!=maxNumberOfIterationsWithoutImprovement; 00074 } 00075 00077 void init () 00078 {} 00079 00080 private: 00081 00083 unsigned int maxNumberOfIterationsWithoutImprovement; 00084 00086 bool firstFitnessSaved; 00087 00089 Fitness fitness; 00090 00092 00096 bool maximization; 00097 00099 unsigned int counter; 00100 }; 00101 00102 #endif
1.5.2