moVectorMonitor peut enregistrer les EOT

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1779 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
verel 2010-05-05 08:33:04 +00:00
commit 29fe6eed3d
5 changed files with 77 additions and 31 deletions

View file

@ -39,10 +39,11 @@
#include <utils/eoParam.h>
/**
* To save the values of the same type in a vector
* To save the values of the same type (double, unsigned int, or EOT) in a vector
* It is similar to eoFileMonitor
*
*/
template <class EOT>
class moVectorMonitor : public eoMonitor
{
public:
@ -51,23 +52,31 @@ public:
* Default Constructor
* @param _param the parameter of type double to save in the vector
*/
moVectorMonitor(eoValueParam<double> & _param) : doubleParam(&_param), intParam(NULL)
moVectorMonitor(eoValueParam<double> & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL)
{ }
/**
* Default Constructor
* @param _param the parameter of type unsigned int to save in the vector
*/
moVectorMonitor(eoValueParam<unsigned int> & _param) : doubleParam(NULL), intParam(&_param)
moVectorMonitor(eoValueParam<unsigned int> & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL)
{ }
/**
* Pure virtual function to have all the values
*
* @return the vector of values
* Default Constructor
* @param _param the parameter of type EOT to save in the vector
*/
// template <class ValueType>
// const std::vector<ValueType>& getVector() const ;
moVectorMonitor(eoValueParam<EOT> & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param)
{ }
/**
* To test if the value are basic type (double or unsigned int), or EOT type
*
* @return true if the type is a EOT type
*/
bool solutionType() {
return eotParam != NULL;
}
/**
* To "print" the value of the parameter in the vector
@ -77,9 +86,12 @@ public:
eoMonitor& operator()(void) {
if (doubleParam != NULL)
valueVec.push_back(doubleParam->value());
else
valueVec.push_back((double) intParam->value());
else
if (intParam != NULL)
valueVec.push_back((double) intParam->value());
else
eotVec.push_back(eotParam->value());
return *this ;
}
@ -88,8 +100,17 @@ public:
*
* @return the vector of values
*/
const std::vector<double>& getVector() const {
return valueVec ;
const std::vector<double>& getValues() const {
return valueVec;
}
/**
* To have all the solutions
*
* @return the vector of solutions
*/
const std::vector<EOT>& getSolutions() const {
return eotVec;
}
/**
@ -98,7 +119,12 @@ public:
*/
std::string getValue(unsigned int i) const {
std::ostringstream os;
os << (valueVec[i]) ;
if (eotParam == NULL)
os << (valueVec[i]) ;
else
os << (eotVec[i]) ;
return os.str();
}
@ -107,6 +133,7 @@ public:
*/
void clear() {
valueVec.clear();
eotVec.clear();
}
/**
@ -114,7 +141,10 @@ public:
* @return size of the vector
*/
unsigned int size() {
return valueVec.size();
if (eotParam == NULL)
return valueVec.size();
else
return eotVec.size();
}
/**
@ -127,8 +157,10 @@ public:
protected:
eoValueParam<double> * doubleParam ;
eoValueParam<unsigned int> * intParam ;
eoValueParam<EOT> * eotParam ;
std::vector<double> valueVec;
std::vector<EOT> eotVec;
};

View file

@ -90,7 +90,7 @@ public:
void add(moStat<EOT, ValueType> & _stat) {
// statVec.push_back(&_stat);
moVectorMonitor * monitor = new moVectorMonitor(_stat);
moVectorMonitor<EOT> * monitor = new moVectorMonitor<EOT>(_stat);
monitorVec.push_back(monitor);
checkpoint->add(_stat);
@ -140,14 +140,11 @@ public:
unsigned vecSize = monitorVec[0]->size();
for(unsigned int i = 0; i < vecSize; i++) {
std::vector<moVectorMonitor*>::iterator it = monitorVec.begin();
os << (*it)->getValue(i);
os << monitorVec[0]->getValue(i);
for(++it; it != monitorVec.end(); ++it)
{
os << _delim.c_str() << (*it)->getValue(i);
}
for(unsigned int j = 1; j < monitorVec.size(); j++) {
os << _delim.c_str() << monitorVec[j]->getValue(i);
}
os << std::endl ;
}
@ -159,8 +156,17 @@ public:
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<double> & getVector(unsigned int _numStat) {
return monitorVec[_numStat]->getVector();
const std::vector<double> & getValues(unsigned int _numStat) {
return monitorVec[_numStat]->getValues();
}
/**
* to get one vector of solutions values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<EOT> & getSolutions(unsigned int _numStat) {
return monitorVec[_numStat]->getSolutions();
}
/**
@ -178,7 +184,7 @@ protected:
moCheckpoint<Neighbor> * checkpoint;
// std::vector<moStatBase<EOT>*> statVec;
std::vector<moVectorMonitor*> monitorVec;
std::vector< moVectorMonitor<EOT> *> monitorVec;
};

View file

@ -186,7 +186,7 @@ void main_function(int argc, char **argv)
// to get the values of statistics
// so, you can compute some statistics in c++ from the data
const std::vector<double> & fitnessValues = sampling.getVector(0);
const std::vector<double> & fitnessValues = sampling.getValues(0);
std::cout << "First values:" << std::endl;
std::cout << "Fitness " << fitnessValues[0] << std::endl;

View file

@ -158,7 +158,7 @@ void main_function(int argc, char **argv)
// to get the values of statistics
// so, you can compute some statistics in c++ from the data
const std::vector<double> & fitnessValues = sampling.getVector(0);
const std::vector<double> & fitnessValues = sampling.getValues(0);
std::cout << "First values:" << std::endl;
std::cout << "Fitness " << fitnessValues[0] << std::endl;

View file

@ -45,6 +45,7 @@ using namespace std;
#include <continuator/moFitnessStat.h>
#include <utils/eoDistance.h>
#include <continuator/moDistanceStat.h>
#include <continuator/moSolutionStat.h>
//-----------------------------------------------------------------------------
// the sampling class
@ -188,6 +189,9 @@ void main_function(int argc, char **argv)
moDistanceStat<Indi, unsigned> distStat(distance, bestSolution); // statistic
// "statistic" of the solution
moSolutionStat<Indi> solStat;
/* =========================================================
*
* The sampling of the search space
@ -201,7 +205,8 @@ void main_function(int argc, char **argv)
moSampling<Neighbor> sampling(random, walk, fStat);
// to add another statistics
sampling.add(distStat);
sampling.add(distStat); // distance
sampling.add(solStat); // solutions
/* =========================================================
*
@ -222,16 +227,19 @@ void main_function(int argc, char **argv)
// to get the values of statistics
// so, you can compute some statistics in c++ from the data
const std::vector<double> & fitnessValues = sampling.getVector(0);
const std::vector<double> & distValues = sampling.getVector(1);
const std::vector<double> & fitnessValues = sampling.getValues(0);
const std::vector<double> & distValues = sampling.getValues(1);
const std::vector<Indi> & solutions = sampling.getSolutions(2);
std::cout << "First values:" << std::endl;
std::cout << "Fitness " << fitnessValues[0] << std::endl;
std::cout << "Distance " << distValues[0] << std::endl << std::endl;
std::cout << "Distance " << distValues[0] << std::endl;
std::cout << "Solution " << solutions[0] << std::endl << std::endl;
std::cout << "Last values:" << std::endl;
std::cout << "Fitness " << fitnessValues[fitnessValues.size() - 1] << std::endl;
std::cout << "Distance " << distValues[distValues.size() - 1] << std::endl;
std::cout << "Solution " << solutions[solutions.size() - 1] << std::endl;
}
// A main that catches the exceptions