eoParam, added specialization for eoValueParam<string>::getValue
FDCStat and FileSnapshot: better error messageing Scalar fitness: is now a vector of doubles exercise3.1 added gnuplot again Don't know about eoCombinedContinue
This commit is contained in:
parent
434010d221
commit
195ad72838
6 changed files with 56 additions and 46 deletions
|
|
@ -31,8 +31,8 @@
|
|||
Combined continuators - logical AND:
|
||||
Continues until one of the embedded continuators says halt!
|
||||
|
||||
20/11/00 MS: Changed the 2-continuator construct to a vector<eoContinue<EOT> >
|
||||
to be consistent with other Combined constructs
|
||||
20/11/00 MS: Changed the 2-continuator construct to a vector<eoContinue<EOT> >
|
||||
to be consistent with other Combined constructs
|
||||
and allow to easily handle more than 2 continuators
|
||||
*/
|
||||
|
||||
|
|
@ -43,29 +43,29 @@ public:
|
|||
/// Define Fitness
|
||||
typedef typename EOT::Fitness FitnessType;
|
||||
|
||||
/// Ctor
|
||||
/// Ctor, make sure that at least on continuator is present
|
||||
eoCombinedContinue( eoContinue<EOT>& _cont)
|
||||
: eoContinue<EOT> ()
|
||||
{
|
||||
continuators.push_back(&_cont);
|
||||
{
|
||||
continuators.push_back(&_cont);
|
||||
}
|
||||
|
||||
/// Ctor - for historical reasons ... should disspear some day
|
||||
eoCombinedContinue( eoContinue<EOT>& _cont1, eoContinue<EOT>& _cont2)
|
||||
: eoContinue<EOT> ()
|
||||
{
|
||||
continuators.push_back(&_cont1);
|
||||
continuators.push_back(&_cont2);
|
||||
{
|
||||
continuators.push_back(&_cont1);
|
||||
continuators.push_back(&_cont2);
|
||||
}
|
||||
|
||||
void add(eoContinue<EOT> & _cont)
|
||||
{
|
||||
continuators.push_back(&_cont);
|
||||
void add(eoContinue<EOT> & _cont)
|
||||
{
|
||||
continuators.push_back(&_cont);
|
||||
}
|
||||
|
||||
/** Returns false when one of the embedded continuators say so (logical and)
|
||||
*/
|
||||
virtual bool operator() ( const eoPop<EOT>& _pop )
|
||||
virtual bool operator() ( const eoPop<EOT>& _pop )
|
||||
{
|
||||
for (unsigned i = 0; i < continuators.size(); ++i)
|
||||
if ( !(*continuators[i])(_pop) ) return false;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#include <utils/eoFileSnapshot.h>
|
||||
|
||||
/**
|
||||
The FDC computation - stores the values into eoValueParam<EOT,double>
|
||||
The FDC computation - stores the values into eoValueParam<EOT,double>
|
||||
so they can be snapshot by some eoGnuplotSnapshot ...
|
||||
*/
|
||||
template <class EOT>
|
||||
|
|
@ -46,9 +46,9 @@ public :
|
|||
|
||||
/** Ctor with the optimum
|
||||
*/
|
||||
eoFDCStat(eoDistance<EOT> & _dist, EOT & _theBest,
|
||||
eoFDCStat(eoDistance<EOT> & _dist, EOT & _theBest,
|
||||
std::string _description = "FDC") :
|
||||
eoStat<EOT,double>(0, _description), dist(_dist),
|
||||
eoStat<EOT,double>(0, _description), dist(_dist),
|
||||
theBest(_theBest), boolOpt(true) {}
|
||||
|
||||
/** Compute the FDC - either from best in pop, or from absolute best
|
||||
|
|
@ -56,7 +56,7 @@ public :
|
|||
*/
|
||||
virtual void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
if (!boolOpt) // take the local best
|
||||
if (!boolOpt) // take the local best
|
||||
theBest = _pop.best_element();
|
||||
unsigned int pSize = _pop.size();
|
||||
distToBest.value().resize(pSize);
|
||||
|
|
@ -109,24 +109,24 @@ class eoFDCFileSnapshot : public eoFileSnapshot // is an eoMonitor
|
|||
{
|
||||
public:
|
||||
/** Ctor: in addition to the parameters of the ctor of an eoFileSnapshot
|
||||
we need here an eoFDCStat. The 2 vectors (distances to optimum
|
||||
we need here an eoFDCStat. The 2 vectors (distances to optimum
|
||||
and fitnesses) are added to the monitor so they can be processed
|
||||
later to a file - and eventually by gnuplot
|
||||
*/
|
||||
eoFDCFileSnapshot(eoFDCStat<EOT> & _FDCstat,
|
||||
std::string _dirname = "tmpFDC", unsigned _frequency = 1,
|
||||
eoFDCFileSnapshot(eoFDCStat<EOT> & _FDCstat,
|
||||
std::string _dirname = "tmpFDC", unsigned _frequency = 1,
|
||||
std::string _filename = "FDC", std::string _delim = " "):
|
||||
eoFileSnapshot(_dirname, _frequency, _filename, _delim),
|
||||
FDCstat(_FDCstat)
|
||||
eoFileSnapshot(_dirname, _frequency, _filename, _delim),
|
||||
FDCstat(_FDCstat)
|
||||
{
|
||||
eoMonitor::add(FDCstat.theDist());
|
||||
eoMonitor::add(FDCstat.theFit());
|
||||
eoFileSnapshot::add(FDCstat.theDist());
|
||||
eoFileSnapshot::add(FDCstat.theFit());
|
||||
}
|
||||
|
||||
/** just to be sure the add method is not called further
|
||||
*/
|
||||
virtual void add(const eoParam& _param)
|
||||
{ throw runtime_error("Trying to add stats to an eoFDCFileSnapshot"); }
|
||||
virtual void add(const eoParam& _param)
|
||||
{ throw runtime_error("eoFDCFileSnapshot::add(). Trying to add stats to an eoFDCFileSnapshot"); }
|
||||
|
||||
private:
|
||||
eoFDCStat<EOT> & FDCstat;
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ public :
|
|||
{
|
||||
if (!dynamic_cast<const eoValueParam<vector<double> >*>(&_param))
|
||||
{
|
||||
throw logic_error("eoFileSnapshot: I can only monitor vectors of doubles, sorry");
|
||||
throw logic_error(string("eoFileSnapshot: I can only monitor vectors of doubles, sorry. The offending parameter name = ") + _param.longName());
|
||||
}
|
||||
eoMonitor::add(_param);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,16 +138,16 @@ public :
|
|||
* @param _shortName Short name of the argument (Optional)
|
||||
* @param _required If it is a necessary parameter or not
|
||||
*/
|
||||
eoValueParam (ValueType _defaultValue,
|
||||
std::string _longName,
|
||||
std::string _description = "No description",
|
||||
eoValueParam (ValueType _defaultValue,
|
||||
std::string _longName,
|
||||
std::string _description = "No description",
|
||||
char _shortHand = 0,
|
||||
bool _required = false)
|
||||
: eoParam(_longName, "", _description, _shortHand, _required), repValue(_defaultValue)
|
||||
{
|
||||
eoParam::defValue(getValue());
|
||||
}
|
||||
|
||||
|
||||
ValueType& value() { return repValue; }
|
||||
ValueType value() const { return repValue; }
|
||||
|
||||
|
|
@ -157,9 +157,9 @@ public :
|
|||
std::ostrstream os(buf, 1023);
|
||||
os << repValue;
|
||||
os << std::ends;
|
||||
return os.str();
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
void setValue(std::string _value)
|
||||
{
|
||||
std::istrstream is(_value.c_str());
|
||||
|
|
@ -170,6 +170,16 @@ private :
|
|||
ValueType repValue;
|
||||
};
|
||||
|
||||
/*
|
||||
Specialization for string
|
||||
*/
|
||||
template <>
|
||||
std::string eoValueParam<std::string>::getValue(void) const
|
||||
{
|
||||
return repValue;
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
void eoValueParam<bool>::setValue(std::string _value)
|
||||
{
|
||||
|
|
@ -290,9 +300,9 @@ void eoValueParam<std::vector<eoMinimizingFitness> >::setValue(std::string _valu
|
|||
class eoContainerParam : public eoParam
|
||||
{
|
||||
public :
|
||||
eoContainerParam (ContainerType& value, string _shortName, string _longName,
|
||||
string _default,
|
||||
string _description,
|
||||
eoContainerParam (ContainerType& value, string _shortName, string _longName,
|
||||
string _default,
|
||||
string _description,
|
||||
bool _required,
|
||||
bool _change )
|
||||
: value(_value), eoParam(_shortName, _longName, _description, _default, _required, _change)
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@
|
|||
The fitnesses of a whole population, as a vector
|
||||
*/
|
||||
template <class EOT, class FitT = typename EOT::Fitness>
|
||||
class eoScalarFitnessStat : public eoSortedStat<EOT, vector<FitT> >
|
||||
class eoScalarFitnessStat : public eoSortedStat<EOT, vector<double> >
|
||||
{
|
||||
public :
|
||||
eoScalarFitnessStat(std::string _description = "FitnessES") :
|
||||
eoSortedStat<EOT, vector<FitT> >(vector<FitT>(0), _description) {}
|
||||
eoScalarFitnessStat(std::string _description = "FitnessES") :
|
||||
eoSortedStat<EOT, vector<double> >(vector<double>(0), _description) {}
|
||||
|
||||
virtual void operator()(const vector<const EOT*>& _popPters)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ void main_function(int argc, char **argv)
|
|||
eoValueParam<string> loadNameParam("", "Load","A save file to restart from",'L');
|
||||
parser.processParam( loadNameParam, "Persistence" );
|
||||
string loadName = loadNameParam.value();
|
||||
|
||||
|
||||
eoValueParam<unsigned int> maxGenParam(500, "maxGen", "Maximum number of generations",'G');
|
||||
parser.processParam( maxGenParam, "Stopping criterion" );
|
||||
unsigned maxGen = maxGenParam.value();
|
||||
|
|
@ -196,7 +196,7 @@ void main_function(int argc, char **argv)
|
|||
// generational replacement at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
// want to add (weak) elitism? easy!
|
||||
// rename the eoGenerationalReplacement replace_main,
|
||||
// rename the eoGenerationalReplacement replace_main,
|
||||
// then encapsulate it in the elitist replacement
|
||||
// eoWeakElitistReplacement<Indi> replace(replace_main);
|
||||
|
||||
|
|
@ -285,7 +285,7 @@ void main_function(int argc, char **argv)
|
|||
// when called by the checkpoint (i.e. at every generation)
|
||||
checkpoint.add(monitor);
|
||||
|
||||
// the monitor will output a series of parameters: add them
|
||||
// the monitor will output a series of parameters: add them
|
||||
monitor.add(generationCounter);
|
||||
monitor.add(eval); // because now eval is an eoEvalFuncCounter!
|
||||
monitor.add(bestStat);
|
||||
|
|
@ -302,7 +302,7 @@ void main_function(int argc, char **argv)
|
|||
eoFileMonitor fileMonitor("stats.xg", " ");
|
||||
// and an eoGnuplot1DMonitor will 1-print to a file, and 2- plot on screen
|
||||
eoGnuplot1DMonitor gnuMonitor("best_average.xg",minimizing_fitness<Indi>());
|
||||
|
||||
|
||||
// the checkpoint mechanism can handle multiple monitors
|
||||
checkpoint.add(fileMonitor);
|
||||
checkpoint.add(gnuMonitor);
|
||||
|
|
@ -318,10 +318,10 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// send a scaling command to gnuplot
|
||||
gnuMonitor.gnuplotCommand("set yrange [0:500]");
|
||||
/*
|
||||
|
||||
// a specific plot monitor for FDC
|
||||
// first into a file (it adds everything ti itself
|
||||
eoFDCFileSnapshot<Indi> fdcFileSnapshot(fdcStat);
|
||||
eoFDCFileSnapshot<Indi> fdcFileSnapshot(fdcStat);
|
||||
// then to a Gnuplot monitor
|
||||
eoGnuplot1DSnapshot fdcGnuplot(fdcFileSnapshot);
|
||||
// and of coruse add them to the checkPoint
|
||||
|
|
@ -331,14 +331,14 @@ void main_function(int argc, char **argv)
|
|||
// want to see how the fitness is spread?
|
||||
eoScalarFitnessStat<Indi> fitStat;
|
||||
checkpoint.add(fitStat);
|
||||
// a gnuplot-based monitor for snapshots: needs a dir name
|
||||
// a gnuplot-based monitor for snapshots: needs a dir name
|
||||
// where to store the files
|
||||
eoGnuplot1DSnapshot fitSnapshot("Fitnesses");
|
||||
// add any stat that is a vector<double> to it
|
||||
fitSnapshot.add(fitStat);
|
||||
// and of course add it to the checkpoint
|
||||
checkpoint.add(fitSnapshot);
|
||||
*/
|
||||
|
||||
// Last type of item the eoCheckpoint can handle: state savers:
|
||||
eoState outState;
|
||||
// Register the algorithm into the state (so it has something to save!!)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue