00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _edoEDASA_h
00029 #define _edoEDASA_h
00030
00031 #include <eo>
00032
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
00124
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
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
00152
00153
00154 distrib = _estimator(selected_pop);
00155
00156
00157
00158
00159
00160
00161 assert(selected_pop.size() > 0);
00162
00163
00164
00165
00166
00167
00168 EOType current_solution = _selectone(selected_pop);
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 _modifier(distrib, current_solution);
00180
00181
00182
00183
00184
00185
00186
00187
00188 _evaluation( current_solution );
00189
00190
00191
00192
00193
00194
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
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);
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