moeoArchiveObjectiveVectorSavingUpdater.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoArchiveObjectiveVectorSavingUpdater.h
00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
00006 /*
00007     This library...
00008 
00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
00010  */
00011 //-----------------------------------------------------------------------------
00012 
00013 #ifndef MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_
00014 #define MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_
00015 
00016 #include <fstream>
00017 #include <string>
00018 #include <eoPop.h>
00019 #include <utils/eoUpdater.h>
00020 #include <archive/moeoArchive.h>
00021 
00022 #define MAX_BUFFER_SIZE 1000
00023 
00027 template < class MOEOT >
00028 class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater
00029 {
00030 public:
00031 
00039     moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<MOEOT> & _arch, const std::string & _filename, bool _count = false, int _id = -1) :
00040             arch(_arch), filename(_filename), count(_count), counter(0), id(_id)
00041     {}
00042 
00043 
00047     void operator()() {
00048         char buff[MAX_BUFFER_SIZE];
00049         if (count)
00050         {
00051             if (id == -1)
00052             {
00053                 sprintf (buff, "%s.%u", filename.c_str(), counter ++);
00054             }
00055             else
00056             {
00057                 sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
00058             }
00059         }
00060         else
00061         {
00062             if (id == -1)
00063             {
00064                 sprintf (buff, "%s", filename.c_str());
00065             }
00066             else
00067             {
00068                 sprintf (buff, "%s.%u", filename.c_str(), id);
00069             }
00070             counter ++;
00071         }
00072         std::ofstream f(buff);
00073         for (unsigned int i = 0; i < arch.size (); i++)
00074             f << arch[i].objectiveVector() << std::endl;
00075         f.close ();
00076     }
00077 
00078 
00079 private:
00080 
00082     moeoArchive<MOEOT> & arch;
00084     std::string filename;
00086     bool count;
00088     unsigned int counter;
00090     int id;
00091 
00092 };
00093 
00094 #endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/

Generated on Tue Jun 26 15:13:04 2007 for ParadisEO-MOEO by  doxygen 1.4.7