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

View file

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

View file

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