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: ???
This commit is contained in:
mac 2000-09-09 13:43:31 +00:00
commit fd8a2529a5
10 changed files with 77 additions and 25 deletions

View file

@ -1,4 +1,6 @@
#include <utils/eoParser.h>
#include <utils/eoState.h>
#include <utils/eoUpdater.h>
#include <utils/eoMonitor.h>
#include <utils/eoFileMonitor.h>

View file

@ -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();
}

View file

@ -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<std::string, eoParam*> MultiMapType;
// used to store all parameters that are processed
MultiMapType params;
string programName;
string programDescription;
map<char, string> shortNameMap;
map<string, string> longNameMap;
typedef map<char, string> ShortNameMapType;
ShortNameMapType shortNameMap;
typedef map<string, string> LongNameMapType;
LongNameMapType longNameMap;
eoValueParam<bool> needHelp;

View file

@ -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;

View file

@ -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);