edoEDASA.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     Caner Candan <caner.candan@thalesgroup.com>
00026 */
00027 
00028 #ifndef _edoEDASA_h
00029 #define _edoEDASA_h
00030 
00031 #include <eo>
00032 //#include <mo>
00033 
00034 #include <utils/eoRNG.h>
00035 
00036 #include "edoAlgo.h"
00037 #include "edoEstimator.h"
00038 #include "edoModifierMass.h"
00039 #include "edoSampler.h"
00040 #include "edoContinue.h"
00041 
00043 
00044 template < typename D >
00045 class edoEDASA : public edoAlgo< D >
00046 {
00047 public:
00049     typedef typename D::EOType EOType;
00050 
00052     typedef typename EOType::AtomType AtomType;
00053 
00055     typedef typename EOType::Fitness Fitness;
00056 
00057 public:
00058 
00060 
00076     edoEDASA (eoSelect< EOType > & selector,
00077               edoEstimator< D > & estimator,
00078               eoSelectOne< EOType > & selectone,
00079               edoModifierMass< D > & modifier,
00080               edoSampler< D > & sampler,
00081               eoContinue< EOType > & pop_continue,
00082               edoContinue< D > & distribution_continue,
00083               eoEvalFunc < EOType > & evaluation,
00084               moContinuator< moDummyNeighbor<EOType> > & sa_continue,
00085               moCoolingSchedule<EOType> & cooling_schedule,
00086               double initial_temperature,
00087               eoReplacement< EOType > & replacor
00088               )
00089         : _selector(selector),
00090           _estimator(estimator),
00091           _selectone(selectone),
00092           _modifier(modifier),
00093           _sampler(sampler),
00094           _pop_continue(pop_continue),
00095           _distribution_continue(distribution_continue),
00096           _evaluation(evaluation),
00097           _sa_continue(sa_continue),
00098           _cooling_schedule(cooling_schedule),
00099           _initial_temperature(initial_temperature),
00100           _replacor(replacor)
00101 
00102     {}
00103 
00105 
00111     void operator ()(eoPop< EOType > & pop)
00112     {
00113         assert(pop.size() > 0);
00114 
00115         double temperature = _initial_temperature;
00116 
00117         eoPop< EOType > current_pop;
00118 
00119         eoPop< EOType > selected_pop;
00120 
00121 
00122         //-------------------------------------------------------------
00123         // Estimating a first time the distribution parameter thanks
00124         // to population.
00125         //-------------------------------------------------------------
00126 
00127         D distrib = _estimator(pop);
00128 
00129         double size = distrib.size();
00130         assert(size > 0);
00131 
00132         //-------------------------------------------------------------
00133 
00134 
00135         do
00136             {
00137                 //-------------------------------------------------------------
00138                 // (3) Selection of the best points in the population
00139                 //-------------------------------------------------------------
00140 
00141                 selected_pop.clear();
00142 
00143                 _selector(pop, selected_pop);
00144 
00145                 assert( selected_pop.size() > 0 );
00146 
00147                 //-------------------------------------------------------------
00148 
00149 
00150                 //-------------------------------------------------------------
00151                 // (4) Estimation of the distribution parameters
00152                 //-------------------------------------------------------------
00153 
00154                 distrib = _estimator(selected_pop);
00155 
00156                 //-------------------------------------------------------------
00157 
00158 
00159                 // TODO: utiliser selected_pop ou pop ???
00160 
00161                 assert(selected_pop.size() > 0);
00162 
00163 
00164                 //-------------------------------------------------------------
00165                 // Init of a variable contening a point with the bestest fitnesses
00166                 //-------------------------------------------------------------
00167 
00168                 EOType current_solution = _selectone(selected_pop);
00169 
00170                 //-------------------------------------------------------------
00171 
00172 
00173                 //-------------------------------------------------------------
00174                 // Fit the current solution with the distribution parameters (bounds)
00175                 //-------------------------------------------------------------
00176 
00177                 // FIXME: si besoin de modifier la dispersion de la distribution
00178                 // _modifier_dispersion(distribution, selected_pop);
00179                 _modifier(distrib, current_solution);
00180 
00181                 //-------------------------------------------------------------
00182 
00183 
00184                 //-------------------------------------------------------------
00185                 // Evaluating a first time the current solution
00186                 //-------------------------------------------------------------
00187 
00188                 _evaluation( current_solution );
00189 
00190                 //-------------------------------------------------------------
00191 
00192 
00193                 //-------------------------------------------------------------
00194                 // Building of the sampler in current_pop
00195                 //-------------------------------------------------------------
00196 
00197                 _sa_continue.init( current_solution );
00198 
00199                 current_pop.clear();
00200 
00201                 do
00202                     {
00203                         EOType candidate_solution = _sampler(distrib);
00204                         _evaluation( candidate_solution );
00205 
00206                         // TODO: verifier le critere d'acceptation
00207                         if ( candidate_solution.fitness() < current_solution.fitness() ||
00208                              rng.uniform() < exp( ::fabs(candidate_solution.fitness() - current_solution.fitness()) / temperature ) )
00209                             {
00210                                 current_pop.push_back(candidate_solution);
00211                                 current_solution = candidate_solution;
00212                             }
00213                     }
00214                 while ( _sa_continue( current_solution ) );
00215 
00216                 //-------------------------------------------------------------
00217 
00218 
00219                 _replacor(pop, current_pop); // copy current_pop in pop
00220 
00221                 pop.sort();
00222 
00223                 if ( ! _cooling_schedule( temperature ) ){ eo::log << eo::debug << "_cooling_schedule" << std::endl; break; }
00224 
00225                 if ( ! _distribution_continue( distrib ) ){ eo::log << eo::debug << "_distribution_continue" << std::endl; break; }
00226 
00227                 if ( ! _pop_continue( pop ) ){ eo::log << eo::debug << "_pop_continue" << std::endl; break; }
00228 
00229             }
00230         while ( 1 );
00231     }
00232 
00233 private:
00234 
00236     eoSelect < EOType > & _selector;
00237 
00239     edoEstimator< D > & _estimator;
00240 
00242     eoSelectOne< EOType > & _selectone;
00243 
00245     edoModifierMass< D > & _modifier;
00246 
00248     edoSampler< D > & _sampler;
00249 
00251     eoContinue < EOType > & _pop_continue;
00252 
00254     edoContinue < D > & _distribution_continue;
00255 
00257     eoEvalFunc < EOType > & _evaluation;
00258 
00260     moContinuator< moDummyNeighbor<EOType> > & _sa_continue;
00261 
00263     moCoolingSchedule<EOType> & _cooling_schedule;
00264 
00266     double  _initial_temperature;
00267 
00269     eoReplacement < EOType > & _replacor;
00270 };
00271 
00272 #endif // !_edoEDASA_h
 All Classes Functions Variables Typedefs