# ParadisEO-MOEOMovingObjects: moeoIteratedIBMOLS.h Source File

# 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/moeoBinaryIndicatorBasedFitnessAssignment.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         moeoBinaryIndicatorBasedFitnessAssignment < 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()) // the given archive contains the individual i
    00138             {
    00139                 // add it to the resulting pop
    00140                 _pop[i] = _arch[shuffle[i]];
    00141                 // apply noise
    00142                 for (unsigned int j=0; j<nNoiseIterations; j++)
    00143                 {
    00144                     monOp(_pop[i]);
    00145                 }
    00146             }
    00147             else // a random solution needs to be added
    00148             {
    00149                 // random initialization
    00150                 randomMonOp(_pop[i]);
    00151             }
    00152             // evaluation of the new individual
    00153             _pop[i].invalidate();
    00154             eval(_pop[i]);
    00155         }
    00156     }
    00157
    00158
    00159
    00160
    00161
    00163 // A DEVELOPPER RAPIDEMENT POUR TESTER AVEC CROSSOVER //
    00164     /*
    00165         void generateNewSolutions2(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
    00166         {
    00167                 // here, we must have a QuadOp !
    00168                 //eoQuadOp < MOEOT > quadOp;
    00169                 rsCrossQuad quadOp;
    00170                 // shuffle vector for the random selection of individuals
    00171                 vector<unsigned int> shuffle;
    00172                 shuffle.resize(_arch.size());
    00173                 // init shuffle
    00174                 for (unsigned int i=0; i<shuffle.size(); i++)
    00175                 {
    00176                         shuffle[i] = i;
    00177                 }
    00178                 // randomize shuffle
    00179                 UF_random_generator <unsigned int int> gen;
    00180                 std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
    00181                 // start the creation of new solutions
    00182                 unsigned int i=0;
    00183                 while ((i<_pop.size()-1) && (i<_arch.size()-1))
    00184                 {
    00185                         _pop[i] = _arch[shuffle[i]];
    00186                         _pop[i+1] = _arch[shuffle[i+1]];
    00187                         // then, apply the operator nIterationsNoise times
    00188                         for (unsigned int j=0; j<nNoiseIterations; j++)
    00189                         {
    00190                                 quadOp(_pop[i], _pop[i+1]);
    00191                         }
    00192                         eval(_pop[i]);
    00193                         eval(_pop[i+1]);
    00194                         i=i+2;
    00195                 }
    00196                 // do we have to add some random solutions ?
    00197                 while (i<_pop.size())
    00198                 {
    00199                         randomMonOp(_pop[i]);
    00200                         eval(_pop[i]);
    00201                         i++;
    00202                 }
    00203         }
    00204         */
    00206
    00207
    00208
    00209
    00210
    00211 };
    00212
    00213 #endif /*MOEOITERATEDIBMOLS_H_*/