eoGenContinue.h

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>
00033 template< class EOT>
00034 class eoGenContinue: public eoContinue<EOT>, public eoValueParam<unsigned>
00035 {
00036 public:
00037 
00039   eoGenContinue( unsigned long _totalGens)
00040           : eoValueParam<unsigned>(0, "Generations", "Generations"),
00041             repTotalGenerations( _totalGens ), 
00042             thisGenerationPlaceHolder(0),
00043             thisGeneration(thisGenerationPlaceHolder), verbose(true) {};
00044   
00046   eoGenContinue( unsigned long _totalGens, unsigned long& _currentGen)
00047           : eoValueParam<unsigned>(0, "Generations", "Generations"),
00048             repTotalGenerations( _totalGens ), 
00049             thisGenerationPlaceHolder(0),
00050             thisGeneration(_currentGen), verbose(true){};
00051   
00054   virtual bool operator() ( const eoPop<EOT>& _vEO ) {
00055     thisGeneration++;
00056     value() = thisGeneration;
00057     //    std::cout << " [" << thisGeneration << "] ";
00058     if (thisGeneration >= repTotalGenerations) 
00059       {
00060           if (verbose)
00061             std::cout << "STOP in eoGenContinue: Reached maximum number of generations [" << thisGeneration << "/" << repTotalGenerations << "]\n";
00062         return false;
00063       }
00064     return true;
00065   }
00066   
00069   virtual void totalGenerations( unsigned long _tg ) { 
00070           repTotalGenerations = _tg; 
00071           thisGeneration = 0;
00072         };
00073   
00075   virtual unsigned long totalGenerations( ) 
00076   {  
00077     return repTotalGenerations; 
00078   };
00079     
00080   
00081   virtual std::string className(void) const { return "eoGenContinue"; }
00082 
00083   void readFrom (std :: istream & __is) {
00084     
00085     __is >> thisGeneration; /* Loading the number of generations counted */
00086   }
00087   
00088   void printOn (std :: ostream & __os) const {
00089     
00090     __os << thisGeneration << std :: endl; /* Saving the number of generations counted */   
00091   }
00092 
00093 private:
00094   unsigned long repTotalGenerations;
00095   unsigned long thisGenerationPlaceHolder;
00096   unsigned long& thisGeneration;
00097   
00098 public:
00099   bool verbose; // allows to turn off annoying message to cout
00100 };
00101 
00102 #endif
00103 

Generated on Thu Oct 19 05:06:35 2006 for EO by  doxygen 1.3.9.1