- Main Page
- Classes
- Files

- Search for |

# moeoIBMOLS.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoIBMOLS.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 MOEOIBMOLS_H_
    00014 #define MOEOIBMOLS_H_
    00015
    00016 #include <eoContinue.h>
    00017 #include <eoEvalFunc.h>
    00018 #include <eoPop.h>
    00019 #include <moMove.h>
    00020 #include <moMoveInit.h>
    00021 #include <moNextMove.h>
    00022 #include <algo/moeoLS.h>
    00023 #include <archive/moeoArchive.h>
    00024 #include <fitness/moeoIndicatorBasedFitnessAssignment.h>
    00025 #include <move/moeoMoveIncrEval.h>
    00026
    00031 template < class MOEOT, class Move >
    00032 class moeoIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
    00033 {
    00034 public:
    00035
    00037     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
    00038
    00039
    00049     moeoIBMOLS(
    00050         moMoveInit < Move > & _moveInit,
    00051         moNextMove < Move > & _nextMove,
    00052         eoEvalFunc < MOEOT > & _eval,
    00053         moeoMoveIncrEval < Move > & _moveIncrEval,
    00054         moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
    00055         eoContinue < MOEOT > & _continuator
    00056     ) :
    00057             moveInit(_moveInit),
    00058             nextMove(_nextMove),
    00059             eval(_eval),
    00060             moveIncrEval(_moveIncrEval),
    00061             fitnessAssignment (_fitnessAssignment),
    00062             continuator (_continuator)
    00063     {}
    00064
    00065
    00072     void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch)
    00073     {
    00074         // evaluation of the objective values
    00075         /*
    00076                 for (unsigned int i=0; i<_pop.size(); i++)
    00077                 {
    00078                     eval(_pop[i]);
    00079                 }
    00080         */
    00081         // fitness assignment for the whole population
    00082         fitnessAssignment(_pop);
    00083         // creation of a local archive
    00084         moeoArchive < MOEOT > archive;
    00085         // creation of another local archive (for the stopping criteria)
    00086         moeoArchive < MOEOT > previousArchive;
    00087         // update the archive with the initial population
    00088         archive.update(_pop);
    00089         do
    00090         {
    00091             previousArchive.update(archive);
    00092             oneStep(_pop);
    00093             archive.update(_pop);
    00094         } while ( (! archive.equals(previousArchive)) && (continuator(_arch)) );
    00095         _arch.update(archive);
    00096     }
    00097
    00098
    00099 private:
    00100
    00102     moMoveInit < Move > & moveInit;
    00104     moNextMove < Move > & nextMove;
    00106     eoEvalFunc < MOEOT > & eval;
    00108     moeoMoveIncrEval < Move > & moveIncrEval;
    00110     moeoIndicatorBasedFitnessAssignment < MOEOT > & fitnessAssignment;
    00112     eoContinue < MOEOT > & continuator;
    00113
    00114
    00119     void oneStep (eoPop < MOEOT > & _pop)
    00120     {
    00122         int ext_0_idx, ext_1_idx;
    00123         ObjectiveVector ext_0_objVec, ext_1_objVec;
    00125         // the move
    00126         Move move;
    00127         // the objective vector and the fitness of the current solution
    00128         ObjectiveVector x_objVec;
    00129         double x_fitness;
    00130         // the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one)
    00131         int worst_idx;
    00132         ObjectiveVector worst_objVec;
    00133         double worst_fitness;
    00134         // the index current of the current solution to be explored
    00135         unsigned int i=0;
    00136         // initilization of the move for the first individual
    00137         moveInit(move, _pop[i]);
    00138         while (i<_pop.size() && continuator(_pop))
    00139         {
    00140             // x = one neigbour of pop[i]
    00141             // evaluate x in the objective space
    00142             x_objVec = moveIncrEval(move, _pop[i]);
    00143             // update every fitness values to take x into account and compute the fitness of x
    00144             x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec);
    00145
    00149 // qui sont les extremes ? (=> min only  !!!)
    00150             ext_0_idx = -1;
    00151             ext_0_objVec = x_objVec;
    00152             ext_1_idx = -1;
    00153             ext_1_objVec = x_objVec;
    00154             for (unsigned int k=0; k<_pop.size(); k++)
    00155             {
    00156                 // ext_0
    00157                 if (_pop[k].objectiveVector()[0] < ext_0_objVec[0])
    00158                 {
    00159                     ext_0_idx = k;
    00160                     ext_0_objVec = _pop[k].objectiveVector();
    00161                 }
    00162                 else if ( (_pop[k].objectiveVector()[0] == ext_0_objVec[0]) && (_pop[k].objectiveVector()[1] < ext_0_objVec[1]) )
    00163                 {
    00164                     ext_0_idx = k;
    00165                     ext_0_objVec = _pop[k].objectiveVector();
    00166                 }
    00167                 // ext_1
    00168                 else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1])
    00169                 {
    00170                     ext_1_idx = k;
    00171                     ext_1_objVec = _pop[k].objectiveVector();
    00172                 }
    00173                 else if ( (_pop[k].objectiveVector()[1] == ext_1_objVec[1]) && (_pop[k].objectiveVector()[0] < ext_1_objVec[0]) )
    00174                 {
    00175                     ext_1_idx = k;
    00176                     ext_1_objVec = _pop[k].objectiveVector();
    00177                 }
    00178             }
    00179 // worst init
    00180             if (ext_0_idx == -1)
    00181             {
    00182                 unsigned int ind = 0;
    00183                 while (ind == ext_1_idx)
    00184                 {
    00185                     ind++;
    00186                 }
    00187                 worst_idx = ind;
    00188                 worst_objVec = _pop[ind].objectiveVector();
    00189                 worst_fitness = _pop[ind].fitness();
    00190             }
    00191             else if (ext_1_idx == -1)
    00192             {
    00193                 unsigned int ind = 0;
    00194                 while (ind == ext_0_idx)
    00195                 {
    00196                     ind++;
    00197                 }
    00198                 worst_idx = ind;
    00199                 worst_objVec = _pop[ind].objectiveVector();
    00200                 worst_fitness = _pop[ind].fitness();
    00201             }
    00202             else
    00203             {
    00204                 worst_idx = -1;
    00205                 worst_objVec = x_objVec;
    00206                 worst_fitness = x_fitness;
    00207             }
    00211
    00212             // who is the worst ?
    00213             for (unsigned int j=0; j<_pop.size(); j++)
    00214             {
    00215                 if ( (j!=ext_0_idx) && (j!=ext_1_idx) )
    00216                 {
    00217                     if (_pop[j].fitness() < worst_fitness)
    00218                     {
    00219                         worst_idx = j;
    00220                         worst_objVec = _pop[j].objectiveVector();
    00221                         worst_fitness = _pop[j].fitness();
    00222                     }
    00223                 }
    00224             }
    00225             // if the worst solution is the new one
    00226             if (worst_idx == -1)
    00227             {
    00228                 // if all its neighbours have been explored,
    00229                 // let's explore the neighborhoud of the next individual
    00230                 if (! nextMove(move, _pop[i]))
    00231                 {
    00232                     i++;
    00233                     if (i<_pop.size())
    00234                     {
    00235                         // initilization of the move for the next individual
    00236                         moveInit(move, _pop[i]);
    00237                     }
    00238                 }
    00239             }
    00240             // if the worst solution is located before _pop[i]
    00241             else if (worst_idx <= i)
    00242             {
    00243                 // the new solution takes place insteed of _pop[worst_idx]
    00244                 _pop[worst_idx] = _pop[i];
    00245                 move(_pop[worst_idx]);
    00246                 _pop[worst_idx].objectiveVector(x_objVec);
    00247                 _pop[worst_idx].fitness(x_fitness);
    00248                 // let's explore the neighborhoud of the next individual
    00249                 i++;
    00250                 if (i<_pop.size())
    00251                 {
    00252                     // initilization of the move for the next individual
    00253                     moveInit(move, _pop[i]);
    00254                 }
    00255             }
    00256             // if the worst solution is located after _pop[i]
    00257             else if (worst_idx > i)
    00258             {
    00259                 // the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted
    00260                 _pop[worst_idx] = _pop[i+1];
    00261                 _pop[i+1] = _pop[i];
    00262                 move(_pop[i+1]);
    00263                 _pop[i+1].objectiveVector(x_objVec);
    00264                 _pop[i+1].fitness(x_fitness);
    00265                 // let's explore the neighborhoud of the individual _pop[i+2]
    00266                 i += 2;
    00267                 if (i<_pop.size())
    00268                 {
    00269                     // initilization of the move for the next individual
    00270                     moveInit(move, _pop[i]);
    00271                 }
    00272             }
    00273             // update fitness values
    00274             fitnessAssignment.updateByDeleting(_pop, worst_objVec);
    00275         }
    00276     }
    00277
    00278 };
    00279
    00280 #endif /*MOEOIBMOLS_H_*/