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 
00058 template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
00059 class MOEO : public EO < MOEOObjectiveVector >
00060 {
00061 public:
00062 
00064     typedef MOEOObjectiveVector ObjectiveVector;
00065 
00067     typedef MOEOFitness Fitness;
00068 
00070     typedef MOEODiversity Diversity;
00071 
00072 
00076     MOEO()
00077     {
00078         // default values for every parameters
00079         objectiveVectorValue = ObjectiveVector();
00080         fitnessValue = Fitness();
00081         diversityValue = Diversity();
00082         // invalidate all
00083         invalidate();
00084     }
00085 
00086 
00090     virtual ~MOEO() {};
00091 
00092 
00096     ObjectiveVector objectiveVector() const
00097     {
00098         if ( invalidObjectiveVector() )
00099         {
00100             throw std::runtime_error("invalid objective vector in MOEO");
00101         }
00102         return objectiveVectorValue;
00103     }
00104 
00105 
00110     void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
00111     {
00112         objectiveVectorValue = _objectiveVectorValue;
00113         invalidObjectiveVectorValue = false;
00114     }
00115 
00116 
00120     void invalidateObjectiveVector()
00121     {
00122         invalidObjectiveVectorValue = true;
00123     }
00124 
00125 
00129     bool invalidObjectiveVector() const
00130     {
00131         return invalidObjectiveVectorValue;
00132     }
00133 
00134 
00138     Fitness fitness() const
00139     {
00140         if ( invalidFitness() )
00141         {
00142             throw std::runtime_error("invalid fitness in MOEO");
00143         }
00144         return fitnessValue;
00145     }
00146 
00147 
00152     void fitness(const Fitness & _fitnessValue)
00153     {
00154         fitnessValue = _fitnessValue;
00155         invalidFitnessValue = false;
00156     }
00157 
00158 
00162     void invalidateFitness()
00163     {
00164         invalidFitnessValue = true;
00165     }
00166 
00167 
00171     bool invalidFitness() const
00172     {
00173         return invalidFitnessValue;
00174     }
00175 
00176 
00180     Diversity diversity() const
00181     {
00182         if ( invalidDiversity() )
00183         {
00184             throw std::runtime_error("invalid diversity in MOEO");
00185         }
00186         return diversityValue;
00187     }
00188 
00189 
00194     void diversity(const Diversity & _diversityValue)
00195     {
00196         diversityValue = _diversityValue;
00197         invalidDiversityValue = false;
00198     }
00199 
00200 
00204     void invalidateDiversity()
00205     {
00206         invalidDiversityValue = true;
00207     }
00208 
00209 
00213     bool invalidDiversity() const
00214     {
00215         return invalidDiversityValue;
00216     }
00217 
00218 
00222     void invalidate()
00223     {
00224         invalidateObjectiveVector();
00225         invalidateFitness();
00226         invalidateDiversity();
00227     }
00228 
00229 
00233     bool invalid() const
00234     {
00235         return invalidObjectiveVector();
00236     }
00237 
00238 
00245     bool operator<(const MOEO & _other) const
00246     {
00247         return objectiveVector() < _other.objectiveVector();
00248     }
00249 
00250 
00254     virtual std::string className() const
00255     {
00256         return "MOEO";
00257     }
00258 
00259 
00264     virtual void printOn(std::ostream & _os) const
00265     {
00266         if ( invalidObjectiveVector() )
00267         {
00268             _os << "INVALID\t";
00269         }
00270         else
00271         {
00272             _os << objectiveVectorValue << '\t';
00273         }
00274     }
00275 
00276 
00281     virtual void readFrom(std::istream & _is)
00282     {
00283         std::string objectiveVector_str;
00284         int pos = _is.tellg();
00285         _is >> objectiveVector_str;
00286         if (objectiveVector_str == "INVALID")
00287         {
00288             invalidateObjectiveVector();
00289         }
00290         else
00291         {
00292             invalidObjectiveVectorValue = false;
00293             _is.seekg(pos); // rewind
00294             _is >> objectiveVectorValue;
00295         }
00296     }
00297 
00298 
00299 private:
00300 
00302     ObjectiveVector objectiveVectorValue;
00304     bool invalidObjectiveVectorValue;
00306     Fitness fitnessValue;
00308     bool invalidFitnessValue;
00310     Diversity diversityValue;
00312     bool invalidDiversityValue;
00313 
00314 };
00315 
00316 #endif /*MOEO_H_*/

Generated on Fri Oct 12 15:16:04 2007 for ParadisEO-MOEO:MultiObjectiveEvolvingObjects by  doxygen 1.4.7