make_checkpoint_moeo.h

00001 /* 
00002 * <make_checkpoint_moeo.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 //-----------------------------------------------------------------------------
00037 
00038 #ifndef MAKE_CHECKPOINT_MOEO_H_
00039 #define MAKE_CHECKPOINT_MOEO_H_
00040 
00041 #include <stdlib.h>
00042 #include <sstream>
00043 #include <eoContinue.h>
00044 #include <eoEvalFuncCounter.h>
00045 #include <utils/checkpointing>
00046 #include <utils/selectors.h>
00047 #include <utils/eoParser.h>
00048 #include <utils/eoState.h>
00049 #include <metric/moeoContributionMetric.h>
00050 #include <metric/moeoEntropyMetric.h>
00051 #include <utils/moeoArchiveUpdater.h>
00052 #include <utils/moeoArchiveObjectiveVectorSavingUpdater.h>
00053 #include <utils/moeoBinaryMetricSavingUpdater.h>
00054 
00055 bool testDirRes(std::string _dirName, bool _erase);
00056 
00066 template < class MOEOT >
00067 eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState & _state, eoEvalFuncCounter < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _archive)
00068 {
00069     eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue));
00070     /* the objective vector type */
00071     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00072     
00074     // Counters
00076     // is nb Eval to be used as counter?
00077     //bool useEval = _parser.getORcreateParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output").value();
00078     // Create anyway a generation-counter parameter
00079     eoValueParam<unsigned int> *generationCounter = new eoValueParam<unsigned int>(0, "Gen.");
00080     // Create an incrementor (sub-class of eoUpdater).
00081     eoIncrementor<unsigned int> & increment = _state.storeFunctor( new eoIncrementor<unsigned int>(generationCounter->value()) );
00082     // Add it to the checkpoint
00083     checkpoint.add(increment);
00084     // dir for DISK output
00085     std::string & dirName =  _parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value();
00086     // shoudl we empty it if exists
00087     eoValueParam<bool>& eraseParam = _parser.getORcreateParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output");
00088     bool dirOK = false;            // not tested yet
00089 
00090     // Dump of the whole population
00091     //-----------------------------
00092     bool printPop = _parser.getORcreateParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output").value();
00093     eoSortedPopStat<MOEOT> * popStat;
00094     if ( printPop ) // we do want pop dump
00095     {
00096         popStat = & _state.storeFunctor(new eoSortedPopStat<MOEOT>);
00097         checkpoint.add(*popStat);
00098     }
00099 
00101     // State savers
00103     // feed the state to state savers
00104     // save state every N  generation
00105     eoValueParam<unsigned int>& saveFrequencyParam = _parser.createParam((unsigned int)(0), "saveFrequency", "Save every F generation (0 = only final state, absent = never)", '\0', "Persistence" );
00106     if (_parser.isItThere(saveFrequencyParam))
00107     {
00108         // first make sure dirName is OK
00109         if (! dirOK )
00110             dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
00111         unsigned int freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
00112 #ifdef _MSVC
00113         std::string stmp = dirName + "\generations";
00114 #else
00115         std::string stmp = dirName + "/generations";
00116 #endif
00117         eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
00118         _state.storeFunctor(stateSaver1);
00119         checkpoint.add(*stateSaver1);
00120     }
00121     // save state every T seconds
00122     eoValueParam<unsigned int>& saveTimeIntervalParam = _parser.getORcreateParam((unsigned int)(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" );
00123     if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
00124     {
00125         // first make sure dirName is OK
00126         if (! dirOK )
00127             dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
00128 #ifdef _MSVC
00129         std::string stmp = dirName + "\time";
00130 #else
00131         std::string stmp = dirName + "/time";
00132 #endif
00133         eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
00134         _state.storeFunctor(stateSaver2);
00135         checkpoint.add(*stateSaver2);
00136     }
00137 
00139     // Archive
00141     // update the archive every generation
00142     bool updateArch = _parser.getORcreateParam(true, "updateArch", "Update the archive at each gen.", '\0', "Evolution Engine").value();
00143     if (updateArch)
00144     {
00145         moeoArchiveUpdater < MOEOT > * updater = new moeoArchiveUpdater < MOEOT > (_archive, _pop);
00146         _state.storeFunctor(updater);
00147         checkpoint.add(*updater);
00148     }
00149     // store the objective vectors contained in the archive every generation
00150     bool storeArch = _parser.getORcreateParam(false, "storeArch", "Store the archive's objective vectors at each gen.", '\0', "Output").value();
00151     if (storeArch)
00152     {
00153         if (! dirOK )
00154             dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
00155 #ifdef _MSVC
00156         std::string stmp = dirName + "\arch";
00157 #else
00158         std::string stmp = dirName + "/arch";
00159 #endif
00160         moeoArchiveObjectiveVectorSavingUpdater < MOEOT > * save_updater = new moeoArchiveObjectiveVectorSavingUpdater < MOEOT > (_archive, stmp);
00161         _state.storeFunctor(save_updater);
00162         checkpoint.add(*save_updater);
00163     }
00164     // store the contribution of the non-dominated solutions
00165     bool cont = _parser.getORcreateParam(false, "contribution", "Store the contribution of the archive at each gen.", '\0', "Output").value();
00166     if (cont)
00167     {
00168         if (! dirOK )
00169             dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
00170 #ifdef _MSVC
00171         std::string stmp = dirName + "\contribution";
00172 #else
00173         std::string stmp = dirName + "/contribution";
00174 #endif
00175         moeoContributionMetric < ObjectiveVector > * contribution = new moeoContributionMetric < ObjectiveVector >;
00176         moeoBinaryMetricSavingUpdater < MOEOT > * contribution_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*contribution, _archive, stmp);
00177         _state.storeFunctor(contribution_updater);
00178         checkpoint.add(*contribution_updater);
00179     }
00180     // store the entropy of the non-dominated solutions
00181     bool ent = _parser.getORcreateParam(false, "entropy", "Store the entropy of the archive at each gen.", '\0', "Output").value();
00182     if (ent)
00183     {
00184         if (! dirOK )
00185             dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
00186 #ifdef _MSVC
00187         std::string stmp = dirName + "\entropy";
00188 #else
00189         std::string stmp = dirName + "/entropy";
00190 #endif
00191         moeoEntropyMetric < ObjectiveVector > * entropy = new moeoEntropyMetric < ObjectiveVector >;
00192         moeoBinaryMetricSavingUpdater < MOEOT > * entropy_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*entropy, _archive, stmp);
00193         _state.storeFunctor(entropy_updater);
00194         checkpoint.add(*entropy_updater);
00195     }
00196 
00197     // and that's it for the (control and) output
00198     return checkpoint;
00199 }
00200 
00201 #endif /*MAKE_CHECKPOINT_MOEO_H_*/

Generated on Fri Oct 12 15:16:04 2007 for ParadisEO-MOEO:MultiObjectiveEvolvingObjects by  doxygen 1.4.7