- Main Page
- Classes
- Files

- Search for |

# moeoElitistReplacement.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoElitistReplacement.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 MOEOELITISTREPLACEMENT_H_
    00014 #define MOEOELITISTREPLACEMENT_H_
    00015
    00016 #include <comparator/moeoComparator.h>
    00017 #include <comparator/moeoFitnessThenDiversityComparator.h>
    00018 #include <diversity/moeoDiversityAssignment.h>
    00019 #include <diversity/moeoDummyDiversityAssignment.h>
    00020 #include <fitness/moeoFitnessAssignment.h>
    00021 #include <replacement/moeoReplacement.h>
    00022
    00026 template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT >
    00027 {
    00028 public:
    00029
    00036     moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) :
    00037             fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator)
    00038     {}
    00039
    00040
    00046     moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) :
    00047             fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator)
    00048     {}
    00049
    00050
    00056     moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) :
    00057             fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator)
    00058     {}
    00059
    00060
    00066     moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) :
    00067             fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator)
    00068     {}
    00069
    00070
    00076     void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
    00077     {
    00078         unsigned int sz = _parents.size ();
    00079         // merges offspring and parents into a global population
    00080         _parents.reserve (_parents.size () + _offspring.size ());
    00081         std::copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
    00082         // evaluates the fitness and the diversity of this global population
    00083         fitnessAssignment (_parents);
    00084         diversityAssignment (_parents);
    00085         // sorts the whole population according to the comparator
    00086         std::sort(_parents.begin(), _parents.end(), comparator);
    00087         // finally, resize this global population
    00088         _parents.resize (sz);
    00089         // and clear the offspring population
    00090         _offspring.clear ();
    00091     }
    00092
    00093
    00094 protected:
    00095
    00097     moeoFitnessAssignment < MOEOT > & fitnessAssignment;
    00099     moeoDiversityAssignment < MOEOT > & diversityAssignment;
    00101     moeoDummyDiversityAssignment < MOEOT > defaultDiversity;
    00103     moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
    00105     class Cmp
    00106     {
    00107     public:
    00112         Cmp(moeoComparator < MOEOT > & _comp) : comp(_comp)
    00113         {}
    00119         bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
    00120         {
    00121             return comp(_moeo2,_moeo1);
    00122         }
    00123     private:
    00125         moeoComparator < MOEOT > & comp;
    00126     } comparator;
    00127
    00128 };
    00129
    00130 #endif /*MOEOELITISTREPLACEMENT_H_ */