edoAlgoAdaptive.h
00001 /*
00002 The Evolving Distribution Objects framework (EDO) is a template-based,
00003 ANSI-C++ evolutionary computation library which helps you to write your
00004 own estimation of distribution algorithms.
00005 
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 This library is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public
00017 License along with this library; if not, write to the Free Software
00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 Copyright (C) 2010 Thales group
00021 */
00022 /*
00023 Authors:
00024     Johann Dréo <johann.dreo@thalesgroup.com>
00025     Pierre Savéant <pierre.saveant@thalesgroup.com>
00026 */
00027 
00028 #ifndef _edoAlgoAdaptive_h
00029 #define _edoAlgoAdaptive_h
00030 
00031 #include <eo>
00032 
00033 #include <utils/eoRNG.h>
00034 
00035 #include "edoAlgo.h"
00036 #include "edoEstimator.h"
00037 #include "edoModifierMass.h"
00038 #include "edoSampler.h"
00039 #include "edoContinue.h"
00040 
00054 template < typename D >
00055 class edoAlgoAdaptive : public edoAlgo< D >
00056 {
00057 public:
00059     typedef typename D::EOType EOType;
00060 
00062     typedef typename EOType::AtomType AtomType;
00063 
00065     typedef typename EOType::Fitness Fitness;
00066 
00067 public:
00068 
00081     edoAlgoAdaptive(
00082         D & distrib,
00083         eoPopEvalFunc < EOType > & evaluator,
00084         eoSelect< EOType > & selector,
00085         edoEstimator< D > & estimator,
00086         edoSampler< D > & sampler,
00087         eoReplacement< EOType > & replacor,
00088         eoContinue< EOType > & pop_continuator,
00089         edoContinue< D > & distribution_continuator
00090     ) :
00091         _distrib(distrib),
00092         _evaluator(evaluator),
00093         _selector(selector),
00094         _estimator(estimator),
00095         _sampler(sampler),
00096         _replacor(replacor),
00097         _pop_continuator(pop_continuator),
00098         _dummy_continue(),
00099         _distribution_continuator(distribution_continuator)
00100     {}
00101 
00102 
00104 
00115     edoAlgoAdaptive (
00116         D & distrib,
00117         eoPopEvalFunc < EOType > & evaluator,
00118         eoSelect< EOType > & selector,
00119         edoEstimator< D > & estimator,
00120         edoSampler< D > & sampler,
00121         eoReplacement< EOType > & replacor,
00122         eoContinue< EOType > & pop_continuator
00123     ) :
00124         _distrib( distrib ),
00125         _evaluator(evaluator),
00126         _selector(selector),
00127         _estimator(estimator),
00128         _sampler(sampler),
00129         _replacor(replacor),
00130         _pop_continuator(pop_continuator),
00131         _dummy_continue(),
00132         _distribution_continuator( _dummy_continue )
00133     {}
00134 
00140     void operator ()(eoPop< EOType > & pop)
00141     {
00142         assert(pop.size() > 0);
00143 
00144         eoPop< EOType > current_pop;
00145         eoPop< EOType > selected_pop;
00146 
00147         // update the extern distribution passed to the estimator (cf. CMA-ES)
00148         // OR replace the dummy distribution for estimators that do not need extern distributions (cf. EDA)
00149         _distrib = _estimator(pop);
00150 
00151         // Evaluating a first time the candidate solutions
00152         // The first pop is not supposed to be evaluated (@see eoPopLoopEval).
00153         // _evaluator( current_pop, pop );
00154 
00155         do {
00156             // (1) Selection of the best points in the population
00157             _selector(pop, selected_pop);
00158             assert( selected_pop.size() > 0 );
00159 
00160             // (2) Estimation of the distribution parameters
00161             _distrib = _estimator(selected_pop);
00162 
00163             // (3) sampling
00164             // The sampler produces feasible solutions (@see edoSampler that
00165             // encapsulate an edoBounder)
00166             current_pop.clear();
00167             for( unsigned int i = 0; i < pop.size(); ++i ) {
00168                 current_pop.push_back( _sampler(_distrib) );
00169             }
00170 
00171             // (4) Evaluate new solutions
00172             _evaluator( pop, current_pop );
00173 
00174             // (5) Replace old solutions by new ones
00175             _replacor(pop, current_pop); // e.g. copy current_pop in pop
00176 
00177         } while( _distribution_continuator( _distrib ) && _pop_continuator( pop ) );
00178     } // operator()
00179 
00180 
00181 protected:
00182 
00184     D & _distrib;
00185 
00187     eoPopEvalFunc<EOType> & _evaluator;
00188 
00190     eoSelect<EOType> & _selector;
00191 
00193     edoEstimator<D> & _estimator;
00194 
00196     edoSampler<D> & _sampler;
00197 
00199     eoReplacement<EOType> & _replacor;
00200 
00202     eoContinue<EOType> & _pop_continuator;
00203 
00205     edoDummyContinue<D> _dummy_continue;
00206 
00208     edoContinue<D> & _distribution_continuator;
00209 
00210 };
00211 
00212 #endif // !_edoAlgoAdaptive_h
00213 
 All Classes Functions Variables Typedefs