- Main Page
- Classes
- Files

- Search for |

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