- Main Page
- Classes
- Files

- Search for |

# moeoArchive.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoArchive.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 MOEOARCHIVE_H_
    00014 #define MOEOARCHIVE_H_
    00015
    00016 #include <eoPop.h>
    00017 #include <moeoObjectiveVectorComparator.h>
    00018
    00022 template < class MOEOT >
    00023 class moeoArchive : public eoPop < MOEOT >
    00024 {
    00025 public:
    00026
    00027     using std::vector < MOEOT > :: size;
    00028     using std::vector < MOEOT > :: operator[];
    00029     using std::vector < MOEOT > :: back;
    00030     using std::vector < MOEOT > :: pop_back;
    00031
    00032
    00036     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
    00037
    00038
    00043     moeoArchive() : eoPop < MOEOT >(), comparator(paretoComparator)
    00044     {}
    00045
    00046
    00051     moeoArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : eoPop < MOEOT >(), comparator(_comparator)
    00052     {}
    00053
    00054
    00059     bool dominates (const ObjectiveVector & _objectiveVector) const
    00060     {
    00061         for (unsigned i = 0; i<size(); i++)
    00062         {
    00063             if ( comparator(operator[](i).fitness(), _objectiveVector) )
    00064             {
    00065                 return true;
    00066             }
    00067         }
    00068         return false;
    00069     }
    00070
    00071
    00076     bool contains (const ObjectiveVector & _objectiveVector) const
    00077     {
    00078         for (unsigned i = 0; i<size(); i++)
    00079         {
    00080             if (operator[](i).objectiveVector() == _objectiveVector)
    00081             {
    00082                 return true;
    00083             }
    00084         }
    00085         return false;
    00086     }
    00087
    00088
    00093     void update (const MOEOT & _moeo)
    00094     {
    00095         // first step: removing the dominated solutions from the archive
    00096         for (unsigned j=0; j<size();)
    00097         {
    00098             // if _moeo dominates the jth solution contained in the archive
    00099             if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
    00100             {
    00101                 operator[](j) = back();
    00102                 pop_back();
    00103             }
    00104             else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
    00105             {
    00106                 operator[](j) = back();
    00107                 pop_back();
    00108             }
    00109             else
    00110             {
    00111                 j++;
    00112             }
    00113         }
    00114         // second step: is _moeo dominated?
    00115         bool dom = false;
    00116         for (unsigned j=0; j<size(); j++)
    00117         {
    00118             // if the jth solution contained in the archive dominates _moeo
    00119             if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
    00120             {
    00121                 dom = true;
    00122                 break;
    00123             }
    00124         }
    00125         if (!dom)
    00126         {
    00127             push_back(_moeo);
    00128         }
    00129     }
    00130
    00131
    00136     void update (const eoPop < MOEOT > & _pop)
    00137     {
    00138         for (unsigned i=0; i<_pop.size(); i++)
    00139         {
    00140             update(_pop[i]);
    00141         }
    00142     }
    00143
    00144
    00150     bool equals (const moeoArchive < MOEOT > & _arch)
    00151     {
    00152         for (unsigned i=0; i<size(); i++)
    00153         {
    00154             if (! _arch.contains(operator[](i).objectiveVector()))
    00155             {
    00156                 return false;
    00157             }
    00158         }
    00159         for (unsigned i=0; i<_arch.size() ; i++)
    00160         {
    00161             if (! contains(_arch[i].objectiveVector()))
    00162             {
    00163                 return false;
    00164             }
    00165         }
    00166         return true;
    00167     }
    00168
    00169
    00170 private:
    00171
    00173     moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
    00175     moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
    00176
    00177 };
    00178
    00179 #endif /*MOEOARCHIVE_H_ */