diff --git a/eo/src/eoCombinedContinue.h b/eo/src/eoCombinedContinue.h index aff47ce57..2420288f0 100644 --- a/eo/src/eoCombinedContinue.h +++ b/eo/src/eoCombinedContinue.h @@ -31,8 +31,8 @@ Combined continuators - logical AND: Continues until one of the embedded continuators says halt! -20/11/00 MS: Changed the 2-continuator construct to a vector > - to be consistent with other Combined constructs +20/11/00 MS: Changed the 2-continuator construct to a vector > + to be consistent with other Combined constructs and allow to easily handle more than 2 continuators */ @@ -43,29 +43,29 @@ public: /// Define Fitness typedef typename EOT::Fitness FitnessType; - /// Ctor + /// Ctor, make sure that at least on continuator is present eoCombinedContinue( eoContinue& _cont) : eoContinue () - { - continuators.push_back(&_cont); + { + continuators.push_back(&_cont); } /// Ctor - for historical reasons ... should disspear some day eoCombinedContinue( eoContinue& _cont1, eoContinue& _cont2) : eoContinue () - { - continuators.push_back(&_cont1); - continuators.push_back(&_cont2); + { + continuators.push_back(&_cont1); + continuators.push_back(&_cont2); } - void add(eoContinue & _cont) - { - continuators.push_back(&_cont); + void add(eoContinue & _cont) + { + continuators.push_back(&_cont); } /** Returns false when one of the embedded continuators say so (logical and) */ - virtual bool operator() ( const eoPop& _pop ) + virtual bool operator() ( const eoPop& _pop ) { for (unsigned i = 0; i < continuators.size(); ++i) if ( !(*continuators[i])(_pop) ) return false; diff --git a/eo/src/utils/eoFDCStat.h b/eo/src/utils/eoFDCStat.h index ed34cc0ff..eaee82f23 100644 --- a/eo/src/utils/eoFDCStat.h +++ b/eo/src/utils/eoFDCStat.h @@ -32,7 +32,7 @@ #include /** - The FDC computation - stores the values into eoValueParam + The FDC computation - stores the values into eoValueParam so they can be snapshot by some eoGnuplotSnapshot ... */ template @@ -46,9 +46,9 @@ public : /** Ctor with the optimum */ - eoFDCStat(eoDistance & _dist, EOT & _theBest, + eoFDCStat(eoDistance & _dist, EOT & _theBest, std::string _description = "FDC") : - eoStat(0, _description), dist(_dist), + eoStat(0, _description), dist(_dist), theBest(_theBest), boolOpt(true) {} /** Compute the FDC - either from best in pop, or from absolute best @@ -56,7 +56,7 @@ public : */ virtual void operator()(const eoPop& _pop) { - if (!boolOpt) // take the local best + if (!boolOpt) // take the local best theBest = _pop.best_element(); unsigned int pSize = _pop.size(); distToBest.value().resize(pSize); @@ -109,24 +109,24 @@ class eoFDCFileSnapshot : public eoFileSnapshot // is an eoMonitor { public: /** Ctor: in addition to the parameters of the ctor of an eoFileSnapshot - we need here an eoFDCStat. The 2 vectors (distances to optimum + we need here an eoFDCStat. The 2 vectors (distances to optimum and fitnesses) are added to the monitor so they can be processed later to a file - and eventually by gnuplot */ - eoFDCFileSnapshot(eoFDCStat & _FDCstat, - std::string _dirname = "tmpFDC", unsigned _frequency = 1, + eoFDCFileSnapshot(eoFDCStat & _FDCstat, + std::string _dirname = "tmpFDC", unsigned _frequency = 1, std::string _filename = "FDC", std::string _delim = " "): - eoFileSnapshot(_dirname, _frequency, _filename, _delim), - FDCstat(_FDCstat) + eoFileSnapshot(_dirname, _frequency, _filename, _delim), + FDCstat(_FDCstat) { - eoMonitor::add(FDCstat.theDist()); - eoMonitor::add(FDCstat.theFit()); + eoFileSnapshot::add(FDCstat.theDist()); + eoFileSnapshot::add(FDCstat.theFit()); } /** just to be sure the add method is not called further */ - virtual void add(const eoParam& _param) - { throw runtime_error("Trying to add stats to an eoFDCFileSnapshot"); } + virtual void add(const eoParam& _param) + { throw runtime_error("eoFDCFileSnapshot::add(). Trying to add stats to an eoFDCFileSnapshot"); } private: eoFDCStat & FDCstat; diff --git a/eo/src/utils/eoFileSnapshot.h b/eo/src/utils/eoFileSnapshot.h index 910b73feb..b5eb55e6b 100644 --- a/eo/src/utils/eoFileSnapshot.h +++ b/eo/src/utils/eoFileSnapshot.h @@ -166,7 +166,7 @@ public : { if (!dynamic_cast >*>(&_param)) { - throw logic_error("eoFileSnapshot: I can only monitor vectors of doubles, sorry"); + throw logic_error(string("eoFileSnapshot: I can only monitor vectors of doubles, sorry. The offending parameter name = ") + _param.longName()); } eoMonitor::add(_param); } diff --git a/eo/src/utils/eoParam.h b/eo/src/utils/eoParam.h index 26db85271..b611d84db 100644 --- a/eo/src/utils/eoParam.h +++ b/eo/src/utils/eoParam.h @@ -138,16 +138,16 @@ public : * @param _shortName Short name of the argument (Optional) * @param _required If it is a necessary parameter or not */ - eoValueParam (ValueType _defaultValue, - std::string _longName, - std::string _description = "No description", + eoValueParam (ValueType _defaultValue, + std::string _longName, + std::string _description = "No description", char _shortHand = 0, bool _required = false) : eoParam(_longName, "", _description, _shortHand, _required), repValue(_defaultValue) { eoParam::defValue(getValue()); } - + ValueType& value() { return repValue; } ValueType value() const { return repValue; } @@ -157,9 +157,9 @@ public : std::ostrstream os(buf, 1023); os << repValue; os << std::ends; - return os.str(); + return os.str(); } - + void setValue(std::string _value) { std::istrstream is(_value.c_str()); @@ -170,6 +170,16 @@ private : ValueType repValue; }; +/* + Specialization for string +*/ +template <> +std::string eoValueParam::getValue(void) const +{ + return repValue; +} + + template <> void eoValueParam::setValue(std::string _value) { @@ -290,9 +300,9 @@ void eoValueParam >::setValue(std::string _valu class eoContainerParam : public eoParam { public : - eoContainerParam (ContainerType& value, string _shortName, string _longName, - string _default, - string _description, + eoContainerParam (ContainerType& value, string _shortName, string _longName, + string _default, + string _description, bool _required, bool _change ) : value(_value), eoParam(_shortName, _longName, _description, _default, _required, _change) diff --git a/eo/src/utils/eoScalarFitnessStat.h b/eo/src/utils/eoScalarFitnessStat.h index 1511e6b90..acfcae5d8 100644 --- a/eo/src/utils/eoScalarFitnessStat.h +++ b/eo/src/utils/eoScalarFitnessStat.h @@ -33,11 +33,11 @@ The fitnesses of a whole population, as a vector */ template -class eoScalarFitnessStat : public eoSortedStat > +class eoScalarFitnessStat : public eoSortedStat > { public : - eoScalarFitnessStat(std::string _description = "FitnessES") : - eoSortedStat >(vector(0), _description) {} + eoScalarFitnessStat(std::string _description = "FitnessES") : + eoSortedStat >(vector(0), _description) {} virtual void operator()(const vector& _popPters) { diff --git a/eo/tutorial/Lesson3/exercise3.1.cpp b/eo/tutorial/Lesson3/exercise3.1.cpp index c4c94030e..a4d0609e2 100644 --- a/eo/tutorial/Lesson3/exercise3.1.cpp +++ b/eo/tutorial/Lesson3/exercise3.1.cpp @@ -64,7 +64,7 @@ void main_function(int argc, char **argv) eoValueParam loadNameParam("", "Load","A save file to restart from",'L'); parser.processParam( loadNameParam, "Persistence" ); string loadName = loadNameParam.value(); - + eoValueParam maxGenParam(500, "maxGen", "Maximum number of generations",'G'); parser.processParam( maxGenParam, "Stopping criterion" ); unsigned maxGen = maxGenParam.value(); @@ -196,7 +196,7 @@ void main_function(int argc, char **argv) // generational replacement at the moment :-) eoGenerationalReplacement replace; // want to add (weak) elitism? easy! - // rename the eoGenerationalReplacement replace_main, + // rename the eoGenerationalReplacement replace_main, // then encapsulate it in the elitist replacement // eoWeakElitistReplacement replace(replace_main); @@ -285,7 +285,7 @@ void main_function(int argc, char **argv) // when called by the checkpoint (i.e. at every generation) checkpoint.add(monitor); - // the monitor will output a series of parameters: add them + // the monitor will output a series of parameters: add them monitor.add(generationCounter); monitor.add(eval); // because now eval is an eoEvalFuncCounter! monitor.add(bestStat); @@ -302,7 +302,7 @@ void main_function(int argc, char **argv) eoFileMonitor fileMonitor("stats.xg", " "); // and an eoGnuplot1DMonitor will 1-print to a file, and 2- plot on screen eoGnuplot1DMonitor gnuMonitor("best_average.xg",minimizing_fitness()); - + // the checkpoint mechanism can handle multiple monitors checkpoint.add(fileMonitor); checkpoint.add(gnuMonitor); @@ -318,10 +318,10 @@ void main_function(int argc, char **argv) // send a scaling command to gnuplot gnuMonitor.gnuplotCommand("set yrange [0:500]"); - /* + // a specific plot monitor for FDC // first into a file (it adds everything ti itself - eoFDCFileSnapshot fdcFileSnapshot(fdcStat); + eoFDCFileSnapshot fdcFileSnapshot(fdcStat); // then to a Gnuplot monitor eoGnuplot1DSnapshot fdcGnuplot(fdcFileSnapshot); // and of coruse add them to the checkPoint @@ -331,14 +331,14 @@ void main_function(int argc, char **argv) // want to see how the fitness is spread? eoScalarFitnessStat fitStat; checkpoint.add(fitStat); - // a gnuplot-based monitor for snapshots: needs a dir name + // a gnuplot-based monitor for snapshots: needs a dir name // where to store the files eoGnuplot1DSnapshot fitSnapshot("Fitnesses"); // add any stat that is a vector to it fitSnapshot.add(fitStat); // and of course add it to the checkpoint checkpoint.add(fitSnapshot); - */ + // Last type of item the eoCheckpoint can handle: state savers: eoState outState; // Register the algorithm into the state (so it has something to save!!)