- Main Page
- Classes
- Files

- Search for |

# moeoEnvironmentalReplacement.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoEnvironmentalReplacement.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 MOEOENVIRONMENTALREPLACEMENT_H_
    00014 #define MOEOENVIRONMENTALREPLACEMENT_H_
    00015
    00016 #include <moeoReplacement.h>
    00017 #include <moeoComparator.h>
    00018 #include <moeoFitnessAssignment.h>
    00019 #include <moeoDiversityAssignment.h>
    00020
    00025 template < class MOEOT > class moeoEnvironmentalReplacement:public moeoReplacement < MOEOT >
    00026 {
    00027 public:
    00028
    00030     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
    00031
    00032
    00039     moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, moeoComparator < MOEOT > & _comparator) :
    00040             evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator)
    00041     {}
    00042
    00043
    00049     moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity) :
    00050             evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
    00051     {}
    00052
    00053
    00059     moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoComparator < MOEOT > & _comparator) :
    00060             evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (_comparator)
    00061     {}
    00062
    00063
    00069     moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness) :
    00070             evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
    00071     {}
    00072
    00073
    00079     void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
    00080     {
    00081         unsigned sz = _parents.size();
    00082         // merges offspring and parents into a global population
    00083         _parents.reserve (_parents.size() + _offspring.size());
    00084         copy (_offspring.begin(), _offspring.end(), back_inserter(_parents));
    00085         // evaluates the fitness and the diversity of this global population
    00086         evalFitness (_parents);
    00087         evalDiversity (_parents);
    00088         // remove individuals 1 by 1 and update the fitness values
    00089         Cmp cmp(comparator);
    00090         ObjectiveVector worstObjVec;
    00091         while (_parents.size() > sz)
    00092         {
    00093             std::sort (_parents.begin(), _parents.end(), cmp);
    00094             worstObjVec = _parents[_parents.size()-1].objectiveVector();
    00095             _parents.resize(_parents.size()-1);
    00096             evalFitness.updateByDeleting(_parents, worstObjVec);
    00097             evalDiversity.updateByDeleting(_parents, worstObjVec);
    00098         }
    00099         // clear the offspring population
    00100         _offspring.clear ();
    00101     }
    00102
    00103
    00104 protected:
    00105
    00107     moeoFitnessAssignment < MOEOT > & evalFitness;
    00109     moeoDiversityAssignment < MOEOT > & evalDiversity;
    00111     moeoComparator < MOEOT > & comparator;
    00112
    00113
    00117     class Cmp
    00118     {
    00119     public:
    00120
    00125         Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
    00126         {}
    00127
    00128
    00134         bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
    00135         {
    00136             return comparator(_moeo1,_moeo2);
    00137         }
    00138
    00139
    00140     private:
    00141
    00143         moeoComparator < MOEOT > & comparator;
    00144
    00145     };
    00146
    00147 };
    00148
    00149 #endif /*MOEOENVIRONMENTALREPLACEMENT_H_ */