moeoAchievementFitnessAssignment.h

00001 /* 
00002 * <moeoAchievementFitnessAssignment.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * AbdelHakim Deneche, 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 MOEOACHIEVEMENTFITNESSASSIGNMENT_H_
00039 #define MOEOACHIEVEMENTFITNESSASSIGNMENT_H_
00040 
00041 #include <vector>
00042 #include <eoPop.h>
00043 #include <fitness/moeoScalarFitnessAssignment.h>
00044 
00048 template < class MOEOT >
00049 class moeoAchievementFitnessAssignment : public moeoScalarFitnessAssignment < MOEOT >
00050 {
00051 public:
00052 
00054     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00055 
00056 
00063     moeoAchievementFitnessAssignment(ObjectiveVector & _reference, std::vector < double > & _lambdas, double _spn=0.0001) : reference(_reference), lambdas(_lambdas), spn(_spn)
00064     {
00065         // consistency check
00066         if ((spn < 0.0) || (spn > 1.0))
00067         {
00068             std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
00069             spn = 0.0001;
00070         }
00071     }
00072 
00073 
00079     moeoAchievementFitnessAssignment(ObjectiveVector & _reference, double _spn=0.0001) : reference(_reference), spn(_spn)
00080     {
00081         // compute the default values for lambdas
00082         lambdas  = std::vector < double > (ObjectiveVector::nObjectives());
00083         for (unsigned int i=0 ; i<lambdas.size(); i++)
00084         {
00085             lambdas[i] = 1.0 / ObjectiveVector::nObjectives();
00086         }
00087         // consistency check
00088         if ((spn < 0.0) || (spn > 1.0))
00089         {
00090             std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
00091             spn = 0.0001;
00092         }
00093     }
00094 
00095 
00100     virtual void operator()(eoPop < MOEOT > & _pop)
00101     {
00102         for (unsigned int i=0; i<_pop.size() ; i++)
00103         {
00104             compute(_pop[i]);
00105         }
00106     }
00107 
00108 
00114     void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
00115     {
00116         // nothing to do ;-)
00117     }
00118 
00119 
00124     void setReference(const ObjectiveVector & _reference)
00125     {
00126         reference = _reference;
00127     }
00128 
00129 
00130 private:
00131 
00133     ObjectiveVector reference;
00135     std::vector < double > lambdas;
00137     double spn;
00138 
00139 
00143     double inf() const
00144     {
00145         return std::numeric_limits<double>::max();
00146     }
00147 
00148 
00153     void compute(MOEOT & _moeo)
00154     {
00155         unsigned int nobj = MOEOT::ObjectiveVector::nObjectives();
00156         double temp;
00157         double min = inf();
00158         double sum = 0;
00159         for (unsigned int obj=0; obj<nobj; obj++)
00160         {
00161             temp = lambdas[obj] * (reference[obj] - _moeo.objectiveVector()[obj]);
00162             min = std::min(min, temp);
00163             sum += temp;
00164         }
00165         _moeo.fitness(min + spn*sum);
00166     }
00167 
00168 };
00169 
00170 #endif /*MOEOACHIEVEMENTFITNESSASSIGNMENT_H_*/

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