eoGenContinue and eoSteadyFitContinue now inherits from a common class eoCountContinue, which contains a overridable method reset.

This commit is contained in:
Benjamin Bouvier 2012-07-26 15:12:54 +02:00
commit a14526e01a
3 changed files with 60 additions and 23 deletions

View file

@ -67,4 +67,43 @@ public:
} }
}; };
/**
* Termination condition with a count condition (totalGenerations). This continuator contains
* a count of cycles, which can be retrieved or set.
*
* @ingroup Continuators
* @ingroup Core
*/
template< class EOT >
class eoCountContinue : public eoContinue< EOT >
{
public:
eoCountContinue( ) :
thisGenerationPlaceholder( 0 ),
thisGeneration( thisGenerationPlaceholder )
{
// empty
}
eoCountContinue( unsigned long& currentGen ) :
thisGenerationPlaceholder( 0 ),
thisGeneration( currentGen )
{
// empty
}
virtual std::string className( void ) const { return "eoCountContinue"; }
virtual void reset( )
{
thisGeneration = 0;
}
protected:
unsigned long thisGenerationPlaceholder;
unsigned long& thisGeneration;
};
#endif #endif

View file

@ -35,24 +35,24 @@
@ingroup Continuators @ingroup Continuators
*/ */
template< class EOT> template< class EOT>
class eoGenContinue: public eoContinue<EOT>, public eoValueParam<unsigned> class eoGenContinue: public eoCountContinue<EOT>, public eoValueParam<unsigned>
{ {
public: public:
using eoCountContinue<EOT>::thisGeneration;
using eoCountContinue<EOT>::thisGenerationPlaceholder;
/// Ctor for setting a /// Ctor for setting a
eoGenContinue( unsigned long _totalGens) eoGenContinue( unsigned long _totalGens)
: eoValueParam<unsigned>(0, "Generations", "Generations"), : eoCountContinue<EOT>( ),
repTotalGenerations( _totalGens ), eoValueParam<unsigned>(0, "Generations", "Generations"),
thisGenerationPlaceHolder(0), repTotalGenerations( _totalGens )
thisGeneration(thisGenerationPlaceHolder)
{}; {};
/// Ctor for enabling the save/load the no. of generations counted /// Ctor for enabling the save/load the no. of generations counted
eoGenContinue( unsigned long _totalGens, unsigned long& _currentGen) eoGenContinue( unsigned long _totalGens, unsigned long& _currentGen)
: eoValueParam<unsigned>(0, "Generations", "Generations"), : eoCountContinue<EOT>( _currentGen ), eoValueParam<unsigned>(0, "Generations", "Generations"),
repTotalGenerations( _totalGens ), repTotalGenerations( _totalGens )
thisGenerationPlaceHolder(0),
thisGeneration(_currentGen)
{}; {};
/** Returns false when a certain number of generations is /** Returns false when a certain number of generations is
@ -77,7 +77,7 @@ public:
*/ */
virtual void totalGenerations( unsigned long _tg ) { virtual void totalGenerations( unsigned long _tg ) {
repTotalGenerations = _tg; repTotalGenerations = _tg;
thisGeneration = 0; eoCountContinue<EOT>::reset();
}; };
/** Returns the number of generations to reach*/ /** Returns the number of generations to reach*/
@ -86,7 +86,6 @@ public:
return repTotalGenerations; return repTotalGenerations;
}; };
virtual std::string className(void) const { return "eoGenContinue"; } virtual std::string className(void) const { return "eoGenContinue"; }
/** Read from a stream /** Read from a stream
@ -107,8 +106,6 @@ public:
private: private:
unsigned long repTotalGenerations; unsigned long repTotalGenerations;
unsigned long thisGenerationPlaceHolder;
unsigned long& thisGeneration;
}; };
#endif #endif

View file

@ -35,23 +35,26 @@
@ingroup Continuators @ingroup Continuators
*/ */
template< class EOT> template< class EOT>
class eoSteadyFitContinue: public eoContinue<EOT> class eoSteadyFitContinue: public eoCountContinue<EOT>
{ {
public: public:
typedef typename EOT::Fitness Fitness; typedef typename EOT::Fitness Fitness;
using eoCountContinue<EOT>::thisGenerationPlaceholder;
using eoCountContinue<EOT>::thisGeneration;
/// Ctor for setting a /// Ctor for setting a
eoSteadyFitContinue( unsigned long _minGens, unsigned long _steadyGens) eoSteadyFitContinue( unsigned long _minGens, unsigned long _steadyGens)
: repMinGenerations( _minGens ), repSteadyGenerations( _steadyGens), : eoCountContinue<EOT>( ), repMinGenerations( _minGens ), repSteadyGenerations( _steadyGens),
steadyState(false), thisGenerationPlaceHolder(0), steadyState(false)
thisGeneration(thisGenerationPlaceHolder){}; {};
/// Ctor for enabling the save/load the no. of generations counted /// Ctor for enabling the save/load the no. of generations counted
eoSteadyFitContinue( unsigned long _minGens, unsigned long _steadyGen, eoSteadyFitContinue( unsigned long _minGens, unsigned long _steadyGen,
unsigned long& _currentGen) unsigned long& _currentGen)
: repMinGenerations( _minGens ), repSteadyGenerations( _steadyGen), : eoCountContinue<EOT>( _currentGen ), repMinGenerations( _minGens ), repSteadyGenerations( _steadyGen),
steadyState(_currentGen>_minGens), thisGenerationPlaceHolder(0), steadyState(_currentGen>_minGens)
thisGeneration(_currentGen){}; {};
/** Returns false when a certain number of generations is /** Returns false when a certain number of generations is
* reached withtout improvement */ * reached withtout improvement */
@ -96,7 +99,7 @@ public:
/// Resets the state after it's been reached /// Resets the state after it's been reached
virtual void reset () { virtual void reset () {
steadyState=false; steadyState=false;
thisGeneration = 0; eoCountContinue<EOT>::reset();
} }
/** accessors*/ /** accessors*/
@ -110,8 +113,6 @@ private:
unsigned long repMinGenerations; unsigned long repMinGenerations;
unsigned long repSteadyGenerations; unsigned long repSteadyGenerations;
bool steadyState; bool steadyState;
unsigned long thisGenerationPlaceHolder;
unsigned long& thisGeneration;
unsigned int lastImprovement; unsigned int lastImprovement;
Fitness bestSoFar; Fitness bestSoFar;
}; };