- Main Page
- Classes
- Files

- Search for |

# moeoAchievementFitnessAssignment.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoAchievementFitnessAssignment.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 MOEOACHIEVEMENTFITNESSASSIGNMENT_H_
    00014 #define MOEOACHIEVEMENTFITNESSASSIGNMENT_H_
    00015
    00016 #include <vector>
    00017 #include <eoPop.h>
    00018 #include <fitness/moeoScalarFitnessAssignment.h>
    00019
    00023 template < class MOEOT >
    00024 class moeoAchievementFitnessAssignment : public moeoScalarFitnessAssignment < MOEOT >
    00025 {
    00026 public:
    00027
    00029     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
    00030
    00031
    00038     moeoAchievementFitnessAssignment(ObjectiveVector & _reference, std::vector < double > & _lambdas, double _spn=0.0001) : reference(_reference), lambdas(_lambdas), spn(_spn)
    00039     {
    00040         // consistency check
    00041         if ((spn < 0.0) || (spn > 1.0))
    00042         {
    00043             std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
    00044             spn = 0.0001;
    00045         }
    00046     }
    00047
    00048
    00054     moeoAchievementFitnessAssignment(ObjectiveVector & _reference, double _spn=0.0001) : reference(_reference), spn(_spn)
    00055     {
    00056         // compute the default values for lambdas
    00057         lambdas  = std::vector < double > (ObjectiveVector::nObjectives());
    00058         for (unsigned int i=0 ; i<lambdas.size(); i++)
    00059         {
    00060             lambdas[i] = 1.0 / ObjectiveVector::nObjectives();
    00061         }
    00062         // consistency check
    00063         if ((spn < 0.0) || (spn > 1.0))
    00064         {
    00065             std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
    00066             spn = 0.0001;
    00067         }
    00068     }
    00069
    00070
    00075     virtual void operator()(eoPop < MOEOT > & _pop)
    00076     {
    00077         for (unsigned int i=0; i<_pop.size() ; i++)
    00078         {
    00079             compute(_pop[i]);
    00080         }
    00081     }
    00082
    00083
    00089     void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
    00090     {
    00091         // nothing to do ;-)
    00092     }
    00093
    00094
    00099     void setReference(const ObjectiveVector & _reference)
    00100     {
    00101         reference = _reference;
    00102     }
    00103
    00104
    00105 private:
    00106
    00108     ObjectiveVector reference;
    00110     std::vector < double > lambdas;
    00112     double spn;
    00113
    00114
    00118     double inf() const
    00119     {
    00120         return std::numeric_limits<double>::max();
    00121     }
    00122
    00123
    00128     void compute(MOEOT & _moeo)
    00129     {
    00130         unsigned int nobj = MOEOT::ObjectiveVector::nObjectives();
    00131         double temp;
    00132         double min = inf();
    00133         double sum = 0;
    00134         for (unsigned int obj=0; obj<nobj; obj++)
    00135         {
    00136             temp = lambdas[obj] * (reference[obj] - _moeo.objectiveVector()[obj]);
    00137             min = std::min(min, temp);
    00138             sum += temp;
    00139         }
    00140         _moeo.fitness(min + spn*sum);
    00141     }
    00142
    00143 };
    00144
    00145 #endif /*MOEOACHIEVEMENTFITNESSASSIGNMENT_H_*/