- Main Page
- Classes
- Files

- Search for |

# moeoIBEA.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoIBEASorting.h
    00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
    00006 /*
    00007     This library...
    00008
    00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
    00010  */
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #ifndef _moeoIBEASorting_h
    00015 #define _moeoIBEASorting_h
    00016
    00017 #include <math.h>
    00018 #include <list>
    00019 #include <eoPop.h>
    00020 #include <eoPerf2Worth.h>
    00021 #include "moeoBinaryQualityIndicator.h"
    00022
    00023
    00028 template < class EOT, class Fitness > class moeoIBEA:public eoPerf2WorthCached < EOT,
    00029   double >
    00030 {
    00031
    00032 public:
    00034   using eoPerf2WorthCached < EOT, double >::value;
    00035
    00036     moeoIBEA (moeoBinaryQualityIndicator < Fitness > *_I)
    00037   {
    00038     I = _I;
    00039   }
    00040
    00041
    00046   void calculate_worths (const eoPop < EOT > &_pop)
    00047   {
    00048     /* resizing the worths beforehand */
    00049     value ().resize (_pop.size ());
    00050
    00051     /* computation and setting of the bounds for each objective */
    00052     setBounds (_pop);
    00053
    00054     /* computation of the fitness for each individual */
    00055     fitnesses (_pop);
    00056
    00057     // higher is better, so invert the value
    00058     double max = *std::max_element (value ().begin (), value ().end ());
    00059     for (unsigned i = 0; i < value ().size (); i++)
    00060       value ()[i] = max - value ()[i];
    00061   }
    00062
    00063
    00064 protected:
    00065
    00067   moeoBinaryQualityIndicator < Fitness > *I;
    00068
    00069   virtual void setBounds (const eoPop < EOT > &_pop) = 0;
    00070   virtual void fitnesses (const eoPop < EOT > &_pop) = 0;
    00071
    00072 };
    00073
    00074
    00075
    00076
    00077
    00084 template < class EOT, class Fitness = typename EOT::Fitness > class moeoIBEASorting:public moeoIBEA < EOT,
    00085   Fitness
    00086   >
    00087 {
    00088
    00089 public:
    00090
    00096   moeoIBEASorting (moeoBinaryQualityIndicator < Fitness > *_I,
    00097                    const double _kappa):
    00098     moeoIBEA <
    00099     EOT,
    00100   Fitness > (_I)
    00101   {
    00102     kappa = _kappa;
    00103   }
    00104
    00105
    00106 private:
    00108   using moeoIBEA < EOT, Fitness >::I;
    00110   using moeoIBEA < EOT, Fitness >::value;
    00112   double
    00113     kappa;
    00114
    00115
    00120   void
    00121   setBounds (const eoPop < EOT > &_pop)
    00122   {
    00123     typedef
    00124       typename
    00125       EOT::Fitness::fitness_traits
    00126       traits;
    00127     double
    00128       min,
    00129       max;
    00130     for (unsigned i = 0; i < traits::nObjectives (); i++)
    00131       {
    00132         min = _pop[0].fitness ()[i];
    00133         max = _pop[0].fitness ()[i];
    00134         for (unsigned j = 1; j < _pop.size (); j++)
    00135           {
    00136             min = std::min (min, _pop[j].fitness ()[i]);
    00137             max = std::max (max, _pop[j].fitness ()[i]);
    00138           }
    00139         // setting of the bounds for the objective i
    00140         I->setBounds (i, min, max);
    00141       }
    00142   }
    00143
    00144
    00149   void
    00150   fitnesses (const eoPop < EOT > &_pop)
    00151   {
    00152     // reprsentation of the fitness components
    00153     std::vector < std::vector < double > >
    00154     fitComponents (_pop.size (), _pop.size ());
    00155     // the maximum absolute indicator value
    00156     double
    00157       maxAbsoluteIndicatorValue = 0;
    00158
    00159     // computation of the indicator values and of the maximum absolute indicator value
    00160     for (unsigned i = 0; i < _pop.size (); i++)
    00161       for (unsigned j = 0; j < _pop.size (); j++)
    00162         if (i != j)
    00163           {
    00164             fitComponents[i][j] =
    00165               (*I) (_pop[i].fitness (), _pop[j].fitness ());
    00166             maxAbsoluteIndicatorValue =
    00167               std::max (maxAbsoluteIndicatorValue,
    00168                         fabs (fitComponents[i][j]));
    00169           }
    00170
    00171     // computation of the fitness components for each pair of individuals
    00172     // if maxAbsoluteIndicatorValue==0, every individuals have the same fitness values for all objectives (already = 0)
    00173     if (maxAbsoluteIndicatorValue != 0)
    00174       for (unsigned i = 0; i < _pop.size (); i++)
    00175         for (unsigned j = 0; j < _pop.size (); j++)
    00176           if (i != j)
    00177             fitComponents[i][j] =
    00178               exp (-fitComponents[i][j] /
    00179                    (maxAbsoluteIndicatorValue * kappa));
    00180
    00181     // computation of the fitness for each individual
    00182     for (unsigned i = 0; i < _pop.size (); i++)
    00183       {
    00184         value ()[i] = 0;
    00185         for (unsigned j = 0; j < _pop.size (); j++)
    00186           if (i != j)
    00187             value ()[i] += fitComponents[j][i];
    00188       }
    00189   }
    00190
    00191 };
    00192
    00193
    00194
    00195
    00196
    00203 template < class EOT, class FitnessEval = typename EOT::Fitness::FitnessEval > class moeoIBEAStochSorting:public moeoIBEA < EOT,
    00204   FitnessEval
    00205   >
    00206 {
    00207
    00208 public:
    00209
    00214 moeoIBEAStochSorting (moeoBinaryQualityIndicator < FitnessEval > *_I):moeoIBEA < EOT,
    00215     FitnessEval >
    00216     (_I)
    00217   {
    00218   }
    00219
    00220
    00221 private:
    00223   using moeoIBEAStochSorting < EOT, FitnessEval >::I;
    00225   using moeoIBEAStochSorting < EOT, FitnessEval >::value;
    00226
    00227
    00231   static double
    00232   zero ()
    00233   {
    00234     return 1e-7;
    00235   }
    00236
    00237
    00242   void
    00243   setBounds (const eoPop < EOT > &_pop)
    00244   {
    00245     typedef
    00246       typename
    00247       EOT::Fitness::FitnessTraits
    00248       traits;
    00249     double
    00250       min,
    00251       max;
    00252     for (unsigned i = 0; i < traits::nObjectives (); i++)
    00253       {
    00254         min = _pop[0].fitness ().minimum (i);
    00255         max = _pop[0].fitness ().maximum (i);
    00256         for (unsigned j = 1; j < _pop.size (); j++)
    00257           {
    00258             min = std::min (min, _pop[j].fitness ().minimum (i));
    00259             max = std::max (max, _pop[j].fitness ().maximum (i));
    00260           }
    00261         // setting of the bounds for the ith objective
    00262         I->setBounds (i, min, max);
    00263       }
    00264   }
    00265
    00266
    00271   void
    00272   fitnesses (const eoPop < EOT > &_pop)
    00273   {
    00274     typedef
    00275       typename
    00276       EOT::Fitness::FitnessTraits
    00277       traits;
    00278     unsigned
    00279       nEval = traits::nEvaluations ();
    00280     unsigned
    00281       index;
    00282     double
    00283       eiv,
    00284       p,
    00285       sumP,
    00286       iValue;
    00287     std::list < std::pair < double, unsigned > >
    00288       l;
    00289     std::vector < unsigned >
    00290     n (_pop.size ());
    00291
    00292     for (unsigned ind = 0; ind < _pop.size (); ind++)
    00293       {
    00294         value ()[ind] = 0.0;    // fitness value for the individual ind
    00295         for (unsigned eval = 0; eval < nEval; eval++)
    00296           {
    00297
    00298             // I-values computation for the evaluation eval of the individual ind
    00299             l.clear ();
    00300             for (unsigned i = 0; i < _pop.size (); i++)
    00301               {
    00302                 if (i != ind)
    00303                   {
    00304                     for (unsigned j = 0; j < nEval; j++)
    00305                       {
    00306                         std::pair < double, unsigned >
    00307                           pa;
    00308                         // I-value
    00309                         pa.first =
    00310                           (*I) (_pop[ind].fitness ()[eval],
    00311                                 _pop[i].fitness ()[j]);
    00312                         // index of the individual
    00313                         pa.second = i;
    00314                         // append this to the list
    00315                         l.push_back (pa);
    00316                       }
    00317                   }
    00318               }
    00319
    00320             // sorting of the I-values (in decreasing order)
    00321             l.sort ();
    00322
    00323             // computation of the Expected Indicator Value (eiv) for the evaluation eval of the individual ind
    00324             eiv = 0.0;
    00325             n.assign (n.size (), 0);    // n[i]==0 for all i
    00326             sumP = 0.0;
    00327             while (((1 - sumP) > zero ()) && (l.size () > 0))
    00328               {
    00329                 // we use the last element of the list (the greatest one)
    00330                 iValue = l.back ().first;
    00331                 index = l.back ().second;
    00332                 // computation of the probability to appear
    00333                 p = (1.0 / (nEval - n[index])) * (1.0 - sumP);
    00334                 // eiv update
    00335                 eiv += p * iValue;
    00336                 // update of the number of elements for individual index
    00337                 n[index]++;
    00338                 // removing the last element of the list
    00339                 l.pop_back ();
    00340                 // sum of p update
    00341                 sumP += p;
    00342               }
    00343             value ()[ind] += eiv / nEval;
    00344           }
    00345       }
    00346
    00347   }
    00348
    00349 };
    00350
    00351
    00352
    00353
    00354
    00361 template < class EOT, class FitnessEval = typename EOT::Fitness::FitnessEval > class moeoIBEAAvgSorting:public moeoIBEA < EOT,
    00362   FitnessEval
    00363   >
    00364 {
    00365
    00366 public:
    00367
    00373   moeoIBEAAvgSorting (moeoBinaryQualityIndicator < FitnessEval > *_I,
    00374                       const double _kappa):
    00375     moeoIBEA <
    00376     EOT,
    00377   FitnessEval > (_I)
    00378   {
    00379     kappa = _kappa;
    00380   }
    00381
    00382
    00383 private:
    00385   using moeoIBEAAvgSorting < EOT, FitnessEval >::I;
    00387   using moeoIBEAAvgSorting < EOT, FitnessEval >::value;
    00389   double
    00390     kappa;
    00391
    00392
    00397   void
    00398   setBounds (const eoPop < EOT > &_pop)
    00399   {
    00400     typedef
    00401       typename
    00402       EOT::Fitness::FitnessTraits
    00403       traits;
    00404     double
    00405       min,
    00406       max;
    00407     for (unsigned i = 0; i < traits::nObjectives (); i++)
    00408       {
    00409         min = _pop[0].fitness ().averagedParetoFitnessObject ()[i];
    00410         max = _pop[0].fitness ().averagedParetoFitnessObject ()[i];
    00411         for (unsigned j = 1; j < _pop.size (); j++)
    00412           {
    00413             min =
    00414               std::min (min,
    00415                         _pop[j].fitness ().averagedParetoFitnessObject ()[i]);
    00416             max =
    00417               std::max (max,
    00418                         _pop[j].fitness ().averagedParetoFitnessObject ()[i]);
    00419           }
    00420         // setting of the bounds for the objective i
    00421         I->setBounds (i, min, max);
    00422       }
    00423   }
    00424
    00425
    00430   void
    00431   fitnesses (const eoPop < EOT > &_pop)
    00432   {
    00433     // reprsentation of the fitness components
    00434     std::vector < std::vector < double > >
    00435     fitComponents (_pop.size (), _pop.size ());
    00436     // the maximum absolute indicator value
    00437     double
    00438       maxAbsoluteIndicatorValue = 0;
    00439
    00440     // computation of the indicator values and of the maximum absolute indicator value
    00441     for (unsigned i = 0; i < _pop.size (); i++)
    00442       for (unsigned j = 0; j < _pop.size (); j++)
    00443         if (i != j)
    00444           {
    00445             fitComponents[i][j] =
    00446               (*I) (_pop[i].fitness ().averagedParetoFitnessObject (),
    00447                     _pop[j].fitness ().averagedParetoFitnessObject ());
    00448             maxAbsoluteIndicatorValue =
    00449               std::max (maxAbsoluteIndicatorValue,
    00450                         fabs (fitComponents[i][j]));
    00451           }
    00452
    00453     // computation of the fitness components for each pair of individuals
    00454     // if maxAbsoluteIndicatorValue==0, every individuals have the same fitness values for all objectives (already = 0)
    00455     if (maxAbsoluteIndicatorValue != 0)
    00456       for (unsigned i = 0; i < _pop.size (); i++)
    00457         for (unsigned j = 0; j < _pop.size (); j++)
    00458           if (i != j)
    00459             fitComponents[i][j] =
    00460               exp (-fitComponents[i][j] /
    00461                    (maxAbsoluteIndicatorValue * kappa));
    00462
    00463     // computation of the fitness for each individual
    00464     for (unsigned i = 0; i < _pop.size (); i++)
    00465       {
    00466         value ()[i] = 0;
    00467         for (unsigned j = 0; j < _pop.size (); j++)
    00468           if (i != j)
    00469             value ()[i] += fitComponents[j][i];
    00470       }
    00471   }
    00472
    00473 };
    00474
    00475
    00476 #endif