moeoFrontByFrontSharingDiversityAssignment.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // moeoFrontByFrontSharingDiversityAssignment.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 MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_
00014 #define MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_
00015 
00016 #include <diversity/moeoSharingDiversityAssignment.h>
00017 
00021 template < class MOEOT >
00022 class moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAssignment < MOEOT >
00023 {
00024 public:
00025 
00027     typedef typename MOEOT::ObjectiveVector ObjectiveVector;
00028 
00029 
00036     moeoFrontByFrontSharingDiversityAssignment(moeoDistance<MOEOT,double> & _distance, double _nicheSize = 0.5, double _alpha = 2.0) : moeoSharingDiversityAssignment < MOEOT >(_distance, _nicheSize, _alpha)
00037     {}
00038 
00039 
00045     moeoFrontByFrontSharingDiversityAssignment(double _nicheSize = 0.5, double _alpha = 2.0) : moeoSharingDiversityAssignment < MOEOT >(_nicheSize, _alpha)
00046     {}
00047 
00048 
00056     void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
00057     {
00058         std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
00059     }
00060 
00061 
00062 private:
00063 
00064     using moeoSharingDiversityAssignment < MOEOT >::distance;
00065     using moeoSharingDiversityAssignment < MOEOT >::nicheSize;
00066     using moeoSharingDiversityAssignment < MOEOT >::sh;
00067     using moeoSharingDiversityAssignment < MOEOT >::operator();
00068 
00069 
00074     void setSimilarities(eoPop < MOEOT > & _pop)
00075     {
00076         // compute distances between every individuals
00077         moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
00078         dMatrix(_pop);
00079         // sets the distance to bigger than the niche size for every couple of solutions that do not belong to the same front
00080         for (unsigned int i=0; i<_pop.size(); i++)
00081         {
00082             for (unsigned int j=0; j<i; j++)
00083             {
00084                 if (_pop[i].fitness() != _pop[j].fitness())
00085                 {
00086                     dMatrix[i][j] = nicheSize;
00087                     dMatrix[j][i] = nicheSize;
00088                 }
00089             }
00090         }
00091         // compute similarities
00092         double sum;
00093         for (unsigned int i=0; i<_pop.size(); i++)
00094         {
00095             sum = 0.0;
00096             for (unsigned int j=0; j<_pop.size(); j++)
00097             {
00098                 sum += sh(dMatrix[i][j]);
00099             }
00100             _pop[i].diversity(sum);
00101         }
00102     }
00103 
00104 };
00105 
00106 #endif /*MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_*/

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