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:
parent
40e4285b7a
commit
29fe6eed3d
5 changed files with 77 additions and 31 deletions
|
|
@ -39,10 +39,11 @@
|
||||||
#include <utils/eoParam.h>
|
#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
|
* It is similar to eoFileMonitor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
template <class EOT>
|
||||||
class moVectorMonitor : public eoMonitor
|
class moVectorMonitor : public eoMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -51,23 +52,31 @@ public:
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _param the parameter of type double to save in the vector
|
* @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
|
* Default Constructor
|
||||||
* @param _param the parameter of type unsigned int to save in the vector
|
* @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
|
* Default Constructor
|
||||||
*
|
* @param _param the parameter of type EOT to save in the vector
|
||||||
* @return the vector of values
|
|
||||||
*/
|
*/
|
||||||
// template <class ValueType>
|
moVectorMonitor(eoValueParam<EOT> & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param)
|
||||||
// const std::vector<ValueType>& getVector() const ;
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* To "print" the value of the parameter in the vector
|
||||||
|
|
@ -78,7 +87,10 @@ public:
|
||||||
if (doubleParam != NULL)
|
if (doubleParam != NULL)
|
||||||
valueVec.push_back(doubleParam->value());
|
valueVec.push_back(doubleParam->value());
|
||||||
else
|
else
|
||||||
valueVec.push_back((double) intParam->value());
|
if (intParam != NULL)
|
||||||
|
valueVec.push_back((double) intParam->value());
|
||||||
|
else
|
||||||
|
eotVec.push_back(eotParam->value());
|
||||||
|
|
||||||
return *this ;
|
return *this ;
|
||||||
}
|
}
|
||||||
|
|
@ -88,8 +100,17 @@ public:
|
||||||
*
|
*
|
||||||
* @return the vector of values
|
* @return the vector of values
|
||||||
*/
|
*/
|
||||||
const std::vector<double>& getVector() const {
|
const std::vector<double>& getValues() const {
|
||||||
return valueVec ;
|
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::string getValue(unsigned int i) const {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << (valueVec[i]) ;
|
|
||||||
|
if (eotParam == NULL)
|
||||||
|
os << (valueVec[i]) ;
|
||||||
|
else
|
||||||
|
os << (eotVec[i]) ;
|
||||||
|
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,6 +133,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void clear() {
|
void clear() {
|
||||||
valueVec.clear();
|
valueVec.clear();
|
||||||
|
eotVec.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -114,7 +141,10 @@ public:
|
||||||
* @return size of the vector
|
* @return size of the vector
|
||||||
*/
|
*/
|
||||||
unsigned int size() {
|
unsigned int size() {
|
||||||
return valueVec.size();
|
if (eotParam == NULL)
|
||||||
|
return valueVec.size();
|
||||||
|
else
|
||||||
|
return eotVec.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,8 +157,10 @@ public:
|
||||||
protected:
|
protected:
|
||||||
eoValueParam<double> * doubleParam ;
|
eoValueParam<double> * doubleParam ;
|
||||||
eoValueParam<unsigned int> * intParam ;
|
eoValueParam<unsigned int> * intParam ;
|
||||||
|
eoValueParam<EOT> * eotParam ;
|
||||||
|
|
||||||
std::vector<double> valueVec;
|
std::vector<double> valueVec;
|
||||||
|
std::vector<EOT> eotVec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ public:
|
||||||
void add(moStat<EOT, ValueType> & _stat) {
|
void add(moStat<EOT, ValueType> & _stat) {
|
||||||
// statVec.push_back(&_stat);
|
// statVec.push_back(&_stat);
|
||||||
|
|
||||||
moVectorMonitor * monitor = new moVectorMonitor(_stat);
|
moVectorMonitor<EOT> * monitor = new moVectorMonitor<EOT>(_stat);
|
||||||
monitorVec.push_back(monitor);
|
monitorVec.push_back(monitor);
|
||||||
|
|
||||||
checkpoint->add(_stat);
|
checkpoint->add(_stat);
|
||||||
|
|
@ -140,14 +140,11 @@ public:
|
||||||
unsigned vecSize = monitorVec[0]->size();
|
unsigned vecSize = monitorVec[0]->size();
|
||||||
|
|
||||||
for(unsigned int i = 0; i < vecSize; i++) {
|
for(unsigned int i = 0; i < vecSize; i++) {
|
||||||
std::vector<moVectorMonitor*>::iterator it = monitorVec.begin();
|
os << monitorVec[0]->getValue(i);
|
||||||
|
|
||||||
os << (*it)->getValue(i);
|
for(unsigned int j = 1; j < monitorVec.size(); j++) {
|
||||||
|
os << _delim.c_str() << monitorVec[j]->getValue(i);
|
||||||
for(++it; it != monitorVec.end(); ++it)
|
}
|
||||||
{
|
|
||||||
os << _delim.c_str() << (*it)->getValue(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
os << std::endl ;
|
os << std::endl ;
|
||||||
}
|
}
|
||||||
|
|
@ -159,8 +156,17 @@ public:
|
||||||
* @param _numStat number of stattistics to get (in order of creation)
|
* @param _numStat number of stattistics to get (in order of creation)
|
||||||
* @return the vector of value (all values are converted in double)
|
* @return the vector of value (all values are converted in double)
|
||||||
*/
|
*/
|
||||||
const std::vector<double> & getVector(unsigned int _numStat) {
|
const std::vector<double> & getValues(unsigned int _numStat) {
|
||||||
return monitorVec[_numStat]->getVector();
|
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;
|
moCheckpoint<Neighbor> * checkpoint;
|
||||||
|
|
||||||
// std::vector<moStatBase<EOT>*> statVec;
|
// std::vector<moStatBase<EOT>*> statVec;
|
||||||
std::vector<moVectorMonitor*> monitorVec;
|
std::vector< moVectorMonitor<EOT> *> monitorVec;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ void main_function(int argc, char **argv)
|
||||||
|
|
||||||
// to get the values of statistics
|
// to get the values of statistics
|
||||||
// so, you can compute some statistics in c++ from the data
|
// 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 << "First values:" << std::endl;
|
||||||
std::cout << "Fitness " << fitnessValues[0] << std::endl;
|
std::cout << "Fitness " << fitnessValues[0] << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ void main_function(int argc, char **argv)
|
||||||
|
|
||||||
// to get the values of statistics
|
// to get the values of statistics
|
||||||
// so, you can compute some statistics in c++ from the data
|
// 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 << "First values:" << std::endl;
|
||||||
std::cout << "Fitness " << fitnessValues[0] << std::endl;
|
std::cout << "Fitness " << fitnessValues[0] << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ using namespace std;
|
||||||
#include <continuator/moFitnessStat.h>
|
#include <continuator/moFitnessStat.h>
|
||||||
#include <utils/eoDistance.h>
|
#include <utils/eoDistance.h>
|
||||||
#include <continuator/moDistanceStat.h>
|
#include <continuator/moDistanceStat.h>
|
||||||
|
#include <continuator/moSolutionStat.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// the sampling class
|
// the sampling class
|
||||||
|
|
@ -188,6 +189,9 @@ void main_function(int argc, char **argv)
|
||||||
|
|
||||||
moDistanceStat<Indi, unsigned> distStat(distance, bestSolution); // statistic
|
moDistanceStat<Indi, unsigned> distStat(distance, bestSolution); // statistic
|
||||||
|
|
||||||
|
// "statistic" of the solution
|
||||||
|
moSolutionStat<Indi> solStat;
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
* The sampling of the search space
|
* The sampling of the search space
|
||||||
|
|
@ -201,7 +205,8 @@ void main_function(int argc, char **argv)
|
||||||
moSampling<Neighbor> sampling(random, walk, fStat);
|
moSampling<Neighbor> sampling(random, walk, fStat);
|
||||||
|
|
||||||
// to add another statistics
|
// 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
|
// to get the values of statistics
|
||||||
// so, you can compute some statistics in c++ from the data
|
// 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);
|
||||||
const std::vector<double> & distValues = sampling.getVector(1);
|
const std::vector<double> & distValues = sampling.getValues(1);
|
||||||
|
const std::vector<Indi> & solutions = sampling.getSolutions(2);
|
||||||
|
|
||||||
std::cout << "First values:" << std::endl;
|
std::cout << "First values:" << std::endl;
|
||||||
std::cout << "Fitness " << fitnessValues[0] << 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 << "Last values:" << std::endl;
|
||||||
std::cout << "Fitness " << fitnessValues[fitnessValues.size() - 1] << std::endl;
|
std::cout << "Fitness " << fitnessValues[fitnessValues.size() - 1] << std::endl;
|
||||||
std::cout << "Distance " << distValues[distValues.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
|
// A main that catches the exceptions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue