diff --git a/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h b/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h index 7ee99a806..66f7a6ba2 100644 --- a/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h +++ b/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h @@ -30,7 +30,7 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr -*/ + */ #ifndef moVectorMonitor_h #define moVectorMonitor_h @@ -49,158 +49,166 @@ class moVectorMonitor : public eoMonitor { public: - /** - * Constructor - * @param _param the parameter of type double to save in the vector - */ - moVectorMonitor(eoValueParam & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL) - { } + /** + * Constructor + * @param _param the parameter of type double to save in the vector + */ + 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), eotParam(NULL) - { } + /** + * Default Constructor + * @param _param the parameter of type unsigned int to save in the vector + */ + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL) + { } - /** - * Default Constructor - * @param _param the parameter of type EOT to save in the vector - */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param) - { } + /** + * Default Constructor + * @param _param the parameter of type EOT to save in the vector + */ + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param) + { } - /** - * Default Constructor - * @param _param the parameter of type eoScalarFitness to save in the vector - */ - template - moVectorMonitor(eoValueParam > & _param) : doubleParam( & (eoValueParam&)_param), intParam(NULL), eotParam(NULL) - { } + /** + * Default Constructor + * @param _param the parameter of type eoScalarFitness to save in the vector + */ + template + moVectorMonitor(eoValueParam > & _param) : doubleParam( & (eoValueParam&)_param), intParam(NULL), eotParam(NULL) + { } - /** - * Default Constructor - * @param _param unvalid Parameter - */ - template - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL) - { - std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl; - } + /** + * Default Constructor + * @param _param unvalid Parameter + */ + template + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL) + { + std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl; + } - /** - * 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 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 - * - * @return this monitor (sorry I don't why, but it is like this in EO) - */ - eoMonitor& operator()(void) { - if (doubleParam != NULL) - valueVec.push_back(doubleParam->value()); - else - if (intParam != NULL) - valueVec.push_back((double) intParam->value()); - else - eotVec.push_back(eotParam->value()); + /** + * To "print" the value of the parameter in the vector + * + * @return this monitor (sorry I don't why, but it is like this in EO) + */ + eoMonitor& operator()(void) { + if (doubleParam != NULL) + valueVec.push_back(doubleParam->value()); + else + if (intParam != NULL) + valueVec.push_back((double) intParam->value()); + else + eotVec.push_back(eotParam->value()); - return *this ; - } + return *this ; + } - /** - * To have all the values - * - * @return the vector of values - */ - const std::vector& getValues() const { - return valueVec; - } + /** + * To have all the values + * + * @return the vector of values + */ + const std::vector& getValues() const { + return valueVec; + } - /** - * To have all the solutions - * - * @return the vector of solutions - */ - const std::vector& getSolutions() const { - return eotVec; - } + /** + * To have all the solutions + * + * @return the vector of solutions + */ + const std::vector& getSolutions() const { + return eotVec; + } - /** - * to get the value out. - * @return the string of the value - */ - std::string getValue(unsigned int i) const { - std::ostringstream os; + /** + * to get the value out. + * @return the string of the value + */ + std::string getValue(unsigned int i) const { + std::ostringstream os; - if (eotParam == NULL) - os << (valueVec[i]) ; - else - os << (eotVec[i]) ; + if (eotParam == NULL) + os << (valueVec[i]) ; + else + os << (eotVec[i]) ; - return os.str(); - } + return os.str(); + } - /** - * clear the vector - */ - void clear() { - valueVec.clear(); - eotVec.clear(); - } + /** + * clear the vector + */ + void clear() { + valueVec.clear(); + eotVec.clear(); + } - /** - * number of value - * @return size of the vector - */ - unsigned int size() { - if (eotParam == NULL) - return valueVec.size(); - else - return eotVec.size(); - } + /** + * number of value + * @return size of the vector + */ + unsigned int size() { + if (eotParam == NULL) + return valueVec.size(); + else + return eotVec.size(); + } - /** - * to export the vector of values into one file - * @param _filename file name - */ - void fileExport(std::string _filename) { - // create file - std::ofstream os(_filename.c_str()); + /** + * to export the vector of values into one file + * @param _filename file name + * @param _openFile to specify if it writes at the following of the file + */ + void fileExport(std::string _filename, bool _openFile=false) { + // create file + std::ofstream os; - if (!os) { - std::string str = "moVectorMonitor: Could not open " + _filename; - throw std::runtime_error(str); - } + if(! _openFile) + os.open(_filename.c_str()); - for (unsigned int i = 0; i < size(); i++) { - os << getValue(i); + else + os.open(_filename.c_str(),std::ios::app); - os << std::endl ; - } - } + if (!os) { + std::string str = "moVectorMonitor: Could not open " + _filename; + throw std::runtime_error(str); + } - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moVectorMonitor"; - } + for (unsigned int i = 0; i < size(); i++) { + os << getValue(i); + + os << std::endl ; + } + + } + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moVectorMonitor"; + } protected: - eoValueParam * doubleParam ; - eoValueParam * intParam ; - eoValueParam * eotParam ; + eoValueParam * doubleParam ; + eoValueParam * intParam ; + eoValueParam * eotParam ; - std::vector valueVec; - std::vector eotVec; + std::vector valueVec; + std::vector eotVec; };