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