eoCounter?
eoEasyEA -- made it copyable again eoEvalFunc -- added specialized eoEvalFuncCounter eoEvolutionStrategy -- nothing much eoGenContinue -- nothing eoPop -- fixed nth_element_fitness eoBitOp -- fixed error in xover eoFileMonitor -- now appends always eoParam -- worked around memory leak in MSC's strstream eoParser -- changed -pconfig_file to @config_file eoParser -- added messages instead of exception when required param is missing eoStat -- added eoDistanceStat t-eoFunctor -- don't know
This commit is contained in:
parent
a7131a7f71
commit
ff108477c3
16 changed files with 222 additions and 83 deletions
|
|
@ -109,6 +109,8 @@
|
||||||
|
|
||||||
// aliens
|
// aliens
|
||||||
//#include <eoNonUniform.h>
|
//#include <eoNonUniform.h>
|
||||||
|
#include <eoCounter.h>
|
||||||
|
#include <utils/eoParser.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// to be continued ...
|
// to be continued ...
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,9 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
eoReplacement<EOT>& _replace
|
eoReplacement<EOT>& _replace
|
||||||
) : continuator(_continuator),
|
) : continuator(_continuator),
|
||||||
eval(_eval),
|
eval(_eval),
|
||||||
selectTransform(0),
|
selectTransform(dummySelect, dummyTransform),
|
||||||
breed(_breed),
|
breed(_breed),
|
||||||
mergeReduce(0),
|
mergeReduce(dummyMerge, dummyReduce),
|
||||||
replace(_replace)
|
replace(_replace)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
@ -70,9 +70,9 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
eoReduce<EOT>& _reduce
|
eoReduce<EOT>& _reduce
|
||||||
) : continuator(_continuator),
|
) : continuator(_continuator),
|
||||||
eval(_eval),
|
eval(_eval),
|
||||||
selectTransform(0),
|
selectTransform(dummySelect, dummyTransform),
|
||||||
breed(_breed),
|
breed(_breed),
|
||||||
mergeReduce(new eoMergeReduce<EOT>(_merge, _reduce)),
|
mergeReduce(_merge, _reduce),
|
||||||
replace(mergeReduce)
|
replace(mergeReduce)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
@ -85,9 +85,9 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
eoReplacement<EOT>& _replace
|
eoReplacement<EOT>& _replace
|
||||||
) : continuator(_continuator),
|
) : continuator(_continuator),
|
||||||
eval(_eval),
|
eval(_eval),
|
||||||
selectTransform(new eoSelectTransform<EOT>(_select, _transform)),
|
selectTransform(_select, _transform),
|
||||||
breed(selectTransform),
|
breed(selectTransform),
|
||||||
mergeReduce(0),
|
mergeReduce(dummyMerge, dummyReduce),
|
||||||
replace(_replace)
|
replace(_replace)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
@ -101,17 +101,15 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
eoReduce<EOT>& _reduce
|
eoReduce<EOT>& _reduce
|
||||||
) : continuator(_continuator),
|
) : continuator(_continuator),
|
||||||
eval(_eval),
|
eval(_eval),
|
||||||
selectTransform(new eoSelectTransform<EOT>(_select, _transform)),
|
selectTransform(_select, _transform),
|
||||||
breed(*selectTransform),
|
breed(selectTransform),
|
||||||
mergeReduce(new eoMergeReduce<EOT>(_merge, _reduce)),
|
mergeReduce(_merge, _reduce),
|
||||||
replace(*mergeReduce)
|
replace(mergeReduce)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
~eoEasyEA() { delete selectTransform; delete mergeReduce; }
|
|
||||||
|
|
||||||
/// Apply a few generation of evolution to the population.
|
/// Apply a few generation of evolution to the population.
|
||||||
virtual void operator()(eoPop<EOT>& _pop)
|
virtual void operator()(eoPop<EOT>& _pop)
|
||||||
{
|
{
|
||||||
|
|
@ -146,16 +144,27 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// dissallow copying cuz of pointer stuff
|
// If selectTransform needs not be used, dummySelect and dummyTransform are used
|
||||||
eoEasyEA(const eoEasyEA&);
|
// to instantiate it.
|
||||||
/// dissallow copying cuz of pointer stuff
|
class eoDummySelect : public eoSelect<EOT>
|
||||||
const eoEasyEA& operator=(const eoEasyEA&);
|
{ public : void operator()(const eoPop<EOT>&, eoPop<EOT>&) {} } dummySelect;
|
||||||
|
|
||||||
|
class eoDummyTransform : public eoTransform<EOT>
|
||||||
|
{ public : void operator()(eoPop<EOT>&) {} } dummyTransform;
|
||||||
|
|
||||||
|
|
||||||
eoContinue<EOT>& continuator;
|
eoContinue<EOT>& continuator;
|
||||||
eoEvalFunc<EOT>& eval;
|
eoEvalFunc<EOT>& eval;
|
||||||
eoSelectTransform<EOT>* selectTransform;
|
|
||||||
|
eoSelectTransform<EOT> selectTransform;
|
||||||
eoBreed<EOT>& breed;
|
eoBreed<EOT>& breed;
|
||||||
eoMergeReduce<EOT>* mergeReduce;
|
|
||||||
|
// If mergeReduce needs not be used, dummyMerge and dummyReduce are used
|
||||||
|
// to instantiate it.
|
||||||
|
eoNoElitism<EOT> dummyMerge;
|
||||||
|
eoTruncate<EOT> dummyReduce;
|
||||||
|
|
||||||
|
eoMergeReduce<EOT> mergeReduce;
|
||||||
eoReplacement<EOT>& replace;
|
eoReplacement<EOT>& replace;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,4 +44,30 @@ template<class EOT> class eoEvalFunc : public eoUnaryFunctor<void, EOT&>
|
||||||
typedef typename EOT::Fitness EOFitT;
|
typedef typename EOT::Fitness EOFitT;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Counts the number of evaluations actually performed, thus checks first
|
||||||
|
if it has to evaluate.. etc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <utils/eoParam.h>
|
||||||
|
template<class EOT> class eoEvalFuncCounter : public eoEvalFunc<EOT>, public eoValueParam<unsigned long>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
eoEvalFuncCounter(eoEvalFunc<EOT>& _func, std::string _name = "eval_counter")
|
||||||
|
: func(_func), eoValueParam<unsigned long>(0, _name) {}
|
||||||
|
|
||||||
|
void operator()(EOT& _eo)
|
||||||
|
{
|
||||||
|
if (_eo.invalid())
|
||||||
|
{
|
||||||
|
value()++;
|
||||||
|
func(_eo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private :
|
||||||
|
eoEvalFunc<EOT>& func;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -81,6 +81,20 @@ class eoEvolutionStrategy: public eoAlgo<EOT>
|
||||||
eoEasyEA<EOT> easyEA;
|
eoEasyEA<EOT> easyEA;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
eoEvolutionStrategy<EOT> make_es(eoContinue<EOT>& _continuator,
|
||||||
|
eoEvalFunc<EOT>& _eval,
|
||||||
|
eoGOpSelector<EOT>& _opSel,
|
||||||
|
float _lambdaRate,
|
||||||
|
bool _comma)
|
||||||
|
|
||||||
|
{
|
||||||
|
if (_comma)
|
||||||
|
return eoEvolutionStrategy<EOT>(_continuator, _eval, _opSel, _lambdaRate, eoEvolutionStrategy<EOT>::comma_strategy());
|
||||||
|
//else
|
||||||
|
return eoEvolutionStrategy<EOT>(_continuator, _eval, _opSel, _lambdaRate, eoEvolutionStrategy<EOT>::plus_strategy());
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif eoSelectTransformReduce_h
|
#endif eoSelectTransformReduce_h
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,13 @@ class eoGenContinue: public eoContinue<EOT>
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ctor for setting a
|
/// Ctor for setting a
|
||||||
eoGenContinue( unsigned _totalGens)
|
eoGenContinue( unsigned long _totalGens)
|
||||||
: repTotalGenerations( _totalGens ),
|
: repTotalGenerations( _totalGens ),
|
||||||
thisGenerationPlaceHolder(0),
|
thisGenerationPlaceHolder(0),
|
||||||
thisGeneration(thisGenerationPlaceHolder){};
|
thisGeneration(thisGenerationPlaceHolder){};
|
||||||
|
|
||||||
/// Ctor for enabling the save/load the no. of generations counted
|
/// Ctor for enabling the save/load the no. of generations counted
|
||||||
eoGenContinue( unsigned _totalGens, unsigned& _currentGen)
|
eoGenContinue( unsigned long _totalGens, unsigned long& _currentGen)
|
||||||
: repTotalGenerations( _totalGens ),
|
: repTotalGenerations( _totalGens ),
|
||||||
thisGenerationPlaceHolder(0),
|
thisGenerationPlaceHolder(0),
|
||||||
thisGeneration(_currentGen){};
|
thisGeneration(_currentGen){};
|
||||||
|
|
@ -57,21 +57,21 @@ public:
|
||||||
|
|
||||||
/** Sets the number of generations to reach
|
/** Sets the number of generations to reach
|
||||||
and sets the current generation to 0 (the begin)*/
|
and sets the current generation to 0 (the begin)*/
|
||||||
virtual void totalGenerations( unsigned _tg ) {
|
virtual void totalGenerations( unsigned long _tg ) {
|
||||||
repTotalGenerations = _tg;
|
repTotalGenerations = _tg;
|
||||||
thisGeneration = 0;
|
thisGeneration = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Returns the number of generations to reach*/
|
/** Returns the number of generations to reach*/
|
||||||
virtual unsigned totalGenerations( )
|
virtual unsigned long totalGenerations( )
|
||||||
{
|
{
|
||||||
return repTotalGenerations;
|
return repTotalGenerations;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned repTotalGenerations;
|
unsigned long repTotalGenerations;
|
||||||
unsigned thisGenerationPlaceHolder;
|
unsigned long thisGenerationPlaceHolder;
|
||||||
unsigned& thisGeneration;
|
unsigned long& thisGeneration;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -113,11 +113,12 @@ class eoPop: public vector<EOT>, public eoObject, public eoPersistent
|
||||||
struct GetFitness { Fitness operator()(const EOT& _eo) const { return _eo.fitness(); } };
|
struct GetFitness { Fitness operator()(const EOT& _eo) const { return _eo.fitness(); } };
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
vector<Fitness> fitness(size());
|
vector<Fitness> fitness(size());
|
||||||
std::transform(begin(), end(), fitness.begin(), GetFitness());
|
std::transform(begin(), end(), fitness.begin(), GetFitness());
|
||||||
|
|
||||||
vector<Fitness>::iterator it = fitness.begin();
|
vector<Fitness>::iterator it = fitness.begin() + which;
|
||||||
std::nth_element(fitness.begin(), it, fitness.end(), greater<Fitness>());
|
std::nth_element(fitness.begin(), it, fitness.end(), greater<Fitness>());
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ template<class Chrom> class eoBinCrossover: public eoQuadraticOp<Chrom>
|
||||||
{
|
{
|
||||||
unsigned site = rng.random(min(chrom1.size(), chrom2.size()));
|
unsigned site = rng.random(min(chrom1.size(), chrom2.size()));
|
||||||
|
|
||||||
if (std::equal(chrom1.begin(), chrom1.begin()+site, chrom2.begin()))
|
if (!std::equal(chrom1.begin(), chrom1.begin()+site, chrom2.begin()))
|
||||||
{
|
{
|
||||||
|
|
||||||
swap_ranges(chrom1.begin(), chrom1.begin() + site, chrom2.begin());
|
swap_ranges(chrom1.begin(), chrom1.begin() + site, chrom2.begin());
|
||||||
|
|
@ -267,6 +267,7 @@ template<class Chrom> class eoBinNxOver: public eoQuadraticOp<Chrom>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** eoBinGxOver --> gene crossover
|
/** eoBinGxOver --> gene crossover
|
||||||
\class eoBinGxOver eoBitOp.h ga/eoBitOp.h
|
\class eoBinGxOver eoBitOp.h ga/eoBitOp.h
|
||||||
\ingroup bitstring
|
\ingroup bitstring
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,8 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
eoMonitor& eoFileMonitor::operator()(void)
|
void eoFileMonitor::printHeader(std::ostream& os)
|
||||||
{
|
{
|
||||||
if (firsttime)
|
|
||||||
{
|
|
||||||
firsttime = false;
|
|
||||||
|
|
||||||
// create file
|
|
||||||
ofstream os(filename.c_str());
|
|
||||||
|
|
||||||
if (!os)
|
|
||||||
{
|
|
||||||
string str = "eoFileMonitor: Could not open " + filename;
|
|
||||||
throw runtime_error(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator it = vec.begin();
|
iterator it = vec.begin();
|
||||||
|
|
||||||
os << (*it)->longName();
|
os << (*it)->longName();
|
||||||
|
|
@ -33,9 +20,25 @@ eoMonitor& eoFileMonitor::operator()(void)
|
||||||
{
|
{
|
||||||
os << ',' << (*it)->longName();
|
os << ',' << (*it)->longName();
|
||||||
}
|
}
|
||||||
|
os << '\n';
|
||||||
}
|
}
|
||||||
// ok, now the real saving. append to file
|
|
||||||
|
|
||||||
|
void eoFileMonitor::printHeader()
|
||||||
|
{
|
||||||
|
// create file
|
||||||
|
ofstream os(filename.c_str());
|
||||||
|
|
||||||
|
if (!os)
|
||||||
|
{
|
||||||
|
string str = "eoFileMonitor: Could not open " + filename;
|
||||||
|
throw runtime_error(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
printHeader(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
eoMonitor& eoFileMonitor::operator()(void)
|
||||||
|
{
|
||||||
ofstream os(filename.c_str(), ios_base::app);
|
ofstream os(filename.c_str(), ios_base::app);
|
||||||
|
|
||||||
if (!os)
|
if (!os)
|
||||||
|
|
@ -44,15 +47,21 @@ eoMonitor& eoFileMonitor::operator()(void)
|
||||||
throw runtime_error(str);
|
throw runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return operator()(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
eoMonitor& eoFileMonitor::operator()(std::ostream& os)
|
||||||
|
{
|
||||||
iterator it = vec.begin();
|
iterator it = vec.begin();
|
||||||
|
|
||||||
os << '\n' << (*it)->getValue();
|
os << (*it)->getValue();
|
||||||
|
|
||||||
for(++it; it != vec.end(); ++it)
|
for(++it; it != vec.end(); ++it)
|
||||||
{
|
{
|
||||||
os << ',' << (*it)->getValue();
|
os << ',' << (*it)->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os << '\n';
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,17 @@
|
||||||
class eoFileMonitor : public eoMonitor
|
class eoFileMonitor : public eoMonitor
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
eoFileMonitor(std::string _filename, std::string _delim = ",") : filename(_filename), delim(_delim), firsttime(true) {}
|
eoFileMonitor(std::string _filename, std::string _delim = ",") : filename(_filename), delim(_delim) {}
|
||||||
eoMonitor& operator()(void);
|
eoMonitor& operator()(void);
|
||||||
|
|
||||||
|
eoMonitor& operator()(std::ostream& os);
|
||||||
|
|
||||||
|
void printHeader(void);
|
||||||
|
virtual void printHeader(std::ostream& os);
|
||||||
|
|
||||||
private :
|
private :
|
||||||
std::string filename;
|
|
||||||
std::string delim;
|
std::string delim;
|
||||||
bool firsttime;
|
std::string filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,8 @@ public :
|
||||||
|
|
||||||
std::string getValue(void) const
|
std::string getValue(void) const
|
||||||
{
|
{
|
||||||
std::ostrstream os;
|
char buf[1024];
|
||||||
|
std::ostrstream os(buf, 1023);
|
||||||
os << repValue;
|
os << repValue;
|
||||||
os << std::ends;
|
os << std::ends;
|
||||||
return os.str();
|
return os.str();
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ eoParameterLoader::~eoParameterLoader()
|
||||||
eoParser::eoParser ( int _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) :
|
eoParser::eoParser ( int _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) :
|
||||||
programName( _argv[0]),
|
programName( _argv[0]),
|
||||||
programDescription( _programDescription),
|
programDescription( _programDescription),
|
||||||
parameterFile("", _lFileParamName, "Load using a configuration file", _shortHand),
|
|
||||||
needHelp(false, "help", "Prints this message", 'h')
|
needHelp(false, "help", "Prints this message", 'h')
|
||||||
{
|
{
|
||||||
strstream stream;
|
strstream stream;
|
||||||
|
|
@ -51,15 +50,7 @@ eoParser::eoParser ( int _argc, char **_argv , string _programDescription, strin
|
||||||
|
|
||||||
readFrom(stream);
|
readFrom(stream);
|
||||||
|
|
||||||
processParam(parameterFile);
|
|
||||||
processParam(needHelp);
|
processParam(needHelp);
|
||||||
|
|
||||||
if (parameterFile.getValue() != parameterFile.defValue())
|
|
||||||
{
|
|
||||||
ifstream is (parameterFile.getValue().c_str());
|
|
||||||
|
|
||||||
readFrom(is);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void eoParser::processParam(eoParam& param, std::string section)
|
void eoParser::processParam(eoParam& param, std::string section)
|
||||||
|
|
@ -72,7 +63,8 @@ void eoParser::doRegisterParam(eoParam& param) const
|
||||||
{
|
{
|
||||||
if (param.required() && !isItThere(param))
|
if (param.required() && !isItThere(param))
|
||||||
{
|
{
|
||||||
throw std::runtime_error("required parameter missing");
|
string msg = "required parameter: " + param.longName() + " missing";
|
||||||
|
messages.push_back(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<bool, string> value = getValue(param);
|
pair<bool, string> value = getValue(param);
|
||||||
|
|
@ -165,6 +157,24 @@ void eoParser::readFrom(istream& is)
|
||||||
shortNameMap[str[1]] = value;
|
shortNameMap[str[1]] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (str[0] == '@')
|
||||||
|
{ // read response file
|
||||||
|
string filename(str.begin() + 1, str.end());
|
||||||
|
|
||||||
|
ifstream ifs (filename.c_str());
|
||||||
|
|
||||||
|
ifs.peek(); // check if it exists
|
||||||
|
|
||||||
|
if (!ifs)
|
||||||
|
{
|
||||||
|
string msg = "Could not open response file: " + filename;
|
||||||
|
throw runtime_error(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read and overwrite
|
||||||
|
readFrom(ifs);
|
||||||
|
break; // stop reading command line
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateParameters();
|
updateParameters();
|
||||||
|
|
@ -214,6 +224,13 @@ void eoParser::printOn(ostream& os) const
|
||||||
|
|
||||||
void eoParser::printHelp(ostream& os)
|
void eoParser::printHelp(ostream& os)
|
||||||
{
|
{
|
||||||
|
if (needHelp.value() == false && !messages.empty())
|
||||||
|
{
|
||||||
|
std::copy(messages.begin(), messages.end(), ostream_iterator<string>(os, "\n"));
|
||||||
|
messages.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// print program name and description
|
// print program name and description
|
||||||
os << this->programName <<": "<< programDescription << "\n\n";
|
os << this->programName <<": "<< programDescription << "\n\n";
|
||||||
|
|
||||||
|
|
@ -253,6 +270,7 @@ void eoParser::printHelp(ostream& os)
|
||||||
os <<". By default: "<<p->second->defValue() << '\n';
|
os <<". By default: "<<p->second->defValue() << '\n';
|
||||||
} // for p
|
} // for p
|
||||||
|
|
||||||
|
os << "\n@param_file \t defines a file where the parameters are stored\n";
|
||||||
os << '\n';
|
os << '\n';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +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(); }
|
bool userNeedsHelp(void) const { return needHelp.value() || !messages.empty(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints an automatic help in the specified output using the information
|
* Prints an automatic help in the specified output using the information
|
||||||
|
|
@ -157,8 +157,9 @@ private:
|
||||||
map<char, string> shortNameMap;
|
map<char, string> shortNameMap;
|
||||||
map<string, string> longNameMap;
|
map<string, string> longNameMap;
|
||||||
|
|
||||||
eoValueParam<string> parameterFile;
|
|
||||||
eoValueParam<bool> needHelp;
|
eoValueParam<bool> needHelp;
|
||||||
|
|
||||||
|
mutable std::vector<std::string> messages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,19 +104,76 @@ public :
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoBestFitnessStat : public eoStat<EOT, typename EOT::Fitness >
|
class eoNthElementFitnessStat : public eoStat<EOT, typename EOT::Fitness >
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
typedef typename EOT::Fitness Fitness;
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
eoBestFitnessStat(std::string _description = "Best Fitness") : eoStat<EOT, Fitness>(Fitness(), _description) {}
|
eoNthElementFitnessStat(int _which, std::string _description = "nth element fitness") : which(_which), eoStat<EOT, Fitness>(Fitness(), _description) {}
|
||||||
|
|
||||||
virtual void operator()(const eoPop<EOT>& _pop)
|
virtual void operator()(const eoPop<EOT>& _pop)
|
||||||
{
|
{
|
||||||
value() = _pop.nth_element_fitness(0);
|
if (which > _pop.size())
|
||||||
|
throw logic_error("fitness requested of element outside of pop");
|
||||||
|
|
||||||
|
value() = _pop.nth_element_fitness(which);
|
||||||
|
}
|
||||||
|
|
||||||
|
private :
|
||||||
|
unsigned which;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
class eoBestFitnessStat : public eoNthElementFitnessStat<EOT>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
|
eoBestFitnessStat(std::string _description = "Best Fitness") : eoNthElementFitnessStat<EOT>(0, _description) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
class eoDistanceStat : public eoStat<EOT, double>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
eoDistanceStat(std::string _name = "distance") : eoStat<EOT, double>(0.0, _name) {}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
double distance(T a, T b)
|
||||||
|
{
|
||||||
|
T res = a-b;
|
||||||
|
return res < 0? -res : res;
|
||||||
|
}
|
||||||
|
|
||||||
|
double distance(bool a, bool b)
|
||||||
|
{
|
||||||
|
return (a==b)? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator()(const eoPop<EOT>& _pop)
|
||||||
|
{
|
||||||
|
double& v = value();
|
||||||
|
v = 0.0;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||||
|
{
|
||||||
|
for (unsigned j = 0; j < _pop.size(); ++j)
|
||||||
|
{
|
||||||
|
for (unsigned k = 0; k < _pop[i].size(); ++k)
|
||||||
|
{
|
||||||
|
v += distance(_pop[i][k], _pop[j][k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double sz = _pop.size();
|
||||||
|
v /= sz * sz * _pop[0].size();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoStdevStat : public eoStat<EOT, double >
|
class eoStdevStat : public eoStat<EOT, double >
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ public :
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <eoTranspose.h>
|
|
||||||
#include <eoFixedLength.h>
|
#include <eoFixedLength.h>
|
||||||
#include <eoVariableLength.h>
|
#include <eoVariableLength.h>
|
||||||
|
|
||||||
|
|
@ -46,8 +45,5 @@ int main(void)
|
||||||
eo.push_back(1);
|
eo.push_back(1);
|
||||||
eo.push_back(2);
|
eo.push_back(2);
|
||||||
|
|
||||||
eoTranspose<EoType> transpose;
|
|
||||||
transpose(eo);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ RSC=rc.exe
|
||||||
# PROP Intermediate_Dir "Release"
|
# PROP Intermediate_Dir "Release"
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
# ADD CPP /nologo /W3 /GR /GX /O2 /I "../src" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FD /c
|
# ADD CPP /nologo /W3 /GR /GX /O2 /I "../src" /I "eo/src" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FD /c
|
||||||
# SUBTRACT CPP /YX
|
# SUBTRACT CPP /YX
|
||||||
# ADD BASE RSC /l 0xc0a /d "NDEBUG"
|
# ADD BASE RSC /l 0xc0a /d "NDEBUG"
|
||||||
# ADD RSC /l 0xc0a /d "NDEBUG"
|
# ADD RSC /l 0xc0a /d "NDEBUG"
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ RSC=rc.exe
|
||||||
# PROP Intermediate_Dir "t_eoFunctor___Win32_Release"
|
# PROP Intermediate_Dir "t_eoFunctor___Win32_Release"
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
# ADD CPP /nologo /W3 /GX /O2 /I "../src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
|
|
|
||||||
Reference in a new issue