MOEO.h

00001 /*
00002 * <MOEO.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 //-----------------------------------------------------------------------------
00037 
00038 #ifndef MOEO_H_
00039 #define MOEO_H_
00040 
00041 #include <iostream>
00042 #include <stdexcept>
00043 #include <string>
00044 #include <EO.h>
00045 
00059 /*
00060  template < typename DataType, typename DataTypeEx > struct Wrapper {
00061 
00062         Wrapper() {}
00063 
00064         Wrapper( const DataType& data )
00065                 : embededData( data ) {}
00066 
00067         Wrapper( const Wrapper& wrapper )
00068                 : embededData( wrapper.embededData ), embededDataEx( wrapper.embededDataEx ) {}
00069 
00070         operator const DataType& () const { return embededData; }
00071 
00072         Wrapper& operator= ( const Wrapper& wrapper ) {
00073 
00074                 embededData = wrapper.embededData;
00075                 embededDataEx = wrapper.embededDataEx;
00076                 return *this;
00077         }
00078 
00079         Wrapper& operator= ( const DataType& data ) {
00080 
00081                 embededData = data;
00082                 return *this;
00083         }
00084 
00085         DataType embededData;
00086         DataTypeEx embededDataEx;
00087 };
00088  **/
00089 
00090 
00091 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
00092 class MOEO : public EO < MOEOObjectiveVector >
00093   {
00094   public:
00095 
00097     typedef MOEOObjectiveVector ObjectiveVector;
00098 
00100     typedef MOEOFitness Fitness;
00101 //      typedef Wrapper< MOEOFitness, MOEOObjectiveVector > Fitness;
00102 
00104     typedef MOEODiversity Diversity;
00105 
00106 
00110     MOEO()
00111     {
00112       // default values for every parameters
00113       objectiveVectorValue = ObjectiveVector();
00114       fitnessValue = Fitness();
00115       diversityValue = Diversity();
00116       // invalidate all
00117       invalidate();
00118     }
00119 
00120 
00124     virtual ~MOEO()
00125     {};
00126 
00127 
00131     ObjectiveVector objectiveVector() const
00132       {
00133         if ( invalidObjectiveVector() )
00134           {
00135             throw std::runtime_error("invalid objective vector in MOEO");
00136           }
00137         return objectiveVectorValue;
00138       }
00139 
00140 
00145     void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
00146     {
00147       objectiveVectorValue = _objectiveVectorValue;
00148       invalidObjectiveVectorValue = false;
00149     }
00150 
00151 
00155     void invalidateObjectiveVector()
00156     {
00157       invalidObjectiveVectorValue = true;
00158     }
00159 
00160 
00164     bool invalidObjectiveVector() const
00165       {
00166         return invalidObjectiveVectorValue;
00167       }
00168 
00169 
00173     Fitness fitness() const
00174       {
00175         if ( invalidFitness() )
00176           {
00177             throw std::runtime_error("invalid fitness in MOEO");
00178           }
00179 //         const_cast< Fitness& >( fitnessValue ).embededDataEx = objectiveVectorValue;
00180 
00181         return fitnessValue;
00182       }
00183 
00184 
00189     void fitness(const Fitness & _fitnessValue)
00190     {
00191       fitnessValue = _fitnessValue;
00192       invalidFitnessValue = false;
00193     }
00194 
00195 
00199     void invalidateFitness()
00200     {
00201       invalidFitnessValue = true;
00202     }
00203 
00204 
00208     bool invalidFitness() const
00209       {
00210         return invalidFitnessValue;
00211       }
00212 
00213 
00217     Diversity diversity() const
00218       {
00219         if ( invalidDiversity() )
00220           {
00221             throw std::runtime_error("invalid diversity in MOEO");
00222           }
00223         return diversityValue;
00224       }
00225 
00226 
00231     void diversity(const Diversity & _diversityValue)
00232     {
00233       diversityValue = _diversityValue;
00234       invalidDiversityValue = false;
00235     }
00236 
00237 
00241     void invalidateDiversity()
00242     {
00243       invalidDiversityValue = true;
00244     }
00245 
00246 
00250     bool invalidDiversity() const
00251       {
00252         return invalidDiversityValue;
00253       }
00254 
00255 
00259     void invalidate()
00260     {
00261       invalidateObjectiveVector();
00262       invalidateFitness();
00263       invalidateDiversity();
00264     }
00265 
00266 
00270     bool invalid() const
00271       {
00272         return invalidObjectiveVector();
00273       }
00274 
00275 
00282     bool operator<(const MOEO & _other) const
00283       {
00284         return objectiveVector() < _other.objectiveVector();
00285       }
00286 
00287 
00291     virtual std::string className() const
00292       {
00293         return "MOEO";
00294       }
00295 
00296 
00301     virtual void printOn(std::ostream & _os) const
00302       {
00303         if ( invalidObjectiveVector() )
00304           {
00305             _os << "INVALID\t";
00306           }
00307         else
00308           {
00309             _os << objectiveVectorValue << '\t';
00310           }
00311       }
00312 
00313 
00318     virtual void readFrom(std::istream & _is)
00319     {
00320       std::string objectiveVector_str;
00321       int pos = _is.tellg();
00322       _is >> objectiveVector_str;
00323       if (objectiveVector_str == "INVALID")
00324         {
00325           invalidateObjectiveVector();
00326         }
00327       else
00328         {
00329           invalidObjectiveVectorValue = false;
00330           _is.seekg(pos); // rewind
00331           _is >> objectiveVectorValue;
00332         }
00333     }
00334 
00335 
00336   private:
00337 
00339     ObjectiveVector objectiveVectorValue;
00341     bool invalidObjectiveVectorValue;
00343     Fitness fitnessValue;
00345     bool invalidFitnessValue;
00347     Diversity diversityValue;
00349     bool invalidDiversityValue;
00350 
00351   };
00352 
00353 
00354 
00355 #endif /*MOEO_H_*/

Generated on Thu Mar 13 15:54:07 2008 for ParadisEO-MOEO-MultiObjectiveEvolvingObjects by  doxygen 1.4.7