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