Add the DUAL fitness assignment class
Change a bit the machinery of moeoExpBinaryIndicatorBasedFitnessAssignment to allow subclassing.
This commit is contained in:
parent
319c286685
commit
ce02ca0e90
3 changed files with 76 additions and 6 deletions
|
|
@ -0,0 +1,67 @@
|
||||||
|
|
||||||
|
#include <fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h>
|
||||||
|
|
||||||
|
template<class MOEOT>
|
||||||
|
class moeoExpBinaryIndicatorBasedDualFitnessAssignment : public moeoExpBinaryIndicatorBasedFitnessAssignment<MOEOT>
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
eoPop<MOEOT> _feasible_pop;
|
||||||
|
eoPop<MOEOT> _unfeasible_pop;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||||
|
|
||||||
|
moeoExpBinaryIndicatorBasedDualFitnessAssignment(
|
||||||
|
moeoNormalizedSolutionVsSolutionBinaryMetric<ObjectiveVector,double> & metric,
|
||||||
|
const double kappa = 0.05
|
||||||
|
) : moeoExpBinaryIndicatorBasedFitnessAssignment<MOEOT>( metric, kappa ) {}
|
||||||
|
|
||||||
|
//! Split up the population in two: in one pop the feasible individual, in the other the feasible ones
|
||||||
|
virtual void split( eoPop<MOEOT> & pop )
|
||||||
|
{
|
||||||
|
_feasible_pop.reserve(pop.size());
|
||||||
|
_unfeasible_pop.reserve(pop.size());
|
||||||
|
|
||||||
|
for( typename eoPop<MOEOT>::iterator it=pop.begin(), end=pop.end(); it != end; ++it ) {
|
||||||
|
// The ObjectiveVector should implement "is_feasible"
|
||||||
|
if( it->objectiveVector().is_feasible() ) {
|
||||||
|
_feasible_pop.push_back( *it );
|
||||||
|
} else {
|
||||||
|
_unfeasible_pop.push_back( *it );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! If the population is homogeneous (only composed of feasible individuals or unfeasible ones),
|
||||||
|
* then apply the operators on the whole population.
|
||||||
|
* But, if there is at least one feasible individual, then apply them only on the feasible individuals.
|
||||||
|
*/
|
||||||
|
virtual void operator()(eoPop < MOEOT > & pop)
|
||||||
|
{
|
||||||
|
// separate the pop in the members
|
||||||
|
split( pop );
|
||||||
|
|
||||||
|
eoPop<MOEOT>* ppop;
|
||||||
|
// if there is at least one feasible individual, it will supersede all the unfeasible ones
|
||||||
|
if( _feasible_pop.size() == 0 ) {
|
||||||
|
ppop = & _unfeasible_pop;
|
||||||
|
} else {
|
||||||
|
ppop = & _feasible_pop;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->setup(*ppop);
|
||||||
|
this->computeValues(*ppop);
|
||||||
|
this->setFitnesses(*ppop);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void setFitnesses(eoPop < MOEOT > & pop)
|
||||||
|
{
|
||||||
|
for (unsigned int i=0; i<pop.size(); i++) {
|
||||||
|
// We should maintain the feasibility of the fitness across computations
|
||||||
|
pop[i].fitness( this->computeFitness(i), pop[i].is_feasible() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -58,6 +58,7 @@ class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorB
|
||||||
/** The type of objective vector */
|
/** The type of objective vector */
|
||||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||||
|
|
||||||
|
typedef typename ObjectiveVector::Type Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor.
|
* Ctor.
|
||||||
|
|
@ -72,7 +73,7 @@ class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorB
|
||||||
* Sets the fitness values for every solution contained in the population _pop
|
* Sets the fitness values for every solution contained in the population _pop
|
||||||
* @param _pop the population
|
* @param _pop the population
|
||||||
*/
|
*/
|
||||||
void operator()(eoPop < MOEOT > & _pop)
|
virtual void operator()(eoPop < MOEOT > & _pop)
|
||||||
{
|
{
|
||||||
// 1 - setting of the bounds
|
// 1 - setting of the bounds
|
||||||
setup(_pop);
|
setup(_pop);
|
||||||
|
|
@ -145,7 +146,7 @@ class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorB
|
||||||
/** the scaling factor */
|
/** the scaling factor */
|
||||||
double kappa;
|
double kappa;
|
||||||
/** the computed indicator values */
|
/** the computed indicator values */
|
||||||
std::vector < std::vector<double> > values;
|
std::vector < std::vector<Type> > values;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -181,6 +182,7 @@ class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorB
|
||||||
for (unsigned int i=0; i<_pop.size(); i++)
|
for (unsigned int i=0; i<_pop.size(); i++)
|
||||||
{
|
{
|
||||||
values[i].resize(_pop.size());
|
values[i].resize(_pop.size());
|
||||||
|
// the metric may not be symetric, thus neither is the matrix
|
||||||
for (unsigned int j=0; j<_pop.size(); j++)
|
for (unsigned int j=0; j<_pop.size(); j++)
|
||||||
{
|
{
|
||||||
if (i != j)
|
if (i != j)
|
||||||
|
|
@ -193,10 +195,10 @@ class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorB
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the fitness value of the whple population
|
* Sets the fitness value of the whole population
|
||||||
* @param _pop the population
|
* @param _pop the population
|
||||||
*/
|
*/
|
||||||
void setFitnesses(eoPop < MOEOT > & _pop)
|
virtual void setFitnesses(eoPop < MOEOT > & _pop)
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<_pop.size(); i++)
|
for (unsigned int i=0; i<_pop.size(); i++)
|
||||||
{
|
{
|
||||||
|
|
@ -209,9 +211,9 @@ class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorB
|
||||||
* Returns the fitness value of the _idx th individual of the population
|
* Returns the fitness value of the _idx th individual of the population
|
||||||
* @param _idx the index
|
* @param _idx the index
|
||||||
*/
|
*/
|
||||||
double computeFitness(const unsigned int _idx)
|
Type computeFitness(const unsigned int _idx)
|
||||||
{
|
{
|
||||||
double result = 0;
|
Type result(0.0);
|
||||||
for (unsigned int i=0; i<values.size(); i++)
|
for (unsigned int i=0; i<values.size(); i++)
|
||||||
{
|
{
|
||||||
if (i != _idx)
|
if (i != _idx)
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@
|
||||||
#include <fitness/moeoDominanceRankFitnessAssignment.h>
|
#include <fitness/moeoDominanceRankFitnessAssignment.h>
|
||||||
#include <fitness/moeoDummyFitnessAssignment.h>
|
#include <fitness/moeoDummyFitnessAssignment.h>
|
||||||
#include <fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h>
|
#include <fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h>
|
||||||
|
#include <fitness/moeoExpBinaryIndicatorBasedDualFitnessAssignment.h>
|
||||||
#include <fitness/moeoFitnessAssignment.h>
|
#include <fitness/moeoFitnessAssignment.h>
|
||||||
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
|
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
|
||||||
#include <fitness/moeoReferencePointIndicatorBasedFitnessAssignment.h>
|
#include <fitness/moeoReferencePointIndicatorBasedFitnessAssignment.h>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue