moeoBinaryMetricSavingUpdater.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoBinaryMetricSavingUpdater.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 MOEOBINARYMETRICSAVINGUPDATER_H_
00014 #define MOEOBINARYMETRICSAVINGUPDATER_H_
00015 
00016 #include <fstream>
00017 #include <string>
00018 #include <eoPop.h>
00019 #include <utils/eoUpdater.h>
00020 #include <metric/moeoMetric.h>
00021 
00026 template < class EOT > class moeoBinaryMetricSavingUpdater:public eoUpdater
00027 {
00028 public:
00029 
00033   typedef typename EOT::Fitness EOFitness;
00034 
00041   moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBM < EOT, double >&_metric,
00042                                  const eoPop < EOT > &_pop,
00043                                  std::string _filename):metric (_metric),
00044     pop (_pop), filename (_filename), counter (1)
00045   {
00046   }
00047 
00051   void operator  () ()
00052   {
00053     if (pop.size ())
00054       {
00055         if (firstGen)
00056           {
00057             firstGen = false;
00058           }
00059         else
00060           {
00061             // creation of the two Pareto sets                              
00062             std::vector < EOFitness > from;
00063             std::vector < EOFitness > to;
00064             for (unsigned i = 0; i < pop.size (); i++)
00065               from.push_back (pop[i].fitness ());
00066             for (unsigned i = 0; i < oldPop.size (); i++)
00067               to.push_back (oldPop[i].fitness ());
00068             // writing the result into the file
00069             std::ofstream f (filename.c_str (), std::ios::app);
00070             f << counter++ << ' ' << metric (from, to) << std::endl;
00071             f.close ();
00072           }
00073         oldPop = pop;
00074       }
00075   }
00076 
00077 private:
00078 
00080   moeoVectorVsVectorBM < EOT, double >&metric;
00082   const eoPop < EOT > &pop;
00084   eoPop < EOT > oldPop;
00086   std::string filename;
00088   bool firstGen;
00090   unsigned counter;
00091 
00092 };
00093 
00094 #endif /*MOEOBINARYMETRICSAVINGUPDATER_H_ */

Generated on Wed Dec 6 10:16:12 2006 for ParadisEO-MOEO by  doxygen 1.5.1