diff --git a/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h b/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h index 00e0bc6f1..049b8a500 100644 --- a/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h +++ b/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h @@ -39,10 +39,11 @@ #include /** - * 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 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 & _param) : doubleParam(&_param), intParam(NULL) + moVectorMonitor(eoValueParam & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL) { } /** * Default Constructor * @param _param the parameter of type unsigned int to save in the vector */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(&_param) + moVectorMonitor(eoValueParam & _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 - // const std::vector& getVector() const ; + moVectorMonitor(eoValueParam & _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& getVector() const { - return valueVec ; + const std::vector& getValues() const { + return valueVec; + } + + /** + * To have all the solutions + * + * @return the vector of solutions + */ + const std::vector& 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 * doubleParam ; eoValueParam * intParam ; + eoValueParam * eotParam ; std::vector valueVec; + std::vector eotVec; }; diff --git a/trunk/paradiseo-mo/src/sampling/moSampling.h b/trunk/paradiseo-mo/src/sampling/moSampling.h index 3c99d82ac..f1026fbee 100644 --- a/trunk/paradiseo-mo/src/sampling/moSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moSampling.h @@ -90,7 +90,7 @@ public: void add(moStat & _stat) { // statVec.push_back(&_stat); - moVectorMonitor * monitor = new moVectorMonitor(_stat); + moVectorMonitor * monitor = new moVectorMonitor(_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::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 & getVector(unsigned int _numStat) { - return monitorVec[_numStat]->getVector(); + const std::vector & 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 & getSolutions(unsigned int _numStat) { + return monitorVec[_numStat]->getSolutions(); } /** @@ -178,7 +184,7 @@ protected: moCheckpoint * checkpoint; // std::vector*> statVec; - std::vector monitorVec; + std::vector< moVectorMonitor *> monitorVec; }; diff --git a/trunk/paradiseo-mo/tutorial/Lesson6/autocorrelation.cpp b/trunk/paradiseo-mo/tutorial/Lesson6/autocorrelation.cpp index dfb608381..78dff0e87 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson6/autocorrelation.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson6/autocorrelation.cpp @@ -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 & fitnessValues = sampling.getVector(0); + const std::vector & fitnessValues = sampling.getValues(0); std::cout << "First values:" << std::endl; std::cout << "Fitness " << fitnessValues[0] << std::endl; diff --git a/trunk/paradiseo-mo/tutorial/Lesson6/densityOfStates.cpp b/trunk/paradiseo-mo/tutorial/Lesson6/densityOfStates.cpp index 89528397a..95be73d87 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson6/densityOfStates.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson6/densityOfStates.cpp @@ -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 & fitnessValues = sampling.getVector(0); + const std::vector & fitnessValues = sampling.getValues(0); std::cout << "First values:" << std::endl; std::cout << "Fitness " << fitnessValues[0] << std::endl; diff --git a/trunk/paradiseo-mo/tutorial/Lesson6/sampling.cpp b/trunk/paradiseo-mo/tutorial/Lesson6/sampling.cpp index e501a88bd..6b00e5f8d 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson6/sampling.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson6/sampling.cpp @@ -45,6 +45,7 @@ using namespace std; #include #include #include +#include //----------------------------------------------------------------------------- // the sampling class @@ -188,6 +189,9 @@ void main_function(int argc, char **argv) moDistanceStat distStat(distance, bestSolution); // statistic + // "statistic" of the solution + moSolutionStat solStat; + /* ========================================================= * * The sampling of the search space @@ -201,7 +205,8 @@ void main_function(int argc, char **argv) moSampling 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 & fitnessValues = sampling.getVector(0); - const std::vector & distValues = sampling.getVector(1); + const std::vector & fitnessValues = sampling.getValues(0); + const std::vector & distValues = sampling.getValues(1); + const std::vector & 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