From 6d55b7832122858941624b94a0a450ad892cd109 Mon Sep 17 00:00:00 2001 From: verel Date: Fri, 7 May 2010 09:23:52 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20m=C3=A9thode=20fileExport=20?= =?UTF-8?q?=C3=A0=20moVectorMonitor.=20Encore=20un=20bout.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1798 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/continuator/moVectorMonitor.h | 21 +++++++++++++++++++ trunk/paradiseo-mo/src/sampling/moSampling.h | 16 +++++++++++++- .../tutorial/Lesson6/neutralWalk.cpp | 3 +++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h b/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h index 6114b4ed5..c0c651fea 100644 --- a/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h +++ b/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h @@ -157,6 +157,27 @@ public: return eotVec.size(); } + /** + * to export the vector of values into one file + * @param _filename file name + */ + void fileExport(std::string _filename) { + // create file + ofstream os(_filename.c_str()); + + if (!os) { + string str = "moVectorMonitor: Could not open " + _filename; + throw runtime_error(str); + } + + for(unsigned int i = 0; i < size(); i++) { + os << getValue(i); + + os << std::endl ; + } + + } + /** * @return name of the class */ diff --git a/trunk/paradiseo-mo/src/sampling/moSampling.h b/trunk/paradiseo-mo/src/sampling/moSampling.h index 2cb90a66a..48034ed7c 100644 --- a/trunk/paradiseo-mo/src/sampling/moSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moSampling.h @@ -125,7 +125,7 @@ public: } /** - * to export the vector of values into one file + * to export the vectors of values into one file * @param _filename file name * @param _delim delimiter between statistics */ @@ -153,6 +153,20 @@ public: } + /** + * to export one vector of values into a file + * @param _col number of vector to print into file + * @param _filename file name + */ + void fileExport(unsigned int _col, std::string _filename) { + if (_col >= monitorVec.size()) { + string str = "moSampling: Could not export into file the vector. The index does not exists (too large)"; + throw runtime_error(str); + } + + monitorVec[_col]->fileExport(_filename); + } + /** * to get one vector of values * @param _numStat number of stattistics to get (in order of creation) diff --git a/trunk/paradiseo-mo/tutorial/Lesson6/neutralWalk.cpp b/trunk/paradiseo-mo/tutorial/Lesson6/neutralWalk.cpp index 1e8964dea..1102affd2 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson6/neutralWalk.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson6/neutralWalk.cpp @@ -206,6 +206,9 @@ void main_function(int argc, char **argv) std::cout << "Last values:" << std::endl; std::cout << "Solution " << solutions[solutions.size() - 1] << std::endl; + + // export only the solution into file + sampling.fileExport(0, str_out + "_sol"); } // A main that catches the exceptions