get rid of the useless temporary members and directly delete the adress of the referenced distrib

This commit is contained in:
Johann Dreo 2012-07-18 11:43:59 +02:00
commit 388358bc5c

View file

@ -30,9 +30,11 @@ Authors:
#include "edoAlgoAdaptive.h" #include "edoAlgoAdaptive.h"
//! edoEDA< D > /** A generic stochastic search template for algorithms that need a distribution parameter but replace it rather than update it
*
/** A generic stochastic search template for algorithms that need a distribution parameter. * This use a default dummy distribution, for algorithms willing to replace it instead of updating
* Thus we can instanciate _distrib on this and replace it at the first iteration with an estimator.
* This is why an edoDistrib must have an empty constructor.
*/ */
template < typename EOD > template < typename EOD >
class edoAlgoStateless : public edoAlgoAdaptive< EOD > class edoAlgoStateless : public edoAlgoAdaptive< EOD >
@ -49,10 +51,7 @@ public:
public: public:
/** Full constructor
/*!
Without a distribution
\param evaluation Evaluate a population \param evaluation Evaluate a population
\param selector Selection of the best candidate solutions in the population \param selector Selection of the best candidate solutions in the population
\param estimator Estimation of the distribution parameters \param estimator Estimation of the distribution parameters
@ -60,6 +59,8 @@ public:
\param replacor Replace old solutions by new ones \param replacor Replace old solutions by new ones
\param pop_continuator Stopping criterion based on the population features \param pop_continuator Stopping criterion based on the population features
\param distribution_continuator Stopping criterion based on the distribution features \param distribution_continuator Stopping criterion based on the distribution features
You are not supposed to override the tmp_distrib default initalization, or else use edoAlgoAdaptive
*/ */
edoAlgoStateless( edoAlgoStateless(
eoPopEvalFunc < EOType > & evaluator, eoPopEvalFunc < EOType > & evaluator,
@ -71,21 +72,19 @@ public:
edoContinue< EOD > & distribution_continuator, edoContinue< EOD > & distribution_continuator,
EOD* tmp_distrib = (new EOD()) EOD* tmp_distrib = (new EOD())
) : ) :
edoAlgoAdaptive<EOD>( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator, distribution_continuator), edoAlgoAdaptive<EOD>( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator, distribution_continuator)
_tmp_distrib( tmp_distrib ), {}
_dummy_distrib()
{ /** Constructor without an edoContinue
this->_distrib = _dummy_distrib;
}
//! constructor without an edoContinue nor a distribution
/*!
\param evaluation Evaluate a population \param evaluation Evaluate a population
\param selector Selection of the best candidate solutions in the population \param selector Selection of the best candidate solutions in the population
\param estimator Estimation of the distribution parameters \param estimator Estimation of the distribution parameters
\param sampler Generate feasible solutions using the distribution \param sampler Generate feasible solutions using the distribution
\param replacor Replace old solutions by new ones \param replacor Replace old solutions by new ones
\param pop_continuator Stopping criterion based on the population features \param pop_continuator Stopping criterion based on the population features
You are not supposed to override the tmp_distrib default initalization, or else use edoAlgoAdaptive
*/ */
edoAlgoStateless ( edoAlgoStateless (
eoPopEvalFunc < EOType > & evaluator, eoPopEvalFunc < EOType > & evaluator,
@ -96,30 +95,14 @@ public:
eoContinue< EOType > & pop_continuator, eoContinue< EOType > & pop_continuator,
EOD* tmp_distrib = (new EOD()) EOD* tmp_distrib = (new EOD())
) : ) :
edoAlgoAdaptive<EOD>( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator), edoAlgoAdaptive<EOD>( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator)
_tmp_distrib( tmp_distrib ), {}
_dummy_distrib()
{
this->_distrib = _dummy_distrib;
}
~edoAlgoStateless() ~edoAlgoStateless()
{ {
delete _tmp_distrib; // delete the temporary distrib allocated in constructors
delete &(this->_distrib);
} }
protected:
EOD* _tmp_distrib;
/** A dummy distribution, for algorithms willing to replace it instead of updating
*
* Thus we can instanciate _distrib on this and replace it at the first iteration with an estimator.
* This is why an edoDistrib must have an empty constructor.
*/
EOD _dummy_distrib;
}; };
#endif // !_edoAlgoStateless_h #endif // !_edoAlgoStateless_h