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,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 <eoSteadyStateEA.h>
#include <eoEvolutionStrategy.h>
// Inserters
#include <eoDetTournamentInserter.h>
#include <eoStochTournamentInserter.h>
// Utils
#include <utils/checkpointing>
// aliens
//#include <eoNonUniform.h>
#include <eoCounter.h>
#include <utils/eoParser.h>
//-----------------------------------------------------------------------------
// to be continued ...

View file

@ -74,7 +74,7 @@ class eoInitVariableLength: public eoInit<EOT>
: 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)

View file

@ -114,7 +114,7 @@ class eoPop: public vector<EOT>, 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> fitness(size());
std::transform(begin(), end(), fitness.begin(), GetFitness());

View file

@ -79,10 +79,10 @@ public :
mutate(offspring[i]);
}
eval(offspring[i]);
}
_pop.swap(offspring);
apply<EOT>(eval, _pop);
} while (cont(_pop));
}

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

View file

@ -3,7 +3,7 @@
#endif
#include <gp/eoParseTree.h>
#include <eoEvalFunc.h>
#include <eo>
using namespace gp_parse_tree;
using namespace std;
@ -203,15 +203,6 @@ void print_best(eoPop<EOT>& pop)
cout << endl << "RMS Error = " << pop[index].fitness() << endl;
}
#include <eo>
#include "eoGOpBreeder.h"
#include "eoSequentialGOpSel.h"
#include "eoProportionalGOpSel.h"
#include "eoDetTournamentInserter.h"
#include "eoSteadyStateEA.h"
#include "eoScalarFitness.h"
int main()
{
typedef eoMinimizingFitness FitnessType;