Removed function template specializations for eoScalarFitnessAssembled from classes in this file, since they do not work under Visual Studio! Reimplemented these stat classes for this new fitness class in eoAssembledFitnessStat.h
This commit is contained in:
parent
a172d34e5f
commit
45e3b86bcb
1 changed files with 14 additions and 76 deletions
|
|
@ -32,7 +32,6 @@
|
|||
#include <eoFunctor.h>
|
||||
#include <utils/eoParam.h>
|
||||
#include <eoPop.h>
|
||||
#include <eoScalarFitnessAssembled.h>
|
||||
#include <eoParetoFitness.h>
|
||||
|
||||
/**
|
||||
|
|
@ -87,10 +86,10 @@ public :
|
|||
Average fitness of a population. Fitness can be:
|
||||
- double
|
||||
- eoMinimizingFitness or eoMaximizingFitness
|
||||
- eoScalarFitnessAssembled:
|
||||
Specify in the constructor, for which fitness term (index) the average should be evaluated.
|
||||
- eoParetoFitness:
|
||||
The average of each objective is evaluated.
|
||||
|
||||
( For eoScalarFitnessAssembled user eoAssembledFitnessStat classes.)
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
template <class EOT> class eoAverageStat : public eoStat<EOT, EOT::Fitness>
|
||||
|
|
@ -99,35 +98,22 @@ template <class EOT> class eoAverageStat : public eoStat<EOT, typename EOT::Fitn
|
|||
#endif
|
||||
{
|
||||
public :
|
||||
typedef typename EOT::Fitness fitness_type;
|
||||
#ifdef _MSC_VER
|
||||
eoAverageStat(std::string _description = "Average Fitness")
|
||||
: eoStat<EOT, EOT::Fitness>(fitness_type(), _description), whichFitnessTerm() {}
|
||||
eoAverageStat(unsigned _whichTerm, std::string _description = "Average Fitness")
|
||||
: eoStat<EOT, EOT::Fitness>(fitness_type(), _description), whichFitnessTerm(_whichTerm) {}
|
||||
#else
|
||||
eoAverageStat(std::string _description = "Average Fitness")
|
||||
: eoStat<EOT, typename EOT::Fitness>(fitness_type(), _description), whichFitnessTerm() {}
|
||||
eoAverageStat(unsigned _whichTerm, std::string _description = "Average Fitness")
|
||||
: eoStat<EOT, typename EOT::Fitness>(fitness_type(), _description), whichFitnessTerm(_whichTerm) {}
|
||||
#endif
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
static fitness_type sumFitness(double _sum, const EOT& _eot)
|
||||
{
|
||||
eoAverageStat(std::string _description = "Average Fitness")
|
||||
: eoStat<EOT, Fitness>(Fitness(), _description) {}
|
||||
|
||||
static Fitness sumFitness(double _sum, const EOT& _eot){
|
||||
_sum += _eot.fitness();
|
||||
return _sum;
|
||||
}
|
||||
|
||||
eoAverageStat(double _value, std::string _desc) : eoStat<EOT, double>(_value, _desc) {}
|
||||
|
||||
virtual void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
doit(_pop, EOT::Fitness()); // specializations for scalar and std::vector
|
||||
#else
|
||||
doit(_pop, typename EOT::Fitness()); // specializations for scalar and std::vector
|
||||
#endif
|
||||
virtual void operator()(const eoPop<EOT>& _pop){
|
||||
doit(_pop, Fitness()); // specializations for scalar and std::vector
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
// Specialization for pareto fitness
|
||||
|
|
@ -147,33 +133,16 @@ private :
|
|||
value()[o] /= _pop.size();
|
||||
}
|
||||
}
|
||||
|
||||
// Specialization for eoScalarFitnessAssembled
|
||||
template <class ScalarType, class Compare, class FitnessTraits>
|
||||
void doit(const eoPop<EOT>& _pop, eoScalarFitnessAssembled<ScalarType, Compare>)
|
||||
{
|
||||
|
||||
if ( whichFitnessTerm >= _pop[0].fitness().size() )
|
||||
throw std::logic_error("Fitness term requested out of range");
|
||||
|
||||
double result =0.0;
|
||||
for (typename eoPop<EOT>::const_iterator it = _pop.begin(); it != _pop.end(); ++it)
|
||||
result+= it->fitness()[whichFitnessTerm];
|
||||
value().clear();
|
||||
value() = result / _pop.size();
|
||||
}
|
||||
|
||||
|
||||
// Default behavior
|
||||
template <class T>
|
||||
void doit(const eoPop<EOT>& _pop, T)
|
||||
{
|
||||
fitness_type v = std::accumulate(_pop.begin(), _pop.end(), fitness_type(0.0), eoAverageStat::sumFitness);
|
||||
Fitness v = std::accumulate(_pop.begin(), _pop.end(), Fitness(0.0), eoAverageStat::sumFitness);
|
||||
|
||||
value() = v / _pop.size();
|
||||
}
|
||||
|
||||
// Store an index of the fitness term to be evaluated in eoScalarFitnessAssembled
|
||||
unsigned whichFitnessTerm;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -223,8 +192,6 @@ public :
|
|||
|
||||
eoNthElementFitnessStat(unsigned _whichElement, std::string _description = "nth element fitness")
|
||||
: eoSortedStat<EOT, Fitness>(Fitness(), _description), whichElement(_whichElement) {}
|
||||
eoNthElementFitnessStat(unsigned _whichElement, unsigned _whichTerm, std::string _description = "nth element fitness")
|
||||
: eoSortedStat<EOT, Fitness>(Fitness(), _description), whichElement(_whichElement), whichFitnessTerm(_whichTerm) {}
|
||||
|
||||
virtual void operator()(const std::vector<const EOT*>& _pop)
|
||||
{
|
||||
|
|
@ -271,16 +238,6 @@ private :
|
|||
}
|
||||
}
|
||||
|
||||
// Specialization for eoScalarFitnessAssembled
|
||||
template <class ScalarType, class Compare>
|
||||
void doit(const eoPop<EOT>& _pop, eoScalarFitnessAssembled<ScalarType, Compare>)
|
||||
{
|
||||
if ( whichFitnessTerm >= _pop[0].fitness().size() )
|
||||
throw std::logic_error("Fitness term requested out of range");
|
||||
value().clear();
|
||||
value() = _pop[whichElement]->fitness()[whichFitnessTerm];
|
||||
}
|
||||
|
||||
// for everything else
|
||||
template <class T>
|
||||
void doit(const std::vector<const EOT*>& _pop, T)
|
||||
|
|
@ -289,7 +246,6 @@ private :
|
|||
}
|
||||
|
||||
unsigned whichElement;
|
||||
unsigned whichFitnessTerm;
|
||||
};
|
||||
|
||||
/* Actually, you shouldn't need to sort the population to get the best fitness
|
||||
|
|
@ -320,10 +276,9 @@ public :
|
|||
Best fitness of a population. Fitness can be:
|
||||
- double
|
||||
- eoMinimizingFitness or eoMaximizingFitness
|
||||
- eoScalarFitnessAssembled:
|
||||
Best individual is found according to its fitness,
|
||||
specify in the constructor which fitness term of this individual should then be stored.
|
||||
- eoParetoFitness:
|
||||
|
||||
( For eoScalarFitnessAssembled look at eoAssembledFitnessStat )
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
|
@ -339,15 +294,9 @@ public :
|
|||
|
||||
eoBestFitnessStat(std::string _description = "Best ")
|
||||
: eoStat<EOT, Fitness>(Fitness(), _description) {}
|
||||
eoBestFitnessStat(unsigned _whichTerm, std::string _description = "Best ")
|
||||
: eoStat<EOT, Fitness>(Fitness(), _description), whichFitnessTerm(_whichTerm) {}
|
||||
|
||||
void operator()(const eoPop<EOT>& _pop){
|
||||
#ifdef _MSC_VER
|
||||
doit(_pop, EOT::Fitness() ); // specializations for scalar and std::vector
|
||||
#else
|
||||
doit(_pop, typename EOT::Fitness()); // specializations for scalar and std::vector
|
||||
#endif
|
||||
doit(_pop, Fitness() ); // specializations for scalar and std::vector
|
||||
}
|
||||
|
||||
private :
|
||||
|
|
@ -382,16 +331,6 @@ private :
|
|||
}
|
||||
}
|
||||
|
||||
// Specialization for eoScalarFitnessAssembled
|
||||
template <class ScalarType, class Compare, class FitnessTraits>
|
||||
void doit(const eoPop<EOT>& _pop, eoScalarFitnessAssembled<ScalarType, Compare>){
|
||||
|
||||
if ( whichFitnessTerm >= _pop[0].fitness().size() )
|
||||
throw std::logic_error("Fitness term requested out of range");
|
||||
value().clear();
|
||||
value() = _pop.best_element().fitness()[whichFitnessTerm];
|
||||
}
|
||||
|
||||
// default
|
||||
template<class T>
|
||||
void doit(const eoPop<EOT>& _pop, T)
|
||||
|
|
@ -399,7 +338,6 @@ private :
|
|||
value() = _pop.best_element().fitness();
|
||||
}
|
||||
|
||||
unsigned whichFitnessTerm;
|
||||
};
|
||||
|
||||
template <class EOT>
|
||||
|
|
|
|||
Reference in a new issue