00001 #include <eo>
00002 #include <mo>
00003
00004 #include <eoEvalFuncCounterBounder.h>
00005
00006 #include <do/make_pop.h>
00007 #include <do/make_run.h>
00008 #include <do/make_continue.h>
00009 #include <do/make_checkpoint.h>
00010
00011 #include <edo>
00012
00013 #include "Rosenbrock.h"
00014 #include "Sphere.h"
00015
00016
00017 typedef eoReal<eoMinimizingFitness> EOT;
00018 typedef edoNormalMulti< EOT > Distrib;
00019
00020
00021 int main(int ac, char** av)
00022 {
00023 eoParser parser(ac, av);
00024
00025
00026
00027
00028 std::string section("Algorithm parameters");
00029
00030
00031 double initial_temperature = parser.createParam((double)10e5, "temperature", "Initial temperature", 'i', section).value();
00032
00033 eoState state;
00034
00035
00036
00037
00038
00039
00040 double selection_rate = parser.createParam((double)0.5, "selection_rate", "Selection Rate", 'R', section).value();
00041
00042 eoSelect< EOT >* selector = new eoDetSelect< EOT >( selection_rate );
00043 state.storeFunctor(selector);
00044
00045 edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< EOT >();
00046 state.storeFunctor(estimator);
00047
00048 eoSelectOne< EOT >* selectone = new eoDetTournamentSelect< EOT >( 2 );
00049 state.storeFunctor(selectone);
00050
00051 edoModifierMass< Distrib >* modifier = new edoNormalMultiCenter< EOT >();
00052 state.storeFunctor(modifier);
00053
00054 eoEvalFunc< EOT >* plainEval = new Rosenbrock< EOT >();
00055 state.storeFunctor(plainEval);
00056
00057 unsigned long max_eval = parser.getORcreateParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion").value();
00058 eoEvalFuncCounterBounder< EOT > eval(*plainEval, max_eval);
00059
00060 eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5);
00061 state.storeFunctor(gen);
00062
00063
00064 unsigned int dimension_size = parser.createParam((unsigned int)10, "dimension-size", "Dimension size", 'd', section).value();
00065
00066 eoInitFixedLength< EOT >* init = new eoInitFixedLength< EOT >( dimension_size, *gen );
00067 state.storeFunctor(init);
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 eoPop< EOT >& pop = do_make_pop(parser, state, *init);
00082
00083
00084
00085
00086
00087
00088
00089
00090 apply(eval, pop);
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 edoBounder< EOT >* bounder = new edoBounderRng< EOT >(EOT(pop[0].size(), -5),
00101 EOT(pop[0].size(), 5),
00102 *gen);
00103 state.storeFunctor(bounder);
00104
00105
00106
00107
00108
00109
00110
00111
00112 edoSampler< Distrib >* sampler = new edoSamplerNormalMulti< EOT >( *bounder );
00113 state.storeFunctor(sampler);
00114
00115
00116
00117
00118
00119
00120
00121
00122 unsigned int popSize = parser.getORcreateParam((unsigned int)20, "popSize", "Population Size", 'P', "Evolution Engine").value();
00123
00124 moContinuator< moDummyNeighbor<EOT> >* sa_continue = new moIterContinuator< moDummyNeighbor<EOT> >( popSize );
00125 state.storeFunctor(sa_continue);
00126
00127
00128
00129
00130
00131
00132
00133
00134 double threshold_temperature = parser.createParam((double)0.1, "threshold", "Minimal temperature at which stop", 't', section).value();
00135 double alpha = parser.createParam((double)0.1, "alpha", "Temperature decrease rate", 'a', section).value();
00136
00137 moCoolingSchedule<EOT>* cooling_schedule = new moSimpleCoolingSchedule<EOT>(initial_temperature, alpha, 0, threshold_temperature);
00138 state.storeFunctor(cooling_schedule);
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 eoContinue< EOT >& eo_continue = do_make_continue(parser, state, eval);
00149
00150
00151
00152
00153
00154
00155
00156
00157 eoCheckPoint< EOT >& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue);
00158
00159
00160
00161
00162
00163
00164
00165
00166 edoDummyContinue< Distrib >* dummy_continue = new edoDummyContinue< Distrib >();
00167 state.storeFunctor(dummy_continue);
00168
00169 edoCheckPoint< Distrib >* distribution_continue = new edoCheckPoint< Distrib >( *dummy_continue );
00170 state.storeFunctor(distribution_continue);
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 eoReplacement< EOT >* replacor = new eoEPReplacement< EOT >(pop.size());
00181
00182
00183
00184
00185
00186 state.storeFunctor(replacor);
00187
00188
00189
00190
00191
00192
00193
00194
00195 if (parser.userNeedsHelp())
00196 {
00197 parser.printHelp(std::cout);
00198 exit(1);
00199 }
00200
00201
00202
00203 make_verbose(parser);
00204 make_help(parser);
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 edoPopStat< EOT >* popStat = new edoPopStat<EOT>;
00217 state.storeFunctor(popStat);
00218 pop_continue.add(*popStat);
00219
00220 edoFileSnapshot* fileSnapshot = new edoFileSnapshot("EDASA_ResPop");
00221 state.storeFunctor(fileSnapshot);
00222 fileSnapshot->add(*popStat);
00223 pop_continue.add(*fileSnapshot);
00224
00225
00226
00227
00228
00229
00230
00231
00232 edoDistribStat< Distrib >* distrib_stat = new edoStatNormalMulti< EOT >();
00233 state.storeFunctor(distrib_stat);
00234
00235 distribution_continue->add( *distrib_stat );
00236
00237
00238
00239
00240
00241
00242 eoFileMonitor* file_monitor = new eoFileMonitor("eda_sa_distribution_bounds.txt");
00243 state.storeFunctor(file_monitor);
00244 file_monitor->add(*distrib_stat);
00245 distribution_continue->add( *file_monitor );
00246
00247
00248
00249
00250
00251
00252
00253
00254 edoAlgo< Distrib >* algo = new edoEDASA< Distrib >
00255 (*selector, *estimator, *selectone, *modifier, *sampler,
00256 pop_continue, *distribution_continue,
00257 eval, *sa_continue, *cooling_schedule,
00258 initial_temperature, *replacor);
00259
00260
00261
00262
00263
00264
00265
00266
00267 try
00268 {
00269 do_run(*algo, pop);
00270 }
00271 catch (eoEvalFuncCounterBounderException& e)
00272 {
00273 eo::log << eo::warnings << "warning: " << e.what() << std::endl;
00274 }
00275 catch (std::exception& e)
00276 {
00277 eo::log << eo::errors << "error: " << e.what() << std::endl;
00278 exit(EXIT_FAILURE);
00279 }
00280
00281
00282
00283 return 0;
00284 }