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:
maartenkeijzer 2001-03-28 09:00:54 +00:00
commit 195ad72838
6 changed files with 56 additions and 46 deletions

View file

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

View file

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

View file

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

View file

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