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 <comparator/moeoParetoObjectiveVectorComparator.h>
00017 #include <metric/moeoMetric.h>
00018 
00023 template < class ObjectiveVector >
00024 class moeoContributionMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
00025 {
00026 public:
00027 
00033     double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
00034         unsigned int c  = card_C(_set1, _set2);
00035         unsigned int w1 = card_W(_set1, _set2);
00036         unsigned int n1 = card_N(_set1, _set2);
00037         unsigned int w2 = card_W(_set2, _set1);
00038         unsigned int n2 = card_N(_set2, _set1);
00039         return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2);
00040     }
00041 
00042 
00043 private:
00044 
00046     moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
00047     
00048     
00054     unsigned int card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
00055         unsigned int c=0;
00056         for (unsigned int i=0; i<_set1.size(); i++)
00057             for (unsigned int j=0; j<_set2.size(); j++)
00058                 if (_set1[i] == _set2[j]) {
00059                     c++;
00060                     break;
00061                 }
00062         return c;
00063     }
00064 
00065 
00071     unsigned int card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
00072         unsigned int w=0;
00073         for (unsigned int i=0; i<_set1.size(); i++)
00074             for (unsigned int j=0; j<_set2.size(); j++)
00075                 if (paretoComparator(_set2[j], _set1[i]))
00076                 {
00077                     w++;
00078                     break;
00079                 }
00080         return w;
00081     }
00082 
00083 
00089     unsigned int card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
00090         unsigned int n=0;
00091         for (unsigned int i=0; i<_set1.size(); i++) {
00092             bool domin_rel = false;
00093             for (unsigned int j=0; j<_set2.size(); j++)
00094                 if ( (paretoComparator(_set2[j], _set1[i])) || (paretoComparator(_set1[i], _set2[j])) )
00095                 {
00096                     domin_rel = true;
00097                     break;
00098                 }
00099             if (! domin_rel)
00100                 n++;
00101         }
00102         return n;
00103     }
00104 
00105 };
00106 
00107 #endif /*MOEOCONTRIBUTIONMETRIC_H_*/

Generated on Tue Jun 26 15:13:04 2007 for ParadisEO-MOEO by  doxygen 1.4.7