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 #ifndef _make_continue_h
00028 #define _make_continue_h
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <eoCombinedContinue.h>
00038 #include <eoGenContinue.h>
00039 #include <eoSteadyFitContinue.h>
00040 #include <eoEvalContinue.h>
00041 #include <eoFitContinue.h>
00042 #ifndef _MSC_VER
00043 #include <eoCtrlCContinue.h>
00044 #endif
00045
00046
00047 #include <utils/eoParser.h>
00048 #include <utils/eoState.h>
00049
00050
00052 template <class Indi>
00053 eoCombinedContinue<Indi> * make_combinedContinue(eoCombinedContinue<Indi> *_combined, eoContinue<Indi> *_cont)
00054 {
00055 if (_combined)
00056 _combined->add(*_cont);
00057 else
00058 _combined = new eoCombinedContinue<Indi>(*_cont);
00059 return _combined;
00060 }
00061
00062 template <class Indi>
00063 eoContinue<Indi> & do_make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)
00064 {
00066
00067 eoCombinedContinue<Indi> *continuator = NULL;
00068
00069
00070
00071
00072
00073 eoValueParam<unsigned>& maxGenParam = _parser.getORcreateParam(unsigned(100), "maxGen", "Maximum number of generations () = none)",'G',"Stopping criterion");
00074
00075 if (maxGenParam.value())
00076 {
00077 eoGenContinue<Indi> *genCont = new eoGenContinue<Indi>(maxGenParam.value());
00078 _state.storeFunctor(genCont);
00079
00080 continuator = make_combinedContinue<Indi>(continuator, genCont);
00081 }
00082
00083
00084 eoValueParam<unsigned>& steadyGenParam = _parser.createParam(unsigned(100), "steadyGen", "Number of generations with no improvement",'s', "Stopping criterion");
00085 eoValueParam<unsigned>& minGenParam = _parser.createParam(unsigned(0), "minGen", "Minimum number of generations",'g', "Stopping criterion");
00086 if (_parser.isItThere(steadyGenParam))
00087 {
00088 eoSteadyFitContinue<Indi> *steadyCont = new eoSteadyFitContinue<Indi>
00089 (minGenParam.value(), steadyGenParam.value());
00090
00091 _state.storeFunctor(steadyCont);
00092
00093 continuator = make_combinedContinue<Indi>(continuator, steadyCont);
00094 }
00095
00096
00097 eoValueParam<unsigned long>& maxEvalParam
00098 = _parser.getORcreateParam((unsigned long)0, "maxEval",
00099 "Maximum number of evaluations (0 = none)",
00100 'E', "Stopping criterion");
00101
00102 if (maxEvalParam.value())
00103 {
00104 eoEvalContinue<Indi> *evalCont = new eoEvalContinue<Indi>(_eval, maxEvalParam.value());
00105 _state.storeFunctor(evalCont);
00106
00107 continuator = make_combinedContinue<Indi>(continuator, evalCont);
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 eoFitContinue<Indi> *fitCont;
00125 eoValueParam<double>& targetFitnessParam = _parser.createParam(double(0.0), "targetFitness", "Stop when fitness reaches",'T', "Stopping criterion");
00126 if (_parser.isItThere(targetFitnessParam))
00127 {
00128 fitCont = new eoFitContinue<Indi>
00129 (targetFitnessParam.value());
00130
00131 _state.storeFunctor(fitCont);
00132
00133 continuator = make_combinedContinue<Indi>(continuator, fitCont);
00134 }
00135
00136 #ifndef _MSC_VER
00137
00138 eoCtrlCContinue<Indi> *ctrlCCont;
00139 eoValueParam<bool>& ctrlCParam = _parser.createParam(false, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
00140 if (ctrlCParam.value())
00141 {
00142 ctrlCCont = new eoCtrlCContinue<Indi>;
00143
00144 _state.storeFunctor(ctrlCCont);
00145
00146 continuator = make_combinedContinue<Indi>(continuator, ctrlCCont);
00147 }
00148 #endif
00149
00150
00151 if (!continuator)
00152 throw std::runtime_error("You MUST provide a stopping criterion");
00153
00154 _state.storeFunctor(continuator);
00155
00156
00157 return *continuator;
00158 }
00159
00160 #endif