This commit is contained in:
LPTK 2013-06-13 14:57:12 +02:00
commit d1428e91c8
13 changed files with 653 additions and 281 deletions

View file

@ -160,7 +160,7 @@ public:
* @param _op variation operators
* @param _fitnessAssignment fitness assignment
*/
moeoIBEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoGenOp < MOEOT > & _op, moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT >& _fitnessAssignment) :
moeoIBEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoGenOp < MOEOT > & _op, moeoBinaryIndicatorBasedFitnessAssignment < MOEOT >& _fitnessAssignment) :
defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), select(2),
selectMany(select,0.0), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), genBreed(select, _op), breed(genBreed), default_fitnessAssignment(NULL), fitnessAssignment(_fitnessAssignment), replace(fitnessAssignment, diversityAssignment)
{}
@ -173,7 +173,7 @@ public:
* @param _op variation operators
* @param _fitnessAssignment fitness assignment
*/
moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT >& _fitnessAssignment) :
moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoBinaryIndicatorBasedFitnessAssignment < MOEOT >& _fitnessAssignment) :
defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), select(2),
selectMany(select,0.0), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), genBreed(select, _op), breed(genBreed), default_fitnessAssignment(NULL), fitnessAssignment(_fitnessAssignment), replace(fitnessAssignment, diversityAssignment)
{}
@ -190,7 +190,7 @@ public:
* Apply the algorithm to the population _pop until the stopping criteria is satified.
* @param _pop the population
*/
virtual void operator () (eoPop < MOEOT > &_pop)
virtual void operator() (eoPop < MOEOT > &_pop)
{
eoPop < MOEOT > offspring, empty_pop;
popEval (empty_pop, _pop); // a first eval of _pop
@ -260,8 +260,8 @@ protected:
/** breeder */
eoBreed < MOEOT > & breed;
/** fitness assignment used in IBEA */
moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT >& fitnessAssignment;
moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT >* default_fitnessAssignment;
moeoBinaryIndicatorBasedFitnessAssignment < MOEOT >& fitnessAssignment;
/** dummy diversity assignment */
moeoDummyDiversityAssignment < MOEOT > diversityAssignment;
/** environmental replacement */

View file

@ -0,0 +1,121 @@
/*
(c) 2013 Thales group
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; version 2
of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Johann Dréo <johann.dreo@thalesgroup.com>
*/
#ifndef _moeoDualHypContinue_h
#define _moeoDualHypContinue_h
#include <continue/moeoHypContinue.h>
/**
Continues until the (feasible or unfeasible) given Pareto set is reached.
@ingroup Continuators
*/
template< class MOEOT, class MetricT = moeoDualHyperVolumeDifferenceMetric<typename MOEOT::ObjectiveVector> >
class moeoDualHypContinue: public moeoHypContinue<MOEOT, MetricT >
{
protected:
bool is_feasible;
using moeoHypContinue<MOEOT, MetricT>::arch;
using moeoHypContinue<MOEOT, MetricT>::OptimSet;
using moeoHypContinue<MOEOT, MetricT>::pareto;
using moeoHypContinue<MOEOT, MetricT>::is_null_hypervolume;
public:
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
typedef typename ObjectiveVector::Type AtomType;
/** A continuator that stops once a given Pareto front has been reached
*
* You should specify the feasibility of the targeted front.
* NOTE: the MOEOT::ObjectiveVector is supposed to implement the moeoDualRealObjectiveVector interface.
*
*/
moeoDualHypContinue( const std::vector<AtomType> & _OptimVec, bool _is_feasible, moeoArchive < MOEOT > & _archive, bool _normalize=true, double _rho=1.1 )
: moeoHypContinue<MOEOT, MetricT>( _OptimVec, _archive, _normalize, _rho ),
is_feasible(_is_feasible)
{
assert( _OptimVec.size() > 0);
vectorToParetoSet(_OptimVec);
}
/** A continuator that stops once a given Pareto front has been reached
*
* You should specify the feasibility of the targeted front.
* NOTE: the MOEOT::ObjectiveVector is supposed to implement the moeoDualRealObjectiveVector interface.
*
*/
moeoDualHypContinue( const std::vector<AtomType> & _OptimVec, bool _is_feasible, moeoArchive < MOEOT > & _archive, bool _normalize=true, ObjectiveVector& _ref_point=NULL )
: moeoHypContinue<MOEOT, MetricT>( _OptimVec, _archive, _normalize, _ref_point ),
is_feasible(_is_feasible)
{
assert( _OptimVec.size() > 0);
vectorToParetoSet(_OptimVec);
}
/** Returns false when a ParetoSet is reached. */
virtual bool operator() ( const eoPop<MOEOT>& /*_pop*/ )
{
std::vector<ObjectiveVector> bestCurrentParetoSet = pareto( arch );
#ifndef NDEBUG
assert( bestCurrentParetoSet.size() > 0 );
for( unsigned int i=1; i<bestCurrentParetoSet.size(); ++i ) {
assert( bestCurrentParetoSet[i].is_feasible() == bestCurrentParetoSet[0].is_feasible() );
}
#endif
// The current Pareto front is either feasible or unfeasible.
// It could not contains both kind of objective vectors, because a feasible solution always dominates an unfeasible front.
if( bestCurrentParetoSet[0].is_feasible() != OptimSet[0].is_feasible() ) {
return false;
}
return is_null_hypervolume( bestCurrentParetoSet );
}
protected:
/** Translate a vector given as param to the ParetoSet that should be reached. */
virtual void vectorToParetoSet(const std::vector<AtomType> & _OptimVec)
{
unsigned dim = (unsigned)(_OptimVec.size()/ObjectiveVector::Traits::nObjectives());
OptimSet.resize(dim);
unsigned k=0;
for(size_t i=0; i < dim; i++) {
for (size_t j=0; j < ObjectiveVector::Traits::nObjectives(); j++) {
// Use the feasibility declaration of an eoDualFitness
OptimSet[i][j] = AtomType(_OptimVec[k++], is_feasible);
}
}
}
};
#endif

View file

@ -36,7 +36,6 @@
//-----------------------------------------------------------------------------
#ifndef _moeoHypContinue_h
#define _moeoHypContinue_h
@ -60,20 +59,32 @@ public:
/// Ctor
moeoHypContinue( const std::vector<AtomType> & _OptimVec, moeoArchive < MOEOT > & _archive, bool _normalize=true, double _rho=1.1)
: eoContinue<MOEOT>(), arch(_archive), metric(_normalize,_rho)
: eoContinue<MOEOT>(), arch(_archive), default_metric(new MetricT(_normalize,_rho)), metric(*default_metric)
{
vectorToParetoSet(_OptimVec);
}
moeoHypContinue( const std::vector<AtomType> & _OptimVec, moeoArchive < MOEOT > & _archive, bool _normalize=true, ObjectiveVector& _ref_point=NULL)
: eoContinue<MOEOT> (), arch(_archive), metric(_normalize,_ref_point)
: eoContinue<MOEOT>(), arch(_archive), default_metric(new MetricT(_normalize,_ref_point)), metric(*default_metric)
{
vectorToParetoSet(_OptimVec);
}
moeoHypContinue( MetricT& _metric, const std::vector<AtomType> & _OptimVec, moeoArchive < MOEOT > & _archive )
: eoContinue<MOEOT>(), arch(_archive), default_metric(NULL), metric(_metric)
{
vectorToParetoSet(_OptimVec);
}
~moeoHypContinue()
{
if( default_metric != NULL ) {
delete default_metric;
}
}
/** Returns false when a ParetoSet is reached. */
virtual bool operator() ( const eoPop<MOEOT>& _pop )
virtual bool operator() ( const eoPop<MOEOT>& /*_pop*/ )
{
std::vector<ObjectiveVector> bestCurrentParetoSet = pareto( arch );
@ -88,8 +99,8 @@ protected:
{
std::vector < ObjectiveVector > bestCurrentParetoSet;
for (size_t i=0; i<arch.size(); i++) {
bestCurrentParetoSet.push_back(arch[i].objectiveVector());
for (size_t i=0; i<_archive.size(); i++) {
bestCurrentParetoSet.push_back(_archive[i].objectiveVector());
}
return bestCurrentParetoSet;
@ -123,96 +134,10 @@ protected:
protected:
moeoArchive <MOEOT> & arch;
MetricT metric;
MetricT* default_metric;
MetricT& metric;
std::vector <ObjectiveVector> OptimSet;
};
/**
Continues until the (feasible or unfeasible) given Pareto set is reached.
@ingroup Continuators
*/
template< class MOEOT, class MetricT = moeoDualHyperVolumeDifferenceMetric<typename MOEOT::ObjectiveVector> >
class moeoDualHypContinue: public moeoHypContinue<MOEOT, MetricT >
{
protected:
bool is_feasible;
using moeoHypContinue<MOEOT, MetricT>::arch;
using moeoHypContinue<MOEOT, MetricT>::OptimSet;
public:
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
typedef typename ObjectiveVector::Type AtomType;
/** A continuator that stops once a given Pareto front has been reached
*
* You should specify the feasibility of the targeted front.
* NOTE: the MOEOT::ObjectiveVector is supposed to implement the moeoDualRealObjectiveVector interface.
*
*/
moeoDualHypContinue<MOEOT, MetricT>( const std::vector<AtomType> & _OptimVec, bool _is_feasible, moeoArchive < MOEOT > & _archive, bool _normalize=true, double _rho=1.1 )
: moeoHypContinue<MOEOT, MetricT>( _OptimVec, _archive, _normalize, _rho ), is_feasible(_is_feasible)
{
assert( _OptimVec.size() > 0);
vectorToParetoSet(_OptimVec);
}
/** A continuator that stops once a given Pareto front has been reached
*
* You should specify the feasibility of the targeted front.
* NOTE: the MOEOT::ObjectiveVector is supposed to implement the moeoDualRealObjectiveVector interface.
*
*/
moeoDualHypContinue<MOEOT, MetricT>( const std::vector<AtomType> & _OptimVec, bool _is_feasible, moeoArchive < MOEOT > & _archive, bool _normalize=true, ObjectiveVector& _ref_point=NULL )
: moeoHypContinue<MOEOT, MetricT>( _OptimVec, _archive, _normalize, _ref_point ), is_feasible(_is_feasible)
{
assert( _OptimVec.size() > 0);
vectorToParetoSet(_OptimVec);
}
/** Returns false when a ParetoSet is reached. */
virtual bool operator() ( const eoPop<MOEOT>& _pop )
{
std::vector<ObjectiveVector> bestCurrentParetoSet = pareto( arch );
#ifndef NDEBUG
assert( bestCurrentParetoSet.size() > 0 );
for( unsigned int i=1; i<bestCurrentParetoSet.size(); ++i ) {
assert( bestCurrentParetoSet[i].is_feasible() == bestCurrentParetoSet[0].is_feasible() );
}
#endif
// The current Pareto front is either feasible or unfeasible.
// It could not contains both kind of objective vectors, because a feasible solution always dominates an unfeasible front.
if( bestCurrentParetoSet[0].is_feasible() != OptimSet[0].is_feasible() ) {
return false;
}
return is_null_hypervolume( bestCurrentParetoSet );
}
protected:
using moeoHypContinue<MOEOT, MetricT>::pareto;
using moeoHypContinue<MOEOT, MetricT>::is_null_hypervolume;
/** Translate a vector given as param to the ParetoSet that should be reached. */
virtual void vectorToParetoSet(const std::vector<AtomType> & _OptimVec)
{
unsigned dim = (unsigned)(_OptimVec.size()/ObjectiveVector::Traits::nObjectives());
OptimSet.resize(dim);
unsigned k=0;
for(size_t i=0; i < dim; i++) {
for (size_t j=0; j < ObjectiveVector::Traits::nObjectives(); j++) {
// Use the feasibility declaration of an eoDualFitness
OptimSet[i][j] = AtomType(_OptimVec[k++], is_feasible);
}
}
}
};
#endif

View file

@ -74,7 +74,7 @@ class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
* @param _pop the population
* @param _objVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
void updateByDeleting(eoPop < MOEOT > & /*_pop*/, ObjectiveVector & /*_objVec*/)
{
// nothing to do... ;-)
}

View file

@ -1,3 +1,31 @@
/*
(c) 2013 Thales group
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; version 2
of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Johann Dréo <johann.dreo@thalesgroup.com>
*/
#ifndef MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_
#define MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_
#include <fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h>
@ -5,8 +33,7 @@ template<class MOEOT>
class moeoExpBinaryIndicatorBasedDualFitnessAssignment : public moeoExpBinaryIndicatorBasedFitnessAssignment<MOEOT>
{
protected:
eoPop<MOEOT> _feasible_pop;
eoPop<MOEOT> _unfeasible_pop;
eoDualPopSplit<MOEOT> _pop_split;
public:
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
@ -19,64 +46,58 @@ public:
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)
virtual void operator()( eoPop<MOEOT>& pop )
{
// separate the pop in the members
split( pop );
// separate the pop in feasible/unfeasible
_pop_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;
// if there is at least one feasible individual,
// it will supersede all the unfeasible ones
if( _pop_split.feasible().size() == 0 ) {
ppop = & _pop_split.unfeasible();
} else {
ppop = & _feasible_pop;
ppop = & _pop_split.feasible();
}
this->setup(*ppop);
this->computeValues(*ppop);
this->setFitnesses(*ppop);
this->setFitnesses(*ppop); // NOTE: this alter individuals
// bring back altered individuals in the pop
pop = _pop_split.merge();
}
protected:
using moeoExpBinaryIndicatorBasedFitnessAssignment<MOEOT>::kappa;
/**
* Compute every indicator value in values (values[i] = I(_v[i], _o))
* @param _pop the population
*/
void computeValues(const eoPop < MOEOT > & _pop)
virtual void computeValues(const eoPop < MOEOT > & pop)
{
values.clear();
values.resize(_pop.size());
for (unsigned int i=0; i<_pop.size(); i++)
{
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++)
{
if (i != j)
{
values[i][j] = Type( metric(_pop[i].objectiveVector(), _pop[j].objectiveVector()), _pop[i].objectiveVector().is_feasible() );
}
}
}
values.clear();
values.resize(pop.size());
for (unsigned int i=0; i<pop.size(); i++) {
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++) {
if (i != j) {
values[i][j] = Type(
metric( pop[i].objectiveVector(), pop[j].objectiveVector() ),
pop[i].objectiveVector().is_feasible()
);
} // if i != j
} // for j in pop
} // for i in pop
}
virtual void setFitnesses(eoPop < MOEOT > & pop)
@ -87,6 +108,20 @@ public:
}
}
virtual Type computeFitness(const unsigned int _idx)
{
Type result( 0.0, values[_idx][_idx].is_feasible() );
for (unsigned int i=0; i<values.size(); i++)
{
if (i != _idx)
{
result -= exp(-values[i][_idx]/kappa);
}
}
return result;
}
};
#endif // MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_

View file

@ -175,7 +175,7 @@ class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorB
* Compute every indicator value in values (values[i] = I(_v[i], _o))
* @param _pop the population
*/
void computeValues(const eoPop < MOEOT > & _pop)
virtual void computeValues(const eoPop < MOEOT > & _pop)
{
values.clear();
values.resize(_pop.size());
@ -211,7 +211,7 @@ class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorB
* Returns the fitness value of the _idx th individual of the population
* @param _idx the index
*/
Type computeFitness(const unsigned int _idx)
virtual Type computeFitness(const unsigned int _idx)
{
Type result(0.0);
for (unsigned int i=0; i<values.size(); i++)

View file

@ -0,0 +1,117 @@
/*
(c) 2013 Thales group
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; version 2
of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Johann Dréo <johann.dreo@thalesgroup.com>
*/
#ifndef MOEODUALHYPERVOLUMEDIFFERENCEMETRIC_H_
#define MOEODUALHYPERVOLUMEDIFFERENCEMETRIC_H_
#include <metric/moeoHyperVolumeDifferenceMetric.h>
template<class ObjectiveVector>
class moeoDualHyperVolumeDifferenceMetric : public moeoHyperVolumeDifferenceMetric<ObjectiveVector>
{
protected:
using moeoHyperVolumeDifferenceMetric<ObjectiveVector>::rho;
using moeoHyperVolumeDifferenceMetric<ObjectiveVector>::normalize;
using moeoHyperVolumeDifferenceMetric<ObjectiveVector>::ref_point;
using moeoHyperVolumeDifferenceMetric<ObjectiveVector>::bounds;
public:
typedef typename ObjectiveVector::Type Type;
moeoDualHyperVolumeDifferenceMetric( bool _normalize=true, double _rho=1.1)
: moeoHyperVolumeDifferenceMetric<ObjectiveVector>(_normalize, _rho)
{
}
moeoDualHyperVolumeDifferenceMetric( bool _normalize/*=true*/, ObjectiveVector& _ref_point/*=NULL*/ )
: moeoHyperVolumeDifferenceMetric<ObjectiveVector>( _normalize, _ref_point )
{
}
/**
* calculates and returns the HyperVolume value of a pareto front
* @param _set1 the vector contains all objective Vector of the first pareto front
* @param _set2 the vector contains all objective Vector of the second pareto front
*/
virtual double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
{
#ifndef NDEBUG
// the two sets must be homogeneous in feasibility
assert( _set1.size() > 0 );
for( unsigned int i=1; i<_set1.size(); ++i ) {
assert( _set1[i].is_feasible() == _set1[0].is_feasible() );
}
assert( _set2.size() > 0 );
for( unsigned int i=1; i<_set2.size(); ++i ) {
assert( _set2[i].is_feasible() == _set2[0].is_feasible() );
}
// and they must have the same feasibility
assert( _set1[0].is_feasible() == _set2[0].is_feasible() );
#endif
bool feasible = _set1[0].is_feasible();
double hypervolume_set1;
double hypervolume_set2;
if(rho >= 1.0){
//determine bounds
setup(_set1, _set2);
//determine reference point
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++){
if(normalize){
if (ObjectiveVector::Traits::minimizing(i))
ref_point[i]= Type(rho, feasible);
else
ref_point[i]= Type(1-rho, feasible);
}
else{
if (ObjectiveVector::Traits::minimizing(i))
ref_point[i]= Type(bounds[i].maximum() * rho, feasible);
else
ref_point[i]= Type(bounds[i].maximum() * (1-rho), feasible);
}
}
//if no normalization, reinit bounds to O..1 for
if(!normalize)
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
bounds[i] = eoRealInterval(0,1);
}
else if(normalize)
setup(_set1, _set2);
moeoHyperVolumeMetric <ObjectiveVector> unaryMetric(ref_point, bounds);
hypervolume_set1 = unaryMetric(_set1);
hypervolume_set2 = unaryMetric(_set2);
return hypervolume_set1 - hypervolume_set2;
}
};
#endif /*MOEODUALHYPERVOLUMEDIFFERENCEMETRIC_H_*/

View file

@ -84,7 +84,7 @@ class moeoHyperVolumeDifferenceMetric : public moeoVectorVsVectorBinaryMetric <
* @param _set1 the vector contains all objective Vector of the first pareto front
* @param _set2 the vector contains all objective Vector of the second pareto front
*/
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
virtual double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
{
double hypervolume_set1;
@ -197,90 +197,4 @@ class moeoHyperVolumeDifferenceMetric : public moeoVectorVsVectorBinaryMetric <
};
template<class ObjectiveVector>
class moeoDualHyperVolumeDifferenceMetric : public moeoHyperVolumeDifferenceMetric<ObjectiveVector>
{
protected:
using moeoHyperVolumeDifferenceMetric<ObjectiveVector>::rho;
using moeoHyperVolumeDifferenceMetric<ObjectiveVector>::normalize;
using moeoHyperVolumeDifferenceMetric<ObjectiveVector>::ref_point;
using moeoHyperVolumeDifferenceMetric<ObjectiveVector>::bounds;
public:
typedef typename ObjectiveVector::Type Type;
moeoDualHyperVolumeDifferenceMetric( bool _normalize=true, double _rho=1.1)
: moeoHyperVolumeDifferenceMetric<ObjectiveVector>(_normalize, _rho)
{
}
moeoDualHyperVolumeDifferenceMetric( bool _normalize/*=true*/, ObjectiveVector& _ref_point/*=NULL*/ )
: moeoHyperVolumeDifferenceMetric<ObjectiveVector>( _normalize, _ref_point )
{
}
/**
* calculates and returns the HyperVolume value of a pareto front
* @param _set1 the vector contains all objective Vector of the first pareto front
* @param _set2 the vector contains all objective Vector of the second pareto front
*/
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
{
#ifndef NDEBUG
// the two sets must be homogeneous in feasibility
assert( _set1.size() > 0 );
for( unsigned int i=1; i<_set1.size(); ++i ) {
assert( _set1[i].is_feasible() == _set1[0].is_feasible() );
}
assert( _set2.size() > 0 );
for( unsigned int i=1; i<_set2.size(); ++i ) {
assert( _set2[i].is_feasible() == _set2[0].is_feasible() );
}
// and they must have the same feasibility
assert( _set1[0].is_feasible() == _set2[0].is_feasible() );
#endif
bool feasible = _set1[0].is_feasible();
double hypervolume_set1;
double hypervolume_set2;
if(rho >= 1.0){
//determine bounds
setup(_set1, _set2);
//determine reference point
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++){
if(normalize){
if (ObjectiveVector::Traits::minimizing(i))
ref_point[i]= Type(rho, feasible);
else
ref_point[i]= Type(1-rho, feasible);
}
else{
if (ObjectiveVector::Traits::minimizing(i))
ref_point[i]= Type(bounds[i].maximum() * rho, feasible);
else
ref_point[i]= Type(bounds[i].maximum() * (1-rho), feasible);
}
}
//if no normalization, reinit bounds to O..1 for
if(!normalize)
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
bounds[i] = eoRealInterval(0,1);
}
else if(normalize)
setup(_set1, _set2);
moeoHyperVolumeMetric <ObjectiveVector> unaryMetric(ref_point, bounds);
hypervolume_set1 = unaryMetric(_set1);
hypervolume_set2 = unaryMetric(_set2);
return hypervolume_set1 - hypervolume_set2;
}
};
#endif /*MOEOHYPERVOLUMEMETRIC_H_*/

View file

@ -144,6 +144,7 @@
#include <metric/moeoEntropyMetric.h>
#include <metric/moeoHypervolumeBinaryMetric.h>
#include <metric/moeoHyperVolumeDifferenceMetric.h>
#include <metric/moeoDualHyperVolumeDifferenceMetric.h>
#include <metric/moeoHyperVolumeMetric.h>
#include <metric/moeoMetric.h>
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
@ -217,5 +218,6 @@
#include <utils/moeoObjVecStat.h>
#include <continue/moeoHypContinue.h>
#include <continue/moeoDualHypContinue.h>
#endif /*MOEO_*/

View file

@ -1,5 +1,38 @@
/*
(c) 2013 Thales group
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; version 2
of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Johann Dréo <johann.dreo@thalesgroup.com>
*/
#ifndef _MOEOBINARYMETRICSTAT_H_
#define _MOEOBINARYMETRICSTAT_H_
#include <eo>
/** A wrapper to save a moeoMetric in an eoStat
*
* This wrap a MOEO binary metric into an eoStat
* This is useful if you want to use it in a checkpoint, for instance.
*/
template <class MOEOT, class T = double>
class moeoBinaryMetricStat : public eoStat<MOEOT, T>
{
@ -57,3 +90,5 @@ protected:
bool _first_gen;
};
#endif // _MOEOBINARYMETRICSTAT_H_