#ifndef __moStdDevEstimator_h__ #define __moStdDevEstimator_h__ #include #include #include // TODO rm #include // TODO rm // TODO make tests template< class EOT, class Neighbor > class moStdDevEstimator : public eoUF { public: /** * General constructor for the estimator * @param continuator a user-defined continuator * @param neighborhood the neighborhood * @param fullEval the full evaluation function * @param eval neighbor's evaluation function * @param walker a local search algorithm */ moStdDevEstimator ( moContinuator& continuator, moNeighborhood < Neighbor > & neighborhood, eoEvalFunc& fullEval, /* The following should be read: moEval& eval = _default_eval * (which is not possible to achieve as is in C++) */ const eoOptional< moEval >& eval = eoOptional< moEval >::null, const eoOptional< moLocalSearch >& walker = eoOptional< moLocalSearch >::null ) : _default_eval ( fullEval ), _eval(eval.hasValue()? eval.get(): _default_eval), _default_continuator( 0 ), _continuator( _continuator ), _checkpoint( _continuator ), _default_walker( neighborhood, fullEval, _eval, _checkpoint ), _walker( walker.hasValue()? walker.get(): _default_walker ) { _checkpoint.add( _varStat ); } /** * Simpler constructor for the estimator * @param max_iters the number of steps the default moIterContinuator should perform * @param neighborhood the neighborhood * @param fullEval the full evaluation function * @param eval neighbor's evaluation function * @param walker a local search algorithm */ moStdDevEstimator ( unsigned int max_iters, moNeighborhood < Neighbor > & neighborhood, eoEvalFunc& fullEval, const eoOptional< moEval >& eval = eoOptional< moEval >::null, const eoOptional< moLocalSearch >& walker = eoOptional< moLocalSearch >::null ) : _default_eval ( fullEval ), _eval(eval.hasValue()? eval.get(): _default_eval), _default_continuator( max_iters, false ), _continuator( _default_continuator ), _checkpoint( _continuator ), _default_walker( neighborhood, fullEval, _eval, _checkpoint ), _walker( walker.hasValue()? walker.get(): _default_walker ) { _checkpoint.add( _varStat ); } /** * Evaluates the estimator with the walker algorithm and returns the standard deviation * @param solution the solution from where to start the walk */ double operator()( EOT & solution ) { _walker(solution); return sqrt(_varStat.value()); } /** * @return the class name */ virtual std::string className(void) const { return "moStdDevEstimator"; } private: moFullEvalByCopy _default_eval; moEval& _eval; moIterContinuator _default_continuator; moContinuator & _continuator; moCheckpoint _checkpoint; moRandomWalk _default_walker; moLocalSearch _walker; moFitnessVarianceStat _varStat; }; #endif // __moStdDevEstimator_h__