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:
parent
fc172ef858
commit
fd8a2529a5
10 changed files with 77 additions and 25 deletions
11
eo/src/eo
11
eo/src/eo
|
|
@ -1,6 +1,6 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eo
|
// eo
|
||||||
// (c) GeNeura Team 1998
|
// (c) GeNeura Team 1998 - 2000
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
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
|
// to avoid long name warnings
|
||||||
#pragma warning(disable:4786)
|
#pragma warning(disable:4786)
|
||||||
#endif // __GNUG__
|
#endif
|
||||||
|
|
||||||
#ifndef _eo_
|
#ifndef _eo_
|
||||||
#define _eo_
|
#define _eo_
|
||||||
|
|
@ -104,13 +104,16 @@
|
||||||
#include <eoSteadyStateEA.h>
|
#include <eoSteadyStateEA.h>
|
||||||
#include <eoEvolutionStrategy.h>
|
#include <eoEvolutionStrategy.h>
|
||||||
|
|
||||||
|
// Inserters
|
||||||
|
#include <eoDetTournamentInserter.h>
|
||||||
|
#include <eoStochTournamentInserter.h>
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
#include <utils/checkpointing>
|
#include <utils/checkpointing>
|
||||||
|
|
||||||
// aliens
|
// aliens
|
||||||
//#include <eoNonUniform.h>
|
//#include <eoNonUniform.h>
|
||||||
#include <eoCounter.h>
|
#include <eoCounter.h>
|
||||||
#include <utils/eoParser.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// to be continued ...
|
// to be continued ...
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ class eoInitVariableLength: public eoInit<EOT>
|
||||||
: offset(_minSize), extent(_maxSize - _minSize), generator(_generator)
|
: offset(_minSize), extent(_maxSize - _minSize), generator(_generator)
|
||||||
{
|
{
|
||||||
if (_minSize >= _maxSize)
|
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)
|
void operator()(EOT& chrom)
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ class eoPop: public vector<EOT>, public eoObject, public eoPersistent
|
||||||
|
|
||||||
Fitness nth_element_fitness(int which) const
|
Fitness nth_element_fitness(int which) const
|
||||||
{ // probably not the fastest way to do this, but what the heck
|
{ // probably not the fastest way to do this, but what the heck
|
||||||
|
|
||||||
vector<Fitness> fitness(size());
|
vector<Fitness> fitness(size());
|
||||||
std::transform(begin(), end(), fitness.begin(), GetFitness());
|
std::transform(begin(), end(), fitness.begin(), GetFitness());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,10 +79,10 @@ public :
|
||||||
mutate(offspring[i]);
|
mutate(offspring[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(offspring[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_pop.swap(offspring);
|
_pop.swap(offspring);
|
||||||
|
apply<EOT>(eval, _pop);
|
||||||
|
|
||||||
} while (cont(_pop));
|
} while (cont(_pop));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
|
#include <utils/eoParser.h>
|
||||||
|
#include <utils/eoState.h>
|
||||||
#include <utils/eoUpdater.h>
|
#include <utils/eoUpdater.h>
|
||||||
#include <utils/eoMonitor.h>
|
#include <utils/eoMonitor.h>
|
||||||
#include <utils/eoFileMonitor.h>
|
#include <utils/eoFileMonitor.h>
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ void eoParser::doRegisterParam(eoParam& param) const
|
||||||
{
|
{
|
||||||
if (param.required() && !isItThere(param))
|
if (param.required() && !isItThere(param))
|
||||||
{
|
{
|
||||||
string msg = "required parameter: " + param.longName() + " missing";
|
string msg = "Required parameter: " + param.longName() + " missing";
|
||||||
messages.push_back(msg);
|
messages.push_back(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,3 +274,56 @@ void eoParser::printHelp(ostream& os)
|
||||||
os << '\n';
|
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();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,7 @@ public:
|
||||||
std::string className(void) const { return "Parser"; }
|
std::string className(void) const { return "Parser"; }
|
||||||
|
|
||||||
/// true if the user made an error or asked for help
|
/// 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
|
* Prints an automatic help in the specified output using the information
|
||||||
* provided by parameters
|
* provided by parameters
|
||||||
|
|
@ -148,14 +147,18 @@ private:
|
||||||
void updateParameters() const;
|
void updateParameters() const;
|
||||||
|
|
||||||
typedef std::multimap<std::string, eoParam*> MultiMapType;
|
typedef std::multimap<std::string, eoParam*> MultiMapType;
|
||||||
|
|
||||||
|
// used to store all parameters that are processed
|
||||||
MultiMapType params;
|
MultiMapType params;
|
||||||
|
|
||||||
string programName;
|
string programName;
|
||||||
string programDescription;
|
string programDescription;
|
||||||
|
|
||||||
map<char, string> shortNameMap;
|
typedef map<char, string> ShortNameMapType;
|
||||||
map<string, string> longNameMap;
|
ShortNameMapType shortNameMap;
|
||||||
|
|
||||||
|
typedef map<string, string> LongNameMapType;
|
||||||
|
LongNameMapType longNameMap;
|
||||||
|
|
||||||
eoValueParam<bool> needHelp;
|
eoValueParam<bool> needHelp;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class boolean_generator
|
||||||
public :
|
public :
|
||||||
boolean_generator(float _bias = 0.5, eoRng& _rng = rng) : bias(_bias), gen(_rng) {}
|
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 :
|
private :
|
||||||
float bias;
|
float bias;
|
||||||
eoRng& gen;
|
eoRng& gen;
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ It inverse_deterministic_tournament(It _begin, It _end, unsigned _t_size, eoRng&
|
||||||
{
|
{
|
||||||
It worst = _begin + _gen.random(_end - _begin);
|
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);
|
It competitor = _begin + _gen.random(_end - _begin);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <gp/eoParseTree.h>
|
#include <gp/eoParseTree.h>
|
||||||
#include <eoEvalFunc.h>
|
#include <eo>
|
||||||
|
|
||||||
using namespace gp_parse_tree;
|
using namespace gp_parse_tree;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -203,15 +203,6 @@ void print_best(eoPop<EOT>& pop)
|
||||||
cout << endl << "RMS Error = " << pop[index].fitness() << endl;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
typedef eoMinimizingFitness FitnessType;
|
typedef eoMinimizingFitness FitnessType;
|
||||||
|
|
|
||||||
Reference in a new issue