moeoContributionMetric.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoContributionMetric.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 MOEOCONTRIBUTIONMETRIC_H_
00014 #define MOEOCONTRIBUTIONMETRIC_H_
00015 
00016 #include <metric/moeoMetric.h>
00017 
00022 template < class ObjectiveVector >
00023 class moeoContributionMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
00024 {
00025 public:
00026 
00032     double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
00033         unsigned c  = card_C(_set1, _set2);
00034         unsigned w1 = card_W(_set1, _set2);
00035         unsigned n1 = card_N(_set1, _set2);
00036         unsigned w2 = card_W(_set2, _set1);
00037         unsigned n2 = card_N(_set2, _set1);
00038         return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2);
00039     }
00040 
00041 
00042 private:
00043 
00049     unsigned card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
00050         unsigned c=0;
00051         for (unsigned i=0; i<_set1.size(); i++)
00052             for (unsigned j=0; j<_set2.size(); j++)
00053                 if (_set1[i] == _set2[j]) {
00054                     c++;
00055                     break;
00056                 }
00057         return c;
00058     }
00059 
00065     unsigned card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
00066         unsigned w=0;
00067         for (unsigned i=0; i<_set1.size(); i++)
00068             for (unsigned j=0; j<_set2.size(); j++)
00069                 if (_set1[i].dominates(_set2[j])) {
00070                     w++;
00071                     break;
00072                 }
00073         return w;
00074     }
00075 
00081     unsigned card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
00082         unsigned n=0;
00083         for (unsigned i=0; i<_set1.size(); i++) {
00084             bool domin_rel = false;
00085             for (unsigned j=0; j<_set2.size(); j++)
00086                 if (_set1[i].dominates(_set2[j]) || _set2[j].dominates(_set1 [i])) {
00087                     domin_rel = true;
00088                     break;
00089                 }
00090             if (! domin_rel)
00091                 n++;
00092         }
00093         return n;
00094     }
00095 
00096 };
00097 
00098 #endif /*MOEOCONTRIBUTIONMETRIC_H_*/

Generated on Tue Apr 17 16:53:20 2007 for ParadisEO-MOEO by  doxygen 1.5.1