- Main Page
- Classes
- Files

- Search for |

# moeoArchiveFitnessSavingUpdater.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoArchiveFitnessSavingUpdater.h
    00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
    00006 /*
    00007     This library...
    00008
    00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
    00010  */
    00011 //-----------------------------------------------------------------------------
    00012
    00013 #ifndef MOEOARCHIVEFITNESSSAVINGUPDATER_H_
    00014 #define MOEOARCHIVEFITNESSSAVINGUPDATER_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 > class moeoArchiveFitnessSavingUpdater:public eoUpdater
    00028 {
    00029 public:
    00030
    00037 moeoArchiveFitnessSavingUpdater (moeoArchive < EOT > &_arch, const std::string & _filename = "Res/Arch", int _id = -1):arch (_arch), filename (_filename), id (_id),
    00038     counter
    00039     (0)
    00040   {
    00041   }
    00042
    00046   void operator () ()
    00047   {
    00048     char buff[MAX_BUFFER_SIZE];
    00049     if (id == -1)
    00050       sprintf (buff, "%s.%u", filename.c_str (), counter++);
    00051     else
    00052       sprintf (buff, "%s.%u.%u", filename.c_str (), id, counter++);
    00053     std::ofstream f (buff);
    00054     for (unsigned i = 0; i < arch.size (); i++)
    00055       f << arch[i].fitness () << std::endl;
    00056     f.close ();
    00057   }
    00058
    00059
    00060 private:
    00061
    00063   moeoArchive < EOT > &arch;
    00065   std::string filename;
    00067   int id;
    00069   unsigned counter;
    00070
    00071 };
    00072
    00073 #endif /*MOEOARCHIVEFITNESSSAVINGUPDATER_H_ */