Doxygen documentation for new/modified Paradiseo-moeo classes
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1350 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
ea69e37e9c
commit
a411cc340d
4 changed files with 65 additions and 22 deletions
|
|
@ -112,11 +112,9 @@ template < class MOEOT > class moeoElitistReplacement2:public moeoReplacement <
|
||||||
|
|
||||||
diversityAssignment(_parents);
|
diversityAssignment(_parents);
|
||||||
// sorts the whole population
|
// sorts the whole population
|
||||||
// the delindex contains the ordered index of the population according to the comparator
|
// the delindex contains the ordered index of the population according to the comparator again, we only sort the index of population instead of population
|
||||||
// again, we only sort the index of population instead of population
|
|
||||||
std::vector<unsigned int> delindex;
|
std::vector<unsigned int> delindex;
|
||||||
vectorSortIndex( _parents, delindex, comparator);
|
vectorSortIndex( _parents, delindex, comparator);
|
||||||
//std::sort( delindex.begin(), delindex.end(), comparatorindex(_parents, delindex, comparator));
|
|
||||||
// now, in order to rezise of population we remove the populations whose index
|
// now, in order to rezise of population we remove the populations whose index
|
||||||
// are in the high of delindex
|
// are in the high of delindex
|
||||||
std::sort(delindex.begin()+sz, delindex.end(), std::greater<int>());
|
std::sort(delindex.begin()+sz, delindex.end(), std::greater<int>());
|
||||||
|
|
@ -127,6 +125,15 @@ template < class MOEOT > class moeoElitistReplacement2:public moeoReplacement <
|
||||||
_offspring.clear ();
|
_offspring.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resizes the whole population obtained.
|
||||||
|
* @param _pop the whole population
|
||||||
|
* @param _index points to the population members which will be deleted
|
||||||
|
* @param _sz size of the resulting population
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
void reduce_population ( eoPop < MOEOT > &_pop, std::vector<unsigned int> &index, unsigned int size)
|
void reduce_population ( eoPop < MOEOT > &_pop, std::vector<unsigned int> &index, unsigned int size)
|
||||||
{
|
{
|
||||||
for(int j=size; j< index.size(); j++)
|
for(int j=size; j< index.size(); j++)
|
||||||
|
|
|
||||||
|
|
@ -91,25 +91,27 @@ class moeoFrontByFrontCrowdingDiversityAssignment2 : public moeoCrowdingDiversit
|
||||||
}
|
}
|
||||||
// sort the whole pop according to fitness values
|
// sort the whole pop according to fitness values
|
||||||
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
|
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
|
||||||
std::vector<const MOEOT *> sortedpop;
|
std::vector<const MOEOT *> sortedptrpop;
|
||||||
sortedpop.resize(_pop.size());
|
sortedptrpop.resize(_pop.size());
|
||||||
std::transform( _pop.begin(), _pop.end(), sortedpop.begin(), typename eoPop<MOEOT>::Ref());
|
// due to intensive sort operations for this diversity assignment,
|
||||||
//struct eoPop<MOEOT>::Ref ref;
|
// it is more efficient to perform sorts using only pointers to the
|
||||||
moeoPtrComparator<MOEOT> cmp1( fitnessComparator);
|
// population members in order to avoid copy of individuals
|
||||||
std::sort(sortedpop.begin(), sortedpop.end(), cmp1);
|
std::transform( _pop.begin(), _pop.end(), sortedptrpop.begin(), typename eoPop<MOEOT>::Ref());
|
||||||
//std::sort(_pop.begin(), _pop.end(), fitnessComparator);
|
//sort the pointers to population members
|
||||||
|
moeoPtrComparator<MOEOT> cmp2( fitnessComparator);
|
||||||
|
std::sort(sortedptrpop.begin(), sortedptrpop.end(), cmp2);
|
||||||
// compute the crowding distance values for every individual "front" by "front" (front : from a to b)
|
// compute the crowding distance values for every individual "front" by "front" (front : from a to b)
|
||||||
a = 0; // the front starts at a
|
a = 0; // the front starts at a
|
||||||
while (a < _pop.size())
|
while (a < _pop.size())
|
||||||
{
|
{
|
||||||
b = lastIndex(sortedpop,a); // the front ends at b
|
b = lastIndex(sortedptrpop,a); // the front ends at b
|
||||||
//b = lastIndex(_pop,a); // the front ends at b
|
//b = lastIndex(_pop,a); // the front ends at b
|
||||||
// if there is less than 2 individuals in the front...
|
// if there is less than 2 individuals in the front...
|
||||||
if ((b-a) < 2)
|
if ((b-a) < 2)
|
||||||
{
|
{
|
||||||
for (unsigned int i=a; i<=b; i++)
|
for (unsigned int i=a; i<=b; i++)
|
||||||
{
|
{
|
||||||
((MOEOT *)sortedpop[i])->diversity(inf());
|
((MOEOT *)sortedptrpop[i])->diversity(inf());
|
||||||
//_pop[i].diversity(inf());
|
//_pop[i].diversity(inf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -122,10 +124,10 @@ class moeoFrontByFrontCrowdingDiversityAssignment2 : public moeoCrowdingDiversit
|
||||||
// sort in the descending order using the values of the objective 'obj'
|
// sort in the descending order using the values of the objective 'obj'
|
||||||
moeoOneObjectiveComparator < MOEOT > objComp(obj);
|
moeoOneObjectiveComparator < MOEOT > objComp(obj);
|
||||||
moeoPtrComparator<MOEOT> cmp2( objComp );
|
moeoPtrComparator<MOEOT> cmp2( objComp );
|
||||||
std::sort(sortedpop.begin(), sortedpop.end(), cmp2);
|
std::sort(sortedptrpop.begin(), sortedptrpop.end(), cmp2);
|
||||||
// min & max
|
// min & max
|
||||||
min = (sortedpop[b])->objectiveVector()[obj];
|
min = (sortedptrpop[b])->objectiveVector()[obj];
|
||||||
max = (sortedpop[a])->objectiveVector()[obj];
|
max = (sortedptrpop[a])->objectiveVector()[obj];
|
||||||
|
|
||||||
// avoid extreme case
|
// avoid extreme case
|
||||||
if (min == max)
|
if (min == max)
|
||||||
|
|
@ -134,13 +136,13 @@ class moeoFrontByFrontCrowdingDiversityAssignment2 : public moeoCrowdingDiversit
|
||||||
max += tiny();
|
max += tiny();
|
||||||
}
|
}
|
||||||
// set the diversity value to infiny for min and max
|
// set the diversity value to infiny for min and max
|
||||||
((MOEOT *)sortedpop[a])->diversity(inf());
|
((MOEOT *)sortedptrpop[a])->diversity(inf());
|
||||||
((MOEOT *)sortedpop[b])->diversity(inf());
|
((MOEOT *)sortedptrpop[b])->diversity(inf());
|
||||||
// set the diversity values for the other individuals
|
// set the diversity values for the other individuals
|
||||||
for (unsigned int i=a+1; i<b; i++)
|
for (unsigned int i=a+1; i<b; i++)
|
||||||
{
|
{
|
||||||
distance = ( (sortedpop[i-1])->objectiveVector()[obj] - (sortedpop[i+1])->objectiveVector()[obj]) / (max-min);
|
distance = ( (sortedptrpop[i-1])->objectiveVector()[obj] - (sortedptrpop[i+1])->objectiveVector()[obj]) / (max-min);
|
||||||
((MOEOT *)sortedpop[i])->diversity(sortedpop[i]->diversity() + distance);
|
((MOEOT *)sortedptrpop[i])->diversity(sortedptrpop[i]->diversity() + distance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +155,7 @@ class moeoFrontByFrontCrowdingDiversityAssignment2 : public moeoCrowdingDiversit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index of the last individual having the same fitness value than _pop[_start]
|
* Returns the index of the last individual having the same fitness value than _pop[_start]
|
||||||
* @param _pop the population
|
* @param _pop the vector of pointers to population individuals
|
||||||
* @param _start the index to start from
|
* @param _start the index to start from
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@
|
||||||
|
|
||||||
#include <utils/eoStat.h>
|
#include <utils/eoStat.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
This base class is a specialization of eoStat which is useful
|
||||||
|
to compute statistics for each objective function
|
||||||
|
*/
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER < 1300)
|
#if defined(_MSC_VER) && (_MSC_VER < 1300)
|
||||||
template <class MOEOT>
|
template <class MOEOT>
|
||||||
class moeoObjVecStat : public eoStat<MOEOT, MOEOT::ObjectiveVector>
|
class moeoObjVecStat : public eoStat<MOEOT, MOEOT::ObjectiveVector>
|
||||||
|
|
@ -46,6 +51,9 @@ class moeoObjVecStat : public eoStat<MOEOT, typename MOEOT::ObjectiveVector>
|
||||||
virtual void doit(const eoPop<MOEOT> &_pop) = 0;
|
virtual void doit(const eoPop<MOEOT> &_pop) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Calculate the best solution for each objective (extreme points
|
||||||
|
*/
|
||||||
|
|
||||||
template <class MOEOT>
|
template <class MOEOT>
|
||||||
class moeoBestObjVecStat : public moeoObjVecStat<MOEOT>
|
class moeoBestObjVecStat : public moeoObjVecStat<MOEOT>
|
||||||
{
|
{
|
||||||
|
|
@ -62,10 +70,20 @@ public:
|
||||||
|
|
||||||
virtual std::string className(void) const { return "moeoBestObjVecStat"; }
|
virtual std::string className(void) const { return "moeoBestObjVecStat"; }
|
||||||
|
|
||||||
const MOEOT & bestindividuals(unsigned int objective) { return *(best_individuals[objective]); }
|
/**
|
||||||
|
Return the best solutions for an given objective function
|
||||||
|
* @param which the objective function number
|
||||||
|
*/
|
||||||
|
const MOEOT & bestindividuals(unsigned int which) {
|
||||||
|
typedef typename moeoObjVecStat<MOEOT>::Traits traits;
|
||||||
|
if(which > traits::nObjectives() ) throw std::logic_error("which is larger than the number of objectives");
|
||||||
|
return *(best_individuals[which]);
|
||||||
|
}
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
|
/** Vector of iterators pointing to best individuals for each objective function */
|
||||||
|
|
||||||
std::vector<typename eoPop<MOEOT>::const_iterator> best_individuals;
|
std::vector<typename eoPop<MOEOT>::const_iterator> best_individuals;
|
||||||
|
|
||||||
struct CmpObjVec
|
struct CmpObjVec
|
||||||
|
|
@ -101,6 +119,10 @@ private :
|
||||||
// default
|
// default
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Calculates average scores for each objective
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
template <class MOEOT> class moeoAverageObjVecStat : public moeoObjVecStat<MOEOT>
|
template <class MOEOT> class moeoAverageObjVecStat : public moeoObjVecStat<MOEOT>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,23 @@ template < class MOEOT >
|
||||||
class moeoPtrComparator : public eoBF < const MOEOT *, const MOEOT *, const bool >
|
class moeoPtrComparator : public eoBF < const MOEOT *, const MOEOT *, const bool >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor with a comparator
|
||||||
|
* @param _cmp comparator to be employed
|
||||||
|
|
||||||
|
*/
|
||||||
moeoPtrComparator( moeoComparator<MOEOT> & _cmp) : cmp(_cmp) {}
|
moeoPtrComparator( moeoComparator<MOEOT> & _cmp) : cmp(_cmp) {}
|
||||||
const bool operator() (const MOEOT *ptr1, const MOEOT *ptr2)
|
const bool operator() (const MOEOT *ptr1, const MOEOT *ptr2)
|
||||||
{
|
{
|
||||||
return cmp(*ptr1, *ptr2);
|
return cmp(*ptr1, *ptr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool operator() (MOEOT *ptr1, MOEOT *ptr2)
|
||||||
|
{
|
||||||
|
return cmp(*ptr1, *ptr2);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
moeoComparator<MOEOT> &cmp;
|
moeoComparator<MOEOT> &cmp;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue