- Main Page
- Classes
- Files
- Related Pages

- 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), 2006
    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
    00021 template < class EOT > class moeoArchive:public eoPop < EOT >
    00022 {
    00023 public:
    00024
    00025   using std::vector < EOT >::size;
    00026   using std::vector < EOT >::operator[];
    00027   using std::vector < EOT >::back;
    00028   using std::vector < EOT >::pop_back;
    00029
    00033   typedef typename EOT::Fitness EOFitness;
    00034
    00039   bool dominates (const EOFitness & _fit) const
    00040   {
    00041     for (unsigned i = 0; i < size; i++)
    00042       if (operator[](i).fitness ().dominates (_fit))
    00043         return true;
    00044     return false;
    00045   }
    00046
    00051   bool contains (const EOFitness & _fit) const
    00052   {
    00053     for (unsigned i = 0; i < size; i++)
    00054       if (operator[](i).fitness () == _fit)
    00055         return true;
    00056     return false;
    00057   }
    00058
    00063   void update (const EOT & _eo)
    00064   {
    00065     // Removing the dominated solutions from the archive
    00066     for (unsigned j = 0; j < size ();)
    00067       {
    00068         if (_eo.fitness ().dominates (operator[](j).fitness ()))
    00069           {
    00070             operator[](j) = back ();
    00071             pop_back ();
    00072           }
    00073         else if (_eo.fitness () == operator[](j).fitness ())
    00074           {
    00075             operator[](j) = back ();
    00076             pop_back ();
    00077           }
    00078         else
    00079           j++;
    00080       }
    00081
    00082     // Dominated ?
    00083     bool dom = false;
    00084     for (unsigned j = 0; j < size (); j++)
    00085       if (operator [](j).fitness ().dominates (_eo.fitness ()))
    00086         {
    00087           dom = true;
    00088           break;
    00089         }
    00090     if (!dom)
    00091       push_back (_eo);
    00092   }
    00093
    00098   void update (const eoPop < EOT > &_pop)
    00099   {
    00100     for (unsigned i = 0; i < _pop.size (); i++)
    00101       update (_pop[i]);
    00102   }
    00103
    00104 };
    00105
    00106 #endif /*MOEOARCHIVE_H_ */