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 
00033 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
00034 class MOEO : public EO < MOEOObjectiveVector >
00035 {
00036 public:
00037 
00039     typedef MOEOObjectiveVector ObjectiveVector;
00040 
00042     typedef MOEOFitness Fitness;
00043 
00045     typedef MOEODiversity Diversity;
00046 
00047 
00051     MOEO()
00052     {
00053         // default values for every parameters
00054         objectiveVectorValue = ObjectiveVector();
00055         fitnessValue = Fitness();
00056         diversityValue = Diversity();
00057         // invalidate all
00058         invalidate();
00059     }
00060 
00061 
00065     virtual ~MOEO() {};
00066 
00067 
00071     ObjectiveVector objectiveVector() const
00072     {
00073         if ( invalidObjectiveVector() )
00074         {
00075             throw std::runtime_error("invalid objective vector in MOEO");
00076         }
00077         return objectiveVectorValue;
00078     }
00079 
00080 
00085     void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
00086     {
00087         objectiveVectorValue = _objectiveVectorValue;
00088         invalidObjectiveVectorValue = false;
00089     }
00090 
00091 
00095     void invalidateObjectiveVector()
00096     {
00097         invalidObjectiveVectorValue = true;
00098     }
00099 
00100 
00104     bool invalidObjectiveVector() const
00105     {
00106         return invalidObjectiveVectorValue;
00107     }
00108 
00109 
00113     Fitness fitness() const
00114     {
00115         if ( invalidFitness() )
00116         {
00117             throw std::runtime_error("invalid fitness in MOEO");
00118         }
00119         return fitnessValue;
00120     }
00121 
00122 
00127     void fitness(const Fitness & _fitnessValue)
00128     {
00129         fitnessValue = _fitnessValue;
00130         invalidFitnessValue = false;
00131     }
00132 
00133 
00137     void invalidateFitness()
00138     {
00139         invalidFitnessValue = true;
00140     }
00141 
00142 
00146     bool invalidFitness() const
00147     {
00148         return invalidFitnessValue;
00149     }
00150 
00151 
00155     Diversity diversity() const
00156     {
00157         if ( invalidDiversity() )
00158         {
00159             throw std::runtime_error("invalid diversity in MOEO");
00160         }
00161         return diversityValue;
00162     }
00163 
00164 
00169     void diversity(const Diversity & _diversityValue)
00170     {
00171         diversityValue = _diversityValue;
00172         invalidDiversityValue = false;
00173     }
00174 
00175 
00179     void invalidateDiversity()
00180     {
00181         invalidDiversityValue = true;
00182     }
00183 
00184 
00188     bool invalidDiversity() const
00189     {
00190         return invalidDiversityValue;
00191     }
00192 
00193 
00197     void invalidate()
00198     {
00199         invalidateObjectiveVector();
00200         invalidateFitness();
00201         invalidateDiversity();
00202     }
00203 
00204 
00208     bool invalid() const
00209     {
00210         return invalidObjectiveVector();
00211     }
00212 
00213 
00220     bool operator<(const MOEO & _other) const
00221     {
00222         return objectiveVector() < _other.objectiveVector();
00223     }
00224 
00225 
00229     virtual std::string className() const
00230     {
00231         return "MOEO";
00232     }
00233 
00234 
00239     virtual void printOn(std::ostream & _os) const
00240     {
00241         if ( invalidObjectiveVector() )
00242         {
00243             _os << "INVALID\t";
00244         }
00245         else
00246         {
00247             _os << objectiveVectorValue << '\t';
00248         }
00249     }
00250 
00251 
00256     virtual void readFrom(std::istream & _is)
00257     {
00258         std::string objectiveVector_str;
00259         int pos = _is.tellg();
00260         _is >> objectiveVector_str;
00261         if (objectiveVector_str == "INVALID")
00262         {
00263             invalidateObjectiveVector();
00264         }
00265         else
00266         {
00267             invalidObjectiveVectorValue = false;
00268             _is.seekg(pos); // rewind
00269             _is >> objectiveVectorValue;
00270         }
00271     }
00272 
00273 
00274 private:
00275 
00277     ObjectiveVector objectiveVectorValue;
00279     bool invalidObjectiveVectorValue;
00281     Fitness fitnessValue;
00283     bool invalidFitnessValue;
00285     Diversity diversityValue;
00287     bool invalidDiversityValue;
00288 
00289 };
00290 
00291 #endif /*MOEO_H_*/

Generated on Fri Jul 6 09:41:04 2007 for ParadisEO-MOEO by  doxygen 1.4.7