- Main Page
- Classes
- Files

- Search for |

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