moeoIteratedIBMOLS.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoIteratedIBMOLS.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 MOEOITERATEDIBMOLS_H_
00014 #define MOEOITERATEDIBMOLS_H_
00015 
00016 #include <eoContinue.h>
00017 #include <eoEvalFunc.h>
00018 #include <eoOp.h>
00019 #include <eoPop.h>
00020 #include <utils/rnd_generators.h>
00021 #include <moMove.h>
00022 #include <moMoveInit.h>
00023 #include <moNextMove.h>
00024 #include <algo/moeoIBMOLS.h>
00025 #include <algo/moeoLS.h>
00026 #include <archive/moeoArchive.h>
00027 #include <fitness/moeoIndicatorBasedFitnessAssignment.h>
00028 #include <move/moeoMoveIncrEval.h>
00029 
00030 
00031 
00032 //#include <rsCrossQuad.h>
00033 
00034 
00035 
00040 template < class MOEOT, class Move >
00041 class moeoIteratedIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
00042 {
00043 public:
00044 
00046     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00047 
00048 
00061     moeoIteratedIBMOLS(
00062         moMoveInit < Move > & _moveInit,
00063         moNextMove < Move > & _nextMove,
00064         eoEvalFunc < MOEOT > & _eval,
00065         moeoMoveIncrEval < Move > & _moveIncrEval,
00066         moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
00067         eoContinue < MOEOT > & _continuator,
00068         eoMonOp < MOEOT > & _monOp,
00069         eoMonOp < MOEOT > & _randomMonOp,
00070         unsigned int _nNoiseIterations=1
00071     ) :
00072             ibmols(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator),
00073             eval(_eval),
00074             continuator(_continuator),
00075             monOp(_monOp),
00076             randomMonOp(_randomMonOp),
00077             nNoiseIterations(_nNoiseIterations)
00078     {}
00079 
00080 
00086     void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch)
00087     {
00088         _arch.update(_pop);
00089         ibmols(_pop, _arch);
00090         while (continuator(_arch))
00091         {
00092             // generate new solutions from the archive
00093             generateNewSolutions(_pop, _arch);
00094             // apply the local search (the global archive is updated in the sub-function)
00095             ibmols(_pop, _arch);
00096         }
00097     }
00098 
00099 
00100 private:
00101 
00103     moeoIBMOLS < MOEOT, Move > ibmols;
00105     eoEvalFunc < MOEOT > & eval;
00107     eoContinue < MOEOT > & continuator;
00109     eoMonOp < MOEOT > & monOp;
00111     eoMonOp < MOEOT > & randomMonOp;
00113     unsigned int nNoiseIterations;
00114 
00115 
00121     void generateNewSolutions(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
00122     {
00123         // shuffle vector for the random selection of individuals
00124         vector<unsigned int> shuffle;
00125         shuffle.resize(std::max(_pop.size(), _arch.size()));
00126         // init shuffle
00127         for (unsigned int i=0; i<shuffle.size(); i++)
00128         {
00129             shuffle[i] = i;
00130         }
00131         // randomize shuffle
00132         UF_random_generator <unsigned int> gen;
00133         std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
00134         // start the creation of new solutions
00135         for (unsigned int i=0; i<_pop.size(); i++)
00136         {
00137             if (shuffle[i] < _arch.size())
00138                 // the given archive contains the individual i
00139             {
00140                 // add it to the resulting pop
00141                 _pop[i] = _arch[shuffle[i]];
00142                 // then, apply the operator nIterationsNoise times
00143                 for (unsigned int j=0; j<nNoiseIterations; j++)
00144                 {
00145                     monOp(_pop[i]);
00146                 }
00147             }
00148             else
00149                 // a randomly generated solution needs to be added
00150             {
00151                 // random initialization
00152                 randomMonOp(_pop[i]);
00153             }
00154             // evaluation of the new individual
00155             _pop[i].invalidate();
00156             eval(_pop[i]);
00157         }
00158     }
00159 
00160 
00161 
00162 
00163 
00165 // A DEVELOPPER RAPIDEMENT POUR TESTER AVEC CROSSOVER //
00166     /*
00167         void generateNewSolutions2(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
00168         {
00169                 // here, we must have a QuadOp !
00170                 //eoQuadOp < MOEOT > quadOp;
00171                 rsCrossQuad quadOp;
00172                 // shuffle vector for the random selection of individuals
00173                 vector<unsigned int> shuffle;
00174                 shuffle.resize(_arch.size());
00175                 // init shuffle
00176                 for (unsigned int i=0; i<shuffle.size(); i++)
00177                 {
00178                         shuffle[i] = i;
00179                 }
00180                 // randomize shuffle
00181                 UF_random_generator <unsigned int int> gen;
00182                 std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
00183                 // start the creation of new solutions
00184                 unsigned int i=0;
00185                 while ((i<_pop.size()-1) && (i<_arch.size()-1))
00186                 {
00187                         _pop[i] = _arch[shuffle[i]];
00188                         _pop[i+1] = _arch[shuffle[i+1]];
00189                         // then, apply the operator nIterationsNoise times
00190                         for (unsigned int j=0; j<nNoiseIterations; j++)
00191                         {
00192                                 quadOp(_pop[i], _pop[i+1]);
00193                         }
00194                         eval(_pop[i]);
00195                         eval(_pop[i+1]);
00196                         i=i+2;
00197                 }
00198                 // do we have to add some random solutions ?
00199                 while (i<_pop.size())
00200                 {
00201                         randomMonOp(_pop[i]);
00202                         eval(_pop[i]);
00203                         i++;
00204                 }
00205         }
00206         */
00208 
00209 
00210 
00211 
00212 
00213 };
00214 
00215 #endif /*MOEOITERATEDIBMOLS_H_*/

Generated on Mon Jul 2 16:05:01 2007 for ParadisEO-MOEO by  doxygen 1.4.7