Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# eoDominanceMap.h

    00001
    00025 //-----------------------------------------------------------------------------
    00026
    00027 #ifndef eoDominanceMap_h
    00028 #define eoDominanceMap_h
    00029
    00030 #include <eoFunctor.h>
    00031 #include <eoPop.h>
    00032
    00046 template <class EoType>
    00047 class eoDominanceMap : public eoUF<const eoPop<EoType>&, void>, public std::vector<std::vector<bool> >
    00048 {
    00049 public:
    00050
    00052     void clear() {
    00053         std::vector<std::vector<bool> >::clear();
    00054         fitness.clear();
    00055     }
    00056
    00060   void operator()(const eoPop<EoType>& _pop)
    00061   {
    00062     setup(_pop);
    00063     return;
    00064   }
    00065
    00069   void remove(unsigned i)
    00070   {
    00071     for (unsigned j = 0; j < size(); ++j)
    00072     {
    00073       operator[](i)[j] = false; // clear row
    00074       operator[](j)[i] = false; // clear col
    00075     }
    00076   }
    00077
    00081   void setup(const eoPop<EoType>& _pop)
    00082   {
    00083     fitness.resize(_pop.size());
    00084     resize(_pop.size());
    00085
    00086     for (unsigned i = 0; i < _pop.size(); ++i)
    00087     {
    00088       fitness[i] = _pop[i].fitness();
    00089       operator[](i).resize(_pop.size(), false);
    00090
    00091       for (unsigned j = 0; j < i; ++j)
    00092       {
    00093         if (_pop[i].fitness().dominates(_pop[j].fitness()))
    00094         {
    00095           operator[](i)[j] = true;
    00096           operator[](j)[i] = false;
    00097         }
    00098         else if (_pop[j].fitness().dominates(_pop[i].fitness()))
    00099         {
    00100           operator[](i)[j] = false;
    00101           operator[](j)[i] = true;
    00102         }
    00103         else
    00104         {
    00105           operator[](i)[j] = false;
    00106           operator[](j)[i] = false;
    00107         }
    00108       }
    00109     }
    00110   }
    00111
    00118   std::vector<double> sum_dominators() const
    00119   {
    00120     std::vector<double> result(size(), 0.0);
    00121
    00122     for (unsigned i = 0; i < size(); ++i)
    00123     {
    00124       for (unsigned j = 0; j < size(); ++j)
    00125       {
    00126         if (operator[](i)[j]) // i dominates j
    00127           result[j]++;
    00128       }
    00129     }
    00130
    00131     return result;
    00132   }
    00133
    00140   std::vector<double> sum_dominants() const
    00141   {
    00142     std::vector<double> result(size(), 0.0);
    00143
    00144     for (unsigned i = 0; i < size(); ++i)
    00145     {
    00146       for (unsigned j = 0; j < size(); ++j)
    00147       {
    00148         if (operator[](i)[j]) // i dominates j
    00149           result[i]++;
    00150       }
    00151     }
    00152
    00153     return result;
    00154   }
    00155
    00156   private :
    00157
    00158
    00159   std::vector<typename EoType::Fitness> fitness;
    00160 };
    00161
    00162 #endif