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
00029
00030 #ifndef _make_checkpoint_assembled_h
00031 #define _make_checkpoint_assembled_h
00032
00033 #include <vector>
00034 #include <string>
00035
00036 #include <eoScalarFitnessAssembled.h>
00037 #include <utils/selectors.h>
00038 #include <EO.h>
00039 #include <eoEvalFuncCounter.h>
00040 #include <utils/checkpointing>
00041
00042
00043
00044 bool testDirRes(std::string _dirName, bool _erase);
00046
00048 template <class EOT>
00049 eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _state, eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
00050 {
00051
00052
00053
00054 std::string dirName = _parser.getORcreateParam(std::string("Res"), "resDir",
00055 "Directory to store DISK outputs",
00056 '\0', "Output").value();
00057 bool erase = _parser.getORcreateParam(true, "eraseDir",
00058 "Erase files in dirName if any",
00059 '\0', "Output").value();
00060 bool gnuplots = _parser.getORcreateParam(true, "plots",
00061 "Plot stuff using GnuPlot",
00062 '\0', "Output").value();
00063 bool printFile = _parser.getORcreateParam(true, "printFile",
00064 "Print statistics file",
00065 '\0', "Output").value();
00066
00067 eoValueParam<unsigned>& saveFrequencyParam
00068 = _parser.getORcreateParam(unsigned(0), "saveFrequency",
00069 "Save every F generation (0 = only final state, absent = never)",
00070 '\0', "Persistence" );
00071
00072 testDirRes(dirName, erase);
00073
00074
00075
00076 eoCheckPoint<EOT> *checkpoint = new eoCheckPoint<EOT>(_continue);
00077 _state.storeFunctor(checkpoint);
00078
00079
00080
00081 eoIncrementorParam<unsigned> *generationCounter = new eoIncrementorParam<unsigned>("Gen.");
00082 _state.storeFunctor(generationCounter);
00083 checkpoint->add(*generationCounter);
00084
00085
00086
00087 eoTimeCounter * tCounter = NULL;
00088 tCounter = new eoTimeCounter;
00089 _state.storeFunctor(tCounter);
00090 checkpoint->add(*tCounter);
00091
00092
00093
00094
00095 typedef typename EOT::Fitness Fit;
00096 Fit fit;
00097 std::vector<std::string> fitness_descriptions = fit.getDescriptionVector();
00098 unsigned nTerms = fitness_descriptions.size();
00099
00100
00101
00102
00103
00104 std::vector<eoAssembledFitnessAverageStat<EOT>* > avgvals( nTerms );
00105 for (unsigned i=0; i < nTerms; ++i){
00106 std::string descr = "Avg. of " + fitness_descriptions[i];
00107 avgvals[i] = new eoAssembledFitnessAverageStat<EOT>(i, descr);
00108 _state.storeFunctor( avgvals[i] );
00109 checkpoint->add( *avgvals[i] );
00110 }
00111
00112
00113 std::vector<eoAssembledFitnessBestStat<EOT>* > bestvals( nTerms );
00114 for (unsigned j=0; j < nTerms; ++j){
00115 std::string descr = fitness_descriptions[j] + " of best ind.";
00116 bestvals[j] = new eoAssembledFitnessBestStat<EOT>(j, descr);
00117 _state.storeFunctor( bestvals[j] );
00118 checkpoint->add( *bestvals[j] );
00119 }
00120
00121
00122
00123 eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
00124 _state.storeFunctor(monitor);
00125 checkpoint->add(*monitor);
00126 monitor->add(*generationCounter);
00127 monitor->add(_eval);
00128 monitor->add(*tCounter);
00129
00130
00131 monitor->add( *bestvals[0] );
00132
00133
00134 for (unsigned l=0; l < nTerms; ++l)
00135 monitor->add( *avgvals[l] );
00136
00137
00138
00139 if (gnuplots ){
00140 std::string stmp;
00141
00142
00143 eoScalarFitnessStat<EOT> *fitStat = new eoScalarFitnessStat<EOT>;
00144 _state.storeFunctor(fitStat);
00145 checkpoint->add(*fitStat);
00146
00147 eoGnuplot1DSnapshot *fitSnapshot = new eoGnuplot1DSnapshot(dirName);
00148 _state.storeFunctor(fitSnapshot);
00149
00150 fitSnapshot->add(*fitStat);
00151
00152 checkpoint->add(*fitSnapshot);
00153
00154 std::vector<eoGnuplot1DMonitor*> gnumonitors(nTerms, NULL );
00155 for (unsigned k=0; k < nTerms; ++k){
00156 stmp = dirName + "/gnuplot_" + fitness_descriptions[k] + ".xg";
00157 gnumonitors[k] = new eoGnuplot1DMonitor(stmp,true);
00158 _state.storeFunctor(gnumonitors[k]);
00159 checkpoint->add(*gnumonitors[k]);
00160 gnumonitors[k]->add(*generationCounter);
00161 gnumonitors[k]->add(*bestvals[k]);
00162 gnumonitors[k]->add(*avgvals[k]);
00163 }
00164
00165 }
00166
00167
00168
00169 if( printFile ){
00170 std::string stmp2 = dirName + "/eoStatistics.sav";
00171 eoFileMonitor *fileMonitor = new eoFileMonitor(stmp2);
00172 _state.storeFunctor(fileMonitor);
00173 checkpoint->add(*fileMonitor);
00174 fileMonitor->add(*generationCounter);
00175 fileMonitor->add(_eval);
00176 fileMonitor->add(*tCounter);
00177
00178 for (unsigned i=0; i < nTerms; ++i){
00179 fileMonitor->add(*bestvals[i]);
00180 fileMonitor->add(*avgvals[i]);
00181 }
00182
00183 }
00184
00185
00186
00187
00188
00189 if (_parser.isItThere(saveFrequencyParam)) {
00190
00191 unsigned freq = (saveFrequencyParam.value() > 0 ? saveFrequencyParam.value() : UINT_MAX );
00192 std::string stmp = dirName + "/generations";
00193 eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
00194 _state.storeFunctor(stateSaver1);
00195 checkpoint->add(*stateSaver1);
00196 }
00197
00198
00199 return *checkpoint;
00200 }
00201
00202 #endif