moeoArchive.h

00001 /*
00002 * <moeoArchive.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 //-----------------------------------------------------------------------------
00037 
00038 #ifndef MOEOARCHIVE_H_
00039 #define MOEOARCHIVE_H_
00040 
00041 #include <eoPop.h>
00042 #include <comparator/moeoObjectiveVectorComparator.h>
00043 #include <comparator/moeoParetoObjectiveVectorComparator.h>
00044 
00048 template < class MOEOT >
00049 class moeoArchive : public eoPop < MOEOT >
00050   {
00051   public:
00052 
00053     using eoPop < MOEOT > :: size;
00054     using eoPop < MOEOT > :: resize;
00055     using eoPop < MOEOT > :: operator[];
00056     using eoPop < MOEOT > :: back;
00057     using eoPop < MOEOT > :: pop_back;
00058 
00059 
00063     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00064 
00065 
00070     moeoArchive() : eoPop < MOEOT >(), comparator(paretoComparator)
00071     {}
00072 
00073 
00078     moeoArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : eoPop < MOEOT >(), comparator(_comparator)
00079     {}
00080 
00081 
00086     bool dominates (const ObjectiveVector & _objectiveVector) const
00087       {
00088         for (unsigned int i = 0; i<size(); i++)
00089           {
00090             // if _objectiveVector is dominated by the ith individual of the archive...
00091             if ( comparator(_objectiveVector, operator[](i).objectiveVector()) )
00092               {
00093                 return true;
00094               }
00095           }
00096         return false;
00097       }
00098 
00099 
00104     bool contains (const ObjectiveVector & _objectiveVector) const
00105       {
00106         for (unsigned int i = 0; i<size(); i++)
00107           {
00108             if (operator[](i).objectiveVector() == _objectiveVector)
00109               {
00110                 return true;
00111               }
00112           }
00113         return false;
00114       }
00115 
00116 
00121     void update (const MOEOT & _moeo)
00122     {
00123       // first step: removing the dominated solutions from the archive
00124       for (unsigned int j=0; j<size();)
00125         {
00126           // if the jth solution contained in the archive is dominated by _moeo
00127           if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
00128             {
00129               operator[](j) = back();
00130               pop_back();
00131             }
00132           else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
00133             {
00134               operator[](j) = back();
00135               pop_back();
00136             }
00137           else
00138             {
00139               j++;
00140             }
00141         }
00142       // second step: is _moeo dominated?
00143       bool dom = false;
00144       for (unsigned int j=0; j<size(); j++)
00145         {
00146           // if _moeo is dominated by the jth solution contained in the archive
00147           if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
00148             {
00149               dom = true;
00150               break;
00151             }
00152         }
00153       if (!dom)
00154         {
00155           push_back(_moeo);
00156         }
00157     }
00158 
00159 
00164     void update (const eoPop < MOEOT > & _pop)
00165     {
00166       for (unsigned int i=0; i<_pop.size(); i++)
00167         {
00168           update(_pop[i]);
00169         }
00170     }
00171 
00172 
00177     bool equals (const moeoArchive < MOEOT > & _arch)
00178     {
00179       for (unsigned int i=0; i<size(); i++)
00180         {
00181           if (! _arch.contains(operator[](i).objectiveVector()))
00182             {
00183               return false;
00184             }
00185         }
00186       for (unsigned int i=0; i<_arch.size() ; i++)
00187         {
00188           if (! contains(_arch[i].objectiveVector()))
00189             {
00190               return false;
00191             }
00192         }
00193       return true;
00194     }
00195 
00196 
00197   private:
00198 
00200     moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
00202     moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
00203 
00204   };
00205 
00206 #endif /*MOEOARCHIVE_H_ */

Generated on Thu Mar 13 15:54:07 2008 for ParadisEO-MOEO-MultiObjectiveEvolvingObjects by  doxygen 1.4.7