- Main Page
- Classes
- Files

- Search for |

# moeoIndicatorBasedFitnessAssignment.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoIndicatorBasedFitnessAssignment.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 MOEOINDICATORBASEDFITNESSASSIGNMENT_H_
    00014 #define MOEOINDICATORBASEDFITNESSASSIGNMENT_H_
    00015
    00016 #include <math.h>
    00017 #include <eoPop.h>
    00018 #include <moeoConvertPopToObjectiveVectors.h>
    00019 #include <moeoFitnessAssignment.h>
    00020 #include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
    00021
    00027 template < class MOEOT >
    00028 class moeoIndicatorBasedFitnessAssignment : public moeoParetoBasedFitnessAssignment < MOEOT >
    00029 {
    00030 public:
    00031
    00033     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
    00034
    00035
    00041     moeoIndicatorBasedFitnessAssignment(moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * _metric, const double _kappa) : metric(_metric), kappa(_kappa)
    00042     {}
    00043
    00044
    00049     void operator()(eoPop < MOEOT > & _pop)
    00050     {
    00051         // 1 - setting of the bounds
    00052         setup(_pop);
    00053         // 2 - computing every indicator values
    00054         computeValues(_pop);
    00055         // 3 - setting fitnesses
    00056         setFitnesses(_pop);
    00057     }
    00058
    00059
    00065     void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
    00066     {
    00067         vector < double > v;
    00068         v.resize(_pop.size());
    00069         for (unsigned i=0; i<_pop.size(); i++)
    00070         {
    00071             v[i] = (*metric)(_objVec, _pop[i].objectiveVector());
    00072         }
    00073         for (unsigned i=0; i<_pop.size(); i++)
    00074         {
    00075             _pop[i].fitness( _pop[i].fitness() + exp(-v[i]/kappa) );
    00076         }
    00077     }
    00078
    00079
    00086     double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
    00087     {
    00088         vector < double > v;
    00089         // update every fitness values to take the new individual into account
    00090         v.resize(_pop.size());
    00091         for (unsigned i=0; i<_pop.size(); i++)
    00092         {
    00093             v[i] = (*metric)(_objVec, _pop[i].objectiveVector());
    00094         }
    00095         for (unsigned i=0; i<_pop.size(); i++)
    00096         {
    00097             _pop[i].fitness( _pop[i].fitness() - exp(-v[i]/kappa) );
    00098         }
    00099         // compute the fitness of the new individual
    00100         v.clear();
    00101         v.resize(_pop.size());
    00102         for (unsigned i=0; i<_pop.size(); i++)
    00103         {
    00104             v[i] = (*metric)(_pop[i].objectiveVector(), _objVec);
    00105         }
    00106         double result = 0;
    00107         for (unsigned i=0; i<v.size(); i++)
    00108         {
    00109             result -= exp(-v[i]/kappa);
    00110         }
    00111         return result;
    00112     }
    00113
    00114
    00115 protected:
    00116
    00118     moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * metric;
    00120     double kappa;
    00122     std::vector < std::vector<double> > values;
    00123
    00124
    00129     void setup(const eoPop < MOEOT > & _pop)
    00130     {
    00131         double min, max;
    00132         for (unsigned i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
    00133         {
    00134             min = _pop[0].objectiveVector()[i];
    00135             max = _pop[0].objectiveVector()[i];
    00136             for (unsigned j=1; j<_pop.size(); j++)
    00137             {
    00138                 min = std::min(min, _pop[j].objectiveVector()[i]);
    00139                 max = std::max(max, _pop[j].objectiveVector()[i]);
    00140             }
    00141             // setting of the bounds for the objective i
    00142             (*metric).setup(min, max, i);
    00143         }
    00144     }
    00145
    00146
    00151     void computeValues(const eoPop < MOEOT > & _pop)
    00152     {
    00153         values.clear();
    00154         values.resize(_pop.size());
    00155         for (unsigned i=0; i<_pop.size(); i++)
    00156         {
    00157             values[i].resize(_pop.size());
    00158             for (unsigned j=0; j<_pop.size(); j++)
    00159             {
    00160                 if (i != j)
    00161                 {
    00162                     values[i][j] = (*metric)(_pop[i].objectiveVector(), _pop[j].objectiveVector());
    00163                 }
    00164             }
    00165         }
    00166     }
    00167
    00168
    00173     void setFitnesses(eoPop < MOEOT > & _pop)
    00174     {
    00175         for (unsigned i=0; i<_pop.size(); i++)
    00176         {
    00177             _pop[i].fitness(computeFitness(i));
    00178         }
    00179     }
    00180
    00181
    00186     double computeFitness(const unsigned _idx)
    00187     {
    00188         double result = 0;
    00189         for (unsigned i=0; i<values.size(); i++)
    00190         {
    00191             if (i != _idx)
    00192             {
    00193                 result -= exp(-values[i][_idx]/kappa);
    00194             }
    00195         }
    00196         return result;
    00197     }
    00198
    00199 };
    00200
    00201 #endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/