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 <comparator/moeoObjectiveVectorComparator.h>
00018 #include <comparator/moeoParetoObjectiveVectorComparator.h>
00019 
00023 template < class MOEOT >
00024 class moeoArchive : public eoPop < MOEOT >
00025 {
00026 public:
00027 
00028     using eoPop < MOEOT > :: size;
00029     using eoPop < MOEOT > :: operator[];
00030     using eoPop < MOEOT > :: back;
00031     using eoPop < MOEOT > :: pop_back;
00032 
00033 
00037     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00038 
00039 
00044     moeoArchive() : eoPop < MOEOT >(), comparator(paretoComparator)
00045     {}
00046 
00047 
00052     moeoArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : eoPop < MOEOT >(), comparator(_comparator)
00053     {}
00054 
00055 
00060     bool dominates (const ObjectiveVector & _objectiveVector) const
00061     {
00062         for (unsigned int i = 0; i<size(); i++)
00063         {
00064             // if _objectiveVector is dominated by the ith individual of the archive...
00065             if ( comparator(_objectiveVector, operator[](i).objectiveVector()) )
00066             {
00067                 return true;
00068             }
00069         }
00070         return false;
00071     }
00072 
00073 
00078     bool contains (const ObjectiveVector & _objectiveVector) const
00079     {
00080         for (unsigned int i = 0; i<size(); i++)
00081         {
00082             if (operator[](i).objectiveVector() == _objectiveVector)
00083             {
00084                 return true;
00085             }
00086         }
00087         return false;
00088     }
00089 
00090 
00095     void update (const MOEOT & _moeo)
00096     {
00097         // first step: removing the dominated solutions from the archive
00098         for (unsigned int j=0; j<size();)
00099         {
00100             // if the jth solution contained in the archive is dominated by _moeo
00101             if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
00102             {
00103                 operator[](j) = back();
00104                 pop_back();
00105             }
00106             else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
00107             {
00108                 operator[](j) = back();
00109                 pop_back();
00110             }
00111             else
00112             {
00113                 j++;
00114             }
00115         }
00116         // second step: is _moeo dominated?
00117         bool dom = false;
00118         for (unsigned int j=0; j<size(); j++)
00119         {
00120             // if _moeo is dominated by the jth solution contained in the archive
00121             if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
00122             {
00123                 dom = true;
00124                 break;
00125             }
00126         }
00127         if (!dom)
00128         {
00129             push_back(_moeo);
00130         }
00131     }
00132 
00133 
00138     void update (const eoPop < MOEOT > & _pop)
00139     {
00140         for (unsigned int i=0; i<_pop.size(); i++)
00141         {
00142             update(_pop[i]);
00143         }
00144     }
00145 
00146 
00151     bool equals (const moeoArchive < MOEOT > & _arch)
00152     {
00153         for (unsigned int i=0; i<size(); i++)
00154         {
00155             if (! _arch.contains(operator[](i).objectiveVector()))
00156             {
00157                 return false;
00158             }
00159         }
00160         for (unsigned int i=0; i<_arch.size() ; i++)
00161         {
00162             if (! contains(_arch[i].objectiveVector()))
00163             {
00164                 return false;
00165             }
00166         }
00167         return true;
00168     }
00169 
00170 
00171 private:
00172 
00174     moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
00176     moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
00177 
00178 };
00179 
00180 #endif /*MOEOARCHIVE_H_ */

Generated on Mon Oct 8 10:35:51 2007 for ParadisEO-MOEOMovingObjects by  doxygen 1.4.7