- Main Page
- Classes
- Files

- Search for |

# 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 <moeoArchive.h>
    00021
    00022 #define MAX_BUFFER_SIZE 1000
    00023
    00027 template <class EOT>
    00028 class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater
    00029 {
    00030 public:
    00031
    00038     moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<EOT> & _arch, const std::string & _filename, int _id = -1) : arch(_arch), filename(_filename), id(_id), counter(0)
    00039     {}
    00040
    00044     void operator()() {
    00045         char buff[MAX_BUFFER_SIZE];
    00046         if (id == -1)
    00047             sprintf (buff, "%s.%u", filename.c_str(), counter ++);
    00048         else
    00049             sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
    00050         std::ofstream f(buff);
    00051         for (unsigned i = 0; i < arch.size (); i++)
    00052             f << arch[i].objectiveVector() << std::endl;
    00053         f.close ();
    00054     }
    00055
    00056
    00057 private:
    00058
    00060     moeoArchive<EOT> & arch;
    00062     std::string filename;
    00064     int id;
    00066     unsigned counter;
    00067
    00068 };
    00069
    00070 #endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/