EvolvingObjects
|
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 //----------------------------------------------------------------------------- 00004 // eoGenContinue.h 00005 // (c) GeNeura Team, 1999 00006 /* 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Contact: todos@geneura.ugr.es, http://geneura.ugr.es 00022 */ 00023 //----------------------------------------------------------------------------- 00024 00025 #ifndef _eoGenContinue_h 00026 #define _eoGenContinue_h 00027 00028 #include <eoContinue.h> 00029 #include <utils/eoParam.h> 00030 #include <utils/eoLogger.h> 00031 00037 template< class EOT> 00038 class eoGenContinue: public eoContinue<EOT>, public eoValueParam<unsigned> 00039 { 00040 public: 00041 00043 eoGenContinue( unsigned long _totalGens) 00044 : eoValueParam<unsigned>(0, "Generations", "Generations"), 00045 repTotalGenerations( _totalGens ), 00046 thisGenerationPlaceHolder(0), 00047 thisGeneration(thisGenerationPlaceHolder) 00048 {}; 00049 00051 eoGenContinue( unsigned long _totalGens, unsigned long& _currentGen) 00052 : eoValueParam<unsigned>(0, "Generations", "Generations"), 00053 repTotalGenerations( _totalGens ), 00054 thisGenerationPlaceHolder(0), 00055 thisGeneration(_currentGen) 00056 {}; 00057 00060 virtual bool operator() ( const eoPop<EOT>& _vEO ) { 00061 (void)_vEO; 00062 thisGeneration++; 00063 value() = thisGeneration; 00064 00065 if (thisGeneration >= repTotalGenerations) 00066 { 00067 eo::log << eo::logging << "STOP in eoGenContinue: Reached maximum number of generations [" << thisGeneration << "/" << repTotalGenerations << "]\n"; 00068 return false; 00069 } 00070 return true; 00071 } 00072 00078 virtual void totalGenerations( unsigned long _tg ) { 00079 repTotalGenerations = _tg; 00080 thisGeneration = 0; 00081 }; 00082 00084 virtual unsigned long totalGenerations( ) 00085 { 00086 return repTotalGenerations; 00087 }; 00088 00089 00090 virtual std::string className(void) const { return "eoGenContinue"; } 00091 00095 void readFrom (std :: istream & __is) { 00096 00097 __is >> thisGeneration; /* Loading the number of generations counted */ 00098 } 00099 00103 void printOn (std :: ostream & __os) const { 00104 00105 __os << thisGeneration << std :: endl; /* Saving the number of generations counted */ 00106 } 00107 00108 private: 00109 unsigned long repTotalGenerations; 00110 unsigned long thisGenerationPlaceHolder; 00111 unsigned long& thisGeneration; 00112 }; 00113 00114 #endif