From fd8a2529a50b3f167347e559891fea7e327b5b15 Mon Sep 17 00:00:00 2001 From: mac Date: Sat, 9 Sep 2000 13:43:31 +0000 Subject: [PATCH] eo: added some missing entries Pop: error in nth_element_fitness sga: error in eval eoParseTree: oddities with gcc checkpointing: added eoParser and eoState eoParser: support for wrongly entered parameter names rnd_generators: flip(0.5) -> flip(bias) in binary_generator selectors.h: ??? --- eo/src/eo | 11 ++++--- eo/src/eoInit.h | 2 +- eo/src/eoPop.h | 2 +- eo/src/eoSGA.h | 2 +- eo/src/utils/checkpointing | 2 ++ eo/src/utils/eoParser.cpp | 55 ++++++++++++++++++++++++++++++++++- eo/src/utils/eoParser.h | 13 +++++---- eo/src/utils/rnd_generators.h | 2 +- eo/src/utils/selectors.h | 2 +- eo/test/t-eoSymreg.cpp | 11 +------ 10 files changed, 77 insertions(+), 25 deletions(-) diff --git a/eo/src/eo b/eo/src/eo index 5b38edac..7a8ae6f3 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -1,6 +1,6 @@ //----------------------------------------------------------------------------- // eo -// (c) GeNeura Team 1998 +// (c) GeNeura Team 1998 - 2000 /* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -20,10 +20,10 @@ */ //----------------------------------------------------------------------------- -#ifndef __GNUG__ +#ifdef _MSC_VER // to avoid long name warnings #pragma warning(disable:4786) -#endif // __GNUG__ +#endif #ifndef _eo_ #define _eo_ @@ -104,13 +104,16 @@ #include #include +// Inserters +#include +#include + // Utils #include // aliens //#include #include -#include //----------------------------------------------------------------------------- // to be continued ... diff --git a/eo/src/eoInit.h b/eo/src/eoInit.h index b6372299..c1f0548d 100644 --- a/eo/src/eoInit.h +++ b/eo/src/eoInit.h @@ -74,7 +74,7 @@ class eoInitVariableLength: public eoInit : offset(_minSize), extent(_maxSize - _minSize), generator(_generator) { if (_minSize >= _maxSize) - throw logical_error("eoInitVariableLength: minSize larger or equal to maxSize"); + throw logic_error("eoInitVariableLength: minSize larger or equal to maxSize"); } void operator()(EOT& chrom) diff --git a/eo/src/eoPop.h b/eo/src/eoPop.h index 8505783c..7d254cb4 100644 --- a/eo/src/eoPop.h +++ b/eo/src/eoPop.h @@ -114,7 +114,7 @@ class eoPop: public vector, public eoObject, public eoPersistent Fitness nth_element_fitness(int which) const { // probably not the fastest way to do this, but what the heck - + vector fitness(size()); std::transform(begin(), end(), fitness.begin(), GetFitness()); diff --git a/eo/src/eoSGA.h b/eo/src/eoSGA.h index 79a402d1..1dcfe610 100644 --- a/eo/src/eoSGA.h +++ b/eo/src/eoSGA.h @@ -79,10 +79,10 @@ public : mutate(offspring[i]); } - eval(offspring[i]); } _pop.swap(offspring); + apply(eval, _pop); } while (cont(_pop)); } diff --git a/eo/src/utils/checkpointing b/eo/src/utils/checkpointing index dba79bce..39178ec3 100644 --- a/eo/src/utils/checkpointing +++ b/eo/src/utils/checkpointing @@ -1,4 +1,6 @@ +#include +#include #include #include #include diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index 07fa0eb5..2487cd67 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -63,7 +63,7 @@ void eoParser::doRegisterParam(eoParam& param) const { if (param.required() && !isItThere(param)) { - string msg = "required parameter: " + param.longName() + " missing"; + string msg = "Required parameter: " + param.longName() + " missing"; messages.push_back(msg); } @@ -274,3 +274,56 @@ void eoParser::printHelp(ostream& os) os << '\n'; } + +bool eoParser::userNeedsHelp(void) +{ + /* + check whether there are long or short names entered + without a corresponding parameter + */ + + for (LongNameMapType::const_iterator lIt = longNameMap.begin(); lIt != longNameMap.end(); ++lIt) + { + string entry = lIt->first; + + MultiMapType::const_iterator it; + + for (it = params.begin(); it != params.end(); ++it) + { + if (entry == it->second->longName()) + { + break; + } + } + + if (it == params.end()) + { + string msg = "Unknown parameter: --" + entry + " entered, type -h or --help to see available parameters"; + messages.push_back(msg); + } + } + + for (ShortNameMapType::const_iterator sIt = shortNameMap.begin(); sIt != shortNameMap.end(); ++sIt) + { + char entry = sIt->first; + + MultiMapType::const_iterator it; + + for (it = params.begin(); it != params.end(); ++it) + { + if (entry == it->second->shortName()) + { + break; + } + } + + if (it == params.end()) + { + string entryString(1, entry); + string msg = "Unknown parameter: -" + entryString + " entered, type -h or --help to see available parameters"; + messages.push_back(msg); + } + } + + return needHelp.value() || !messages.empty(); +} diff --git a/eo/src/utils/eoParser.h b/eo/src/utils/eoParser.h index d65278c5..8af3a11b 100644 --- a/eo/src/utils/eoParser.h +++ b/eo/src/utils/eoParser.h @@ -127,8 +127,7 @@ public: std::string className(void) const { return "Parser"; } /// true if the user made an error or asked for help - bool userNeedsHelp(void) const { return needHelp.value() || !messages.empty(); } - + bool userNeedsHelp(void); /** * Prints an automatic help in the specified output using the information * provided by parameters @@ -148,14 +147,18 @@ private: void updateParameters() const; typedef std::multimap MultiMapType; - + + // used to store all parameters that are processed MultiMapType params; string programName; string programDescription; - map shortNameMap; - map longNameMap; + typedef map ShortNameMapType; + ShortNameMapType shortNameMap; + + typedef map LongNameMapType; + LongNameMapType longNameMap; eoValueParam needHelp; diff --git a/eo/src/utils/rnd_generators.h b/eo/src/utils/rnd_generators.h index a8c6ceb1..17152113 100644 --- a/eo/src/utils/rnd_generators.h +++ b/eo/src/utils/rnd_generators.h @@ -58,7 +58,7 @@ class boolean_generator public : boolean_generator(float _bias = 0.5, eoRng& _rng = rng) : bias(_bias), gen(_rng) {} - bool operator()(void) { return gen.flip(0.5); } + bool operator()(void) { return gen.flip(bias); } private : float bias; eoRng& gen; diff --git a/eo/src/utils/selectors.h b/eo/src/utils/selectors.h index 2d9a3db7..349bf7cc 100644 --- a/eo/src/utils/selectors.h +++ b/eo/src/utils/selectors.h @@ -209,7 +209,7 @@ It inverse_deterministic_tournament(It _begin, It _end, unsigned _t_size, eoRng& { It worst = _begin + _gen.random(_end - _begin); - for (unsigned i = 0; i < _t_size - 1; ++i) + for (unsigned i = 1; i < _t_size; ++i) { It competitor = _begin + _gen.random(_end - _begin); diff --git a/eo/test/t-eoSymreg.cpp b/eo/test/t-eoSymreg.cpp index d2750e17..3f5d62a1 100644 --- a/eo/test/t-eoSymreg.cpp +++ b/eo/test/t-eoSymreg.cpp @@ -3,7 +3,7 @@ #endif #include -#include +#include using namespace gp_parse_tree; using namespace std; @@ -203,15 +203,6 @@ void print_best(eoPop& pop) cout << endl << "RMS Error = " << pop[index].fitness() << endl; } - -#include -#include "eoGOpBreeder.h" -#include "eoSequentialGOpSel.h" -#include "eoProportionalGOpSel.h" -#include "eoDetTournamentInserter.h" -#include "eoSteadyStateEA.h" -#include "eoScalarFitness.h" - int main() { typedef eoMinimizingFitness FitnessType;