moeoExpBinaryIndicatorBasedFitnessAssignment.h

00001 /* 
00002 * <moeoExpBinaryIndicatorBasedFitnessAssignment.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * 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 MOEOEXPBINARYINDICATORBASEDFITNESSASSIGNMENT_H_
00039 #define MOEOEXPBINARYINDICATORBASEDFITNESSASSIGNMENT_H_
00040 
00041 #include <math.h>
00042 #include <vector>
00043 #include <eoPop.h>
00044 #include <fitness/moeoBinaryIndicatorBasedFitnessAssignment.h>
00045 #include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
00046 #include <utils/moeoConvertPopToObjectiveVectors.h>
00047 
00053 template < class MOEOT >
00054 class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorBasedFitnessAssignment < MOEOT >
00055 {
00056 public:
00057 
00059     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00060 
00061 
00067     moeoExpBinaryIndicatorBasedFitnessAssignment(moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa = 0.05) : metric(_metric), kappa(_kappa)
00068     {}
00069 
00070 
00075     void operator()(eoPop < MOEOT > & _pop)
00076     {
00077         // 1 - setting of the bounds
00078         setup(_pop);
00079         // 2 - computing every indicator values
00080         computeValues(_pop);
00081         // 3 - setting fitnesses
00082         setFitnesses(_pop);
00083     }
00084 
00085 
00091     void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
00092     {
00093         std::vector < double > v;
00094         v.resize(_pop.size());
00095         for (unsigned int i=0; i<_pop.size(); i++)
00096         {
00097             v[i] = metric(_objVec, _pop[i].objectiveVector());
00098         }
00099         for (unsigned int i=0; i<_pop.size(); i++)
00100         {
00101             _pop[i].fitness( _pop[i].fitness() + exp(-v[i]/kappa) );
00102         }
00103     }
00104 
00105 
00112     double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
00113     {
00114         std::vector < double > v;
00115         // update every fitness values to take the new individual into account
00116         v.resize(_pop.size());
00117         for (unsigned int i=0; i<_pop.size(); i++)
00118         {
00119             v[i] = metric(_objVec, _pop[i].objectiveVector());
00120         }
00121         for (unsigned int i=0; i<_pop.size(); i++)
00122         {
00123             _pop[i].fitness( _pop[i].fitness() - exp(-v[i]/kappa) );
00124         }
00125         // compute the fitness of the new individual
00126         v.clear();
00127         v.resize(_pop.size());
00128         for (unsigned int i=0; i<_pop.size(); i++)
00129         {
00130             v[i] = metric(_pop[i].objectiveVector(), _objVec);
00131         }
00132         double result = 0;
00133         for (unsigned int i=0; i<v.size(); i++)
00134         {
00135             result -= exp(-v[i]/kappa);
00136         }
00137         return result;
00138     }
00139 
00140 
00141 protected:
00142 
00144     moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & metric;
00146     double kappa;
00148     std::vector < std::vector<double> > values;
00149 
00150 
00155     void setup(const eoPop < MOEOT > & _pop)
00156     {
00157         double min, max;
00158         for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
00159         {
00160             min = _pop[0].objectiveVector()[i];
00161             max = _pop[0].objectiveVector()[i];
00162             for (unsigned int j=1; j<_pop.size(); j++)
00163             {
00164                 min = std::min(min, _pop[j].objectiveVector()[i]);
00165                 max = std::max(max, _pop[j].objectiveVector()[i]);
00166             }
00167             // setting of the bounds for the objective i
00168             metric.setup(min, max, i);
00169         }
00170     }
00171 
00172 
00177     void computeValues(const eoPop < MOEOT > & _pop)
00178     {
00179         values.clear();
00180         values.resize(_pop.size());
00181         for (unsigned int i=0; i<_pop.size(); i++)
00182         {
00183             values[i].resize(_pop.size());
00184             for (unsigned int j=0; j<_pop.size(); j++)
00185             {
00186                 if (i != j)
00187                 {
00188                     values[i][j] = metric(_pop[i].objectiveVector(), _pop[j].objectiveVector());
00189                 }
00190             }
00191         }
00192     }
00193 
00194 
00199     void setFitnesses(eoPop < MOEOT > & _pop)
00200     {
00201         for (unsigned int i=0; i<_pop.size(); i++)
00202         {
00203             _pop[i].fitness(computeFitness(i));
00204         }
00205     }
00206 
00207 
00212     double computeFitness(const unsigned int _idx)
00213     {
00214         double result = 0;
00215         for (unsigned int i=0; i<values.size(); i++)
00216         {
00217             if (i != _idx)
00218             {
00219                 result -= exp(-values[i][_idx]/kappa);
00220             }
00221         }
00222         return result;
00223     }
00224 
00225 };
00226 
00227 #endif /*MOEOEXPBINARYINDICATORBASEDFITNESSASSIGNMENT_H_*/

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