From 388358bc5c35f0ab3d7c9c22a729a07e8819f1ca Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Wed, 18 Jul 2012 11:43:59 +0200 Subject: [PATCH] get rid of the useless temporary members and directly delete the adress of the referenced distrib --- edo/src/edoAlgoStateless.h | 53 +++++++++++++------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/edo/src/edoAlgoStateless.h b/edo/src/edoAlgoStateless.h index c2d4834d6..45bcea06f 100644 --- a/edo/src/edoAlgoStateless.h +++ b/edo/src/edoAlgoStateless.h @@ -30,9 +30,11 @@ Authors: #include "edoAlgoAdaptive.h" -//! edoEDA< D > - -/** A generic stochastic search template for algorithms that need a distribution parameter. +/** A generic stochastic search template for algorithms that need a distribution parameter but replace it rather than update it + * + * 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 > class edoAlgoStateless : public edoAlgoAdaptive< EOD > @@ -49,10 +51,7 @@ public: public: - - /*! - Without a distribution - + /** Full constructor \param evaluation Evaluate a population \param selector Selection of the best candidate solutions in the population \param estimator Estimation of the distribution parameters @@ -60,6 +59,8 @@ public: \param replacor Replace old solutions by new ones \param pop_continuator Stopping criterion based on the population 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( eoPopEvalFunc < EOType > & evaluator, @@ -71,21 +72,19 @@ public: edoContinue< EOD > & distribution_continuator, EOD* tmp_distrib = (new EOD()) ) : - edoAlgoAdaptive( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator, distribution_continuator), - _tmp_distrib( tmp_distrib ), - _dummy_distrib() - { - this->_distrib = _dummy_distrib; - } + edoAlgoAdaptive( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator, distribution_continuator) + {} + + /** Constructor without an edoContinue - //! constructor without an edoContinue nor a distribution - /*! \param evaluation Evaluate a population \param selector Selection of the best candidate solutions in the population \param estimator Estimation of the distribution parameters \param sampler Generate feasible solutions using the distribution \param replacor Replace old solutions by new ones \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 ( eoPopEvalFunc < EOType > & evaluator, @@ -96,30 +95,14 @@ public: eoContinue< EOType > & pop_continuator, EOD* tmp_distrib = (new EOD()) ) : - edoAlgoAdaptive( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator), - _tmp_distrib( tmp_distrib ), - _dummy_distrib() - { - this->_distrib = _dummy_distrib; - } + edoAlgoAdaptive( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator) + {} ~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