- Main Page
- Classes
- Files

- Search for |

# MOEO.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // MOEO.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 MOEO_H_
    00014 #define MOEO_H_
    00015
    00016 #include <iostream>
    00017 #include <stdexcept>
    00018 #include <string>
    00019 #include <EO.h>
    00020
    00030 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
    00031 class MOEO : public EO < MOEOObjectiveVector >
    00032 {
    00033 public:
    00034
    00036     typedef MOEOObjectiveVector ObjectiveVector;
    00037
    00039     typedef MOEOFitness Fitness;
    00040
    00042     typedef MOEODiversity Diversity;
    00043
    00044
    00048     MOEO()
    00049     {
    00050         // default values for every parameters
    00051         objectiveVectorValue = ObjectiveVector();
    00052         fitnessValue = Fitness();
    00053         diversityValue = Diversity();
    00054         // invalidate all
    00055         invalidate();
    00056     }
    00057
    00058
    00062     virtual ~MOEO() {};
    00063
    00064
    00068     ObjectiveVector objectiveVector() const
    00069     {
    00070         if ( invalidObjectiveVector() )
    00071         {
    00072             throw std::runtime_error("invalid objective vector");
    00073         }
    00074         return objectiveVectorValue;
    00075     }
    00076
    00077
    00082     void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
    00083     {
    00084         objectiveVectorValue = _objectiveVectorValue;
    00085         invalidObjectiveVectorValue = false;
    00086     }
    00087
    00088
    00092     void invalidateObjectiveVector()
    00093     {
    00094         invalidObjectiveVectorValue = true;
    00095     }
    00096
    00097
    00101     bool invalidObjectiveVector() const
    00102     {
    00103         return invalidObjectiveVectorValue;
    00104     }
    00105
    00106
    00110     Fitness fitness() const
    00111     {
    00112         if ( invalidFitness() )
    00113         {
    00114             throw std::runtime_error("invalid fitness (MOEO)");
    00115         }
    00116         return fitnessValue;
    00117     }
    00118
    00119
    00124     void fitness(const Fitness & _fitnessValue)
    00125     {
    00126         fitnessValue = _fitnessValue;
    00127         invalidFitnessValue = false;
    00128     }
    00129
    00130
    00134     void invalidateFitness()
    00135     {
    00136         invalidFitnessValue = true;
    00137     }
    00138
    00139
    00143     bool invalidFitness() const
    00144     {
    00145         return invalidFitnessValue;
    00146     }
    00147
    00148
    00152     Diversity diversity() const
    00153     {
    00154         if ( invalidDiversity() )
    00155         {
    00156             throw std::runtime_error("invalid diversity");
    00157         }
    00158         return diversityValue;
    00159     }
    00160
    00161
    00166     void diversity(const Diversity & _diversityValue)
    00167     {
    00168         diversityValue = _diversityValue;
    00169         invalidDiversityValue = false;
    00170     }
    00171
    00172
    00176     void invalidateDiversity()
    00177     {
    00178         invalidDiversityValue = true;
    00179     }
    00180
    00181
    00185     bool invalidDiversity() const
    00186     {
    00187         return invalidDiversityValue;
    00188     }
    00189
    00190
    00194     void invalidate()
    00195     {
    00196         invalidateObjectiveVector();
    00197         invalidateFitness();
    00198         invalidateDiversity();
    00199     }
    00200
    00201
    00205     bool invalid() const
    00206     {
    00207         return invalidObjectiveVector();
    00208     }
    00209
    00210
    00217     bool operator<(const MOEO & _other) const
    00218     {
    00219         return objectiveVector() < _other.objectiveVector();
    00220     }
    00221
    00222
    00226     virtual std::string className() const
    00227     {
    00228         return "MOEO";
    00229     }
    00230
    00231
    00236     virtual void printOn(std::ostream & _os) const
    00237     {
    00238         if ( invalidObjectiveVector() )
    00239         {
    00240             _os << "INVALID\t";
    00241         }
    00242         else
    00243         {
    00244             _os << objectiveVectorValue << '\t';
    00245         }
    00246     }
    00247
    00248
    00253     virtual void readFrom(std::istream & _is)
    00254     {
    00255         std::string objectiveVector_str;
    00256         int pos = _is.tellg();
    00257         _is >> objectiveVector_str;
    00258         if (objectiveVector_str == "INVALID")
    00259         {
    00260             invalidateObjectiveVector();
    00261         }
    00262         else
    00263         {
    00264             invalidObjectiveVectorValue = false;
    00265             _is.seekg(pos); // rewind
    00266             _is >> objectiveVectorValue;
    00267         }
    00268     }
    00269
    00270
    00271 private:
    00272
    00274     ObjectiveVector objectiveVectorValue;
    00276     bool invalidObjectiveVectorValue;
    00278     Fitness fitnessValue;
    00280     bool invalidFitnessValue;
    00282     Diversity diversityValue;
    00284     bool invalidDiversityValue;
    00285
    00286 };
    00287
    00288 #endif /*MOEO_H_*/