- Main Page
- Classes
- Files

- Search for |

# make_continue_moeo.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // make_continue_moeo.h
    00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
    00006 /*
    00007     This library...
    00008
    00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
    00010  */
    00011 //-----------------------------------------------------------------------------
    00012
    00013 #ifndef MAKE_CONTINUE_MOEO_H_
    00014 #define MAKE_CONTINUE_MOEO_H_
    00015
    00016 #include <eoCombinedContinue.h>
    00017 #include <eoGenContinue.h>
    00018 #include <eoEvalContinue.h>
    00019 #include <eoFitContinue.h>
    00020 #include <eoTimeContinue.h>
    00021 #ifndef _MSC_VER
    00022 #include <eoCtrlCContinue.h>
    00023 #endif
    00024 #include <utils/eoParser.h>
    00025 #include <utils/eoState.h>
    00026
    00027
    00033 template <class MOEOT>
    00034 eoCombinedContinue<MOEOT> * make_combinedContinue(eoCombinedContinue<MOEOT> *_combined, eoContinue<MOEOT> *_cont)
    00035 {
    00036     if (_combined)                 // already exists
    00037         _combined->add(*_cont);
    00038     else
    00039         _combined = new eoCombinedContinue<MOEOT>(*_cont);
    00040     return _combined;
    00041 }
    00042
    00043
    00050 template <class MOEOT>
    00051 eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eoEvalFuncCounter<MOEOT> & _eval)
    00052 {
    00053     // the combined continue - to be filled
    00054     eoCombinedContinue<MOEOT> *continuator = NULL;
    00055     // First the eoGenContinue - need a default value so you can run blind
    00056     // but we also need to be able to avoid it <--> 0
    00057     eoValueParam<unsigned>& maxGenParam = _parser.createParam(unsigned(100), "maxGen", "Maximum number of generations (0 = none)",'G',"Stopping criterion");
    00058     if (maxGenParam.value()) // positive: -> define and store
    00059     {
    00060         eoGenContinue<MOEOT> *genCont = new eoGenContinue<MOEOT>(maxGenParam.value());
    00061         _state.storeFunctor(genCont);
    00062         // and "add" to combined
    00063         continuator = make_combinedContinue<MOEOT>(continuator, genCont);
    00064     }
    00065     // maxEval
    00066     eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
    00067     if (maxEvalParam.value())
    00068     {
    00069         eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
    00070         _state.storeFunctor(evalCont);
    00071         // and "add" to combined
    00072         continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
    00073     }
    00074     // maxTime
    00075     eoValueParam<unsigned long>& maxTimeParam = _parser.getORcreateParam((unsigned long)0, "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion");
    00076     if (maxTimeParam.value()) // positive: -> define and store
    00077     {
    00078         eoTimeContinue<MOEOT> *timeCont = new eoTimeContinue<MOEOT>(maxTimeParam.value());
    00079         _state.storeFunctor(timeCont);
    00080         // and "add" to combined
    00081         continuator = make_combinedContinue<MOEOT>(continuator, timeCont);
    00082     }
    00083     // CtrlC
    00084 #ifndef _MSC_VER
    00085     // the CtrlC interception (Linux only I'm afraid)
    00086     eoCtrlCContinue<MOEOT> *ctrlCCont;
    00087     eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
    00088     if (_parser.isItThere(ctrlCParam))
    00089     {
    00090         ctrlCCont = new eoCtrlCContinue<MOEOT>;
    00091         // store
    00092         _state.storeFunctor(ctrlCCont);
    00093         // add to combinedContinue
    00094         continuator = make_combinedContinue<MOEOT>(continuator, ctrlCCont);
    00095     }
    00096 #endif
    00097     // now check that there is at least one!
    00098     if (!continuator)
    00099         throw std::runtime_error("You MUST provide a stopping criterion");
    00100     // OK, it's there: store in the eoState
    00101     _state.storeFunctor(continuator);
    00102     // and return
    00103     return *continuator;
    00104 }
    00105
    00106 #endif /*MAKE_CONTINUE_MOEO_H_*/