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 * Sebastien Cahon, 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 > :: operator[];
00055     using eoPop < MOEOT > :: back;
00056     using eoPop < MOEOT > :: pop_back;
00057 
00058 
00062     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00063 
00064 
00069     moeoArchive() : eoPop < MOEOT >(), comparator(paretoComparator)
00070     {}
00071 
00072 
00077     moeoArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : eoPop < MOEOT >(), comparator(_comparator)
00078     {}
00079 
00080 
00085     bool dominates (const ObjectiveVector & _objectiveVector) const
00086     {
00087         for (unsigned int i = 0; i<size(); i++)
00088         {
00089             // if _objectiveVector is dominated by the ith individual of the archive...
00090             if ( comparator(_objectiveVector, operator[](i).objectiveVector()) )
00091             {
00092                 return true;
00093             }
00094         }
00095         return false;
00096     }
00097 
00098 
00103     bool contains (const ObjectiveVector & _objectiveVector) const
00104     {
00105         for (unsigned int i = 0; i<size(); i++)
00106         {
00107             if (operator[](i).objectiveVector() == _objectiveVector)
00108             {
00109                 return true;
00110             }
00111         }
00112         return false;
00113     }
00114 
00115 
00120     void update (const MOEOT & _moeo)
00121     {
00122         // first step: removing the dominated solutions from the archive
00123         for (unsigned int j=0; j<size();)
00124         {
00125             // if the jth solution contained in the archive is dominated by _moeo
00126             if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
00127             {
00128                 operator[](j) = back();
00129                 pop_back();
00130             }
00131             else if (_moeo.objectiveVector() == operator[](j).objectiveVector())
00132             {
00133                 operator[](j) = back();
00134                 pop_back();
00135             }
00136             else
00137             {
00138                 j++;
00139             }
00140         }
00141         // second step: is _moeo dominated?
00142         bool dom = false;
00143         for (unsigned int j=0; j<size(); j++)
00144         {
00145             // if _moeo is dominated by the jth solution contained in the archive
00146             if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
00147             {
00148                 dom = true;
00149                 break;
00150             }
00151         }
00152         if (!dom)
00153         {
00154             push_back(_moeo);
00155         }
00156     }
00157 
00158 
00163     void update (const eoPop < MOEOT > & _pop)
00164     {
00165         for (unsigned int i=0; i<_pop.size(); i++)
00166         {
00167             update(_pop[i]);
00168         }
00169     }
00170 
00171 
00176     bool equals (const moeoArchive < MOEOT > & _arch)
00177     {
00178         for (unsigned int i=0; i<size(); i++)
00179         {
00180             if (! _arch.contains(operator[](i).objectiveVector()))
00181             {
00182                 return false;
00183             }
00184         }
00185         for (unsigned int i=0; i<_arch.size() ; i++)
00186         {
00187             if (! contains(_arch[i].objectiveVector()))
00188             {
00189                 return false;
00190             }
00191         }
00192         return true;
00193     }
00194 
00195 
00196 private:
00197 
00199     moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
00201     moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
00202 
00203 };
00204 
00205 #endif /*MOEOARCHIVE_H_ */

Generated on Fri Oct 12 15:16:04 2007 for ParadisEO-MOEO:MultiObjectiveEvolvingObjects by  doxygen 1.4.7