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), 2007
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 <vector>
00019 #include <eoPop.h>
00020 #include <utils/eoUpdater.h>
00021 #include <metric/moeoMetric.h>
00022 
00027 template < class MOEOT >
00028 class moeoBinaryMetricSavingUpdater : public eoUpdater
00029 {
00030 public:
00031 
00033     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00034 
00035 
00042     moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) :
00043             metric(_metric), pop(_pop), filename(_filename), counter(1)
00044     {}
00045 
00046 
00050     void operator()() {
00051         if (pop.size()) {
00052             if (firstGen) {
00053                 firstGen = false;
00054             }
00055             else {
00056                 // creation of the two Pareto sets
00057                 std::vector < ObjectiveVector > from;
00058                 std::vector < ObjectiveVector > to;
00059                 for (unsigned int i=0; i<pop.size(); i++)
00060                     from.push_back(pop[i].objectiveVector());
00061                 for (unsigned int i=0 ; i<oldPop.size(); i++)
00062                     to.push_back(oldPop[i].objectiveVector());
00063                 // writing the result into the file
00064                 std::ofstream f (filename.c_str(), std::ios::app);
00065                 f << counter++ << ' ' << metric(from,to) << std::endl;
00066                 f.close();
00067             }
00068             oldPop = pop;
00069         }
00070     }
00071 
00072 
00073 private:
00074 
00076     moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & metric;
00078     const eoPop < MOEOT > & pop;
00080     eoPop< MOEOT > oldPop;
00082     std::string filename;
00084     bool firstGen;
00086     unsigned int counter;
00087 
00088 };
00089 
00090 #endif /*MOEOBINARYMETRICSAVINGUPDATER_H_*/

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