Merge branch 'master' into trikiSA
This commit is contained in:
commit
8c4e91584f
13 changed files with 653 additions and 281 deletions
111
edo/src/edoTransform.h
Normal file
111
edo/src/edoTransform.h
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||
ANSI-C++ evolutionary computation library which helps you to write your
|
||||
own estimation of distribution algorithms.
|
||||
|
||||
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; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Copyright (C) 2013 Thales group
|
||||
*/
|
||||
/*
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#ifndef _edoTransform_h
|
||||
#define _edoTransform_h
|
||||
|
||||
#include <eo> // eoTransform
|
||||
|
||||
/** @defgroup Wrappers
|
||||
*
|
||||
* Wrappers to interact with other parts of the framework
|
||||
*/
|
||||
|
||||
/** Abstract base class for wrapping an estimator and a sampler as an eoTransform
|
||||
*
|
||||
* @ingroup Wrappers
|
||||
*/
|
||||
template<class D>
|
||||
class edoTransform : public eoTransform< eoPop<typename D::EOType>& >
|
||||
{
|
||||
public:
|
||||
typedef typename D::EOType EOType;
|
||||
|
||||
edoTransform( edoEstimator<D> & estimator, edoSampler<D> & sampler ) :
|
||||
_estimator(estimator), _sampler(sampler)
|
||||
{}
|
||||
|
||||
virtual void operator()( eoPop<EOType> & pop ) = 0;
|
||||
|
||||
protected:
|
||||
edoEstimator<D> & _estimator;
|
||||
edoSampler<D> & _sampler;
|
||||
};
|
||||
|
||||
|
||||
/** Wrapping an estimator and a sampler as an eoTransform.
|
||||
*
|
||||
* @ingroup Wrappers
|
||||
*/
|
||||
template<typename D>
|
||||
class edoTransformAdaptive : public edoTransform<D>
|
||||
{
|
||||
public:
|
||||
typedef typename D::EOType EOType;
|
||||
|
||||
edoTransformAdaptive( D & distrib, edoEstimator<D> & estimator, edoSampler<D> & sampler )
|
||||
: _distrib(distrib), _estimator(estimator), _sampler(sampler)
|
||||
{}
|
||||
|
||||
virtual void operator()( eoPop<EOType> & pop )
|
||||
{
|
||||
_distrib = _estimator( pop );
|
||||
pop.clear();
|
||||
for( unsigned int i = 0; i < pop.size(); ++i ) {
|
||||
pop.push_back( _sampler(_distrib) );
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
D & _distrib;
|
||||
edoEstimator<D> & _estimator;
|
||||
edoSampler<D> & _sampler;
|
||||
};
|
||||
|
||||
|
||||
/** Wrapping an estimator and a sampler as an eoTransform,
|
||||
* the distribution is created at instanciation and replaced at each call.
|
||||
*
|
||||
* @ingroup Wrappers
|
||||
*/
|
||||
template<typename D>
|
||||
class edoTransformStateless : public edoTransformAdaptive<D>
|
||||
{
|
||||
public:
|
||||
typedef typename D::EOType EOType;
|
||||
|
||||
edoTransformStateless( edoEstimator<D> & estimator, edoSampler<D> & sampler )
|
||||
: edoTransformAdaptive<D>( *(new D), estimator, sampler )
|
||||
{}
|
||||
|
||||
~edoTransformStateless()
|
||||
{
|
||||
// delete the temporary distrib allocated in constructor
|
||||
delete &(this->_distrib);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !_edoTransform_h
|
||||
|
|
@ -74,6 +74,25 @@ protected:
|
|||
//! Flag that marks if the individual is feasible
|
||||
bool _is_feasible;
|
||||
|
||||
/** Flag to prevent partial initialization
|
||||
*
|
||||
* The reason behind the use of this flag is a bit complicated.
|
||||
* Normally, we would not want to allow initialization on a scalar.
|
||||
* But in MOEO, this would necessitate to re-implement most of the
|
||||
* operator computing metrics, as they expect generic scalars.
|
||||
*
|
||||
* As this would be too much work, we use derived metric classes and
|
||||
* overload them so that they initialize dual fitnesses with the
|
||||
* feasibility flag. But the compiler still must compile the base
|
||||
* methods, that use the scalar interface.
|
||||
*
|
||||
* Thus, eoDualFitness has a scalar interface, but this flag add a
|
||||
* security against partial initialization. In DEBUG mode, asserts
|
||||
* will fail if the feasibility has not been explicitly initialized
|
||||
* at runtime.
|
||||
*/
|
||||
bool _feasible_init;
|
||||
|
||||
public:
|
||||
|
||||
//! Empty initialization
|
||||
|
|
@ -82,42 +101,46 @@ public:
|
|||
*/
|
||||
eoDualFitness() :
|
||||
_value(0.0),
|
||||
_is_feasible(false)
|
||||
_is_feasible(false),
|
||||
_feasible_init(false)
|
||||
{}
|
||||
|
||||
//! Initialization with only the value, the fitness will be unfeasible.
|
||||
/*!
|
||||
* WARNING: this is what is used when you initialize a new fitness from a double.
|
||||
* Unfeasible by default
|
||||
* If you use this interface, you MUST set the feasibility BEFORE
|
||||
* asking for it or the value. Or else, an assert will fail in debug mode.
|
||||
*/
|
||||
template<class T>
|
||||
eoDualFitness( T value ) :
|
||||
_value(value),
|
||||
_is_feasible(false)
|
||||
_is_feasible(false),
|
||||
_feasible_init(false)
|
||||
{
|
||||
assert( _value == 0 );
|
||||
}
|
||||
|
||||
|
||||
//! Copy constructor
|
||||
eoDualFitness(const eoDualFitness& other) :
|
||||
_value(other._value),
|
||||
_is_feasible(other._is_feasible)
|
||||
_is_feasible(other._is_feasible),
|
||||
_feasible_init(true)
|
||||
{}
|
||||
|
||||
//! Constructor from explicit value/feasibility
|
||||
eoDualFitness(const BaseType& v, const bool& is_feasible) :
|
||||
_value(v),
|
||||
_is_feasible(is_feasible)
|
||||
_is_feasible(is_feasible),
|
||||
_feasible_init(true)
|
||||
{}
|
||||
|
||||
//! From a std::pair (first element is the value, second is the feasibility)
|
||||
eoDualFitness(const std::pair<BaseType,bool>& dual) :
|
||||
_value(dual.first),
|
||||
_is_feasible(dual.second)
|
||||
_is_feasible(dual.second),
|
||||
_feasible_init(true)
|
||||
{}
|
||||
|
||||
// FIXME is it a good idea to include implicit conversion here?
|
||||
/** Conversion operator: it permits to use a fitness instance as its scalar
|
||||
* type, if needed. For example, this is possible:
|
||||
* eoDualFitness<double,std::less<double> > fit;
|
||||
|
|
@ -129,11 +152,20 @@ public:
|
|||
|
||||
inline bool is_feasible() const
|
||||
{
|
||||
assert( _feasible_init );
|
||||
return _is_feasible;
|
||||
}
|
||||
|
||||
//! Explicitly set the feasibility. Useful if you have used previously the instantiation on a single scalar.
|
||||
inline void is_feasible( bool feasible )
|
||||
{
|
||||
this->is_feasible( feasible );
|
||||
this->_feasible_init = true;
|
||||
}
|
||||
|
||||
inline BaseType value() const
|
||||
{
|
||||
assert( _feasible_init );
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +173,7 @@ public:
|
|||
eoDualFitness& operator=( const std::pair<BaseType, bool>& v )
|
||||
{
|
||||
this->_value = v.first;
|
||||
this->_is_feasible = v.second;
|
||||
this->is_feasible( v.second );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -151,21 +183,20 @@ public:
|
|||
{
|
||||
if (this != &other) {
|
||||
this->_value = other._value;
|
||||
this->_is_feasible = other._is_feasible;
|
||||
this->is_feasible( other.is_feasible() );
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
//! Copy operator from a scalar
|
||||
template<class T>
|
||||
eoDualFitness& operator=(const T v)
|
||||
{
|
||||
this->_value = v;
|
||||
this->_is_feasible = false;
|
||||
this->_feasible_init = false;
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
||||
//! Comparison that separate feasible individuals from unfeasible ones. Feasible are always better
|
||||
/*!
|
||||
|
|
@ -178,11 +209,11 @@ public:
|
|||
// am I better (less, by default) than the other ?
|
||||
|
||||
// if I'm feasible and the other is not
|
||||
if( this->_is_feasible && !other._is_feasible ) {
|
||||
if( this->is_feasible() && !other.is_feasible() ) {
|
||||
// no, the other has a better fitness
|
||||
return false;
|
||||
|
||||
} else if( !this->_is_feasible && other._is_feasible ) {
|
||||
} else if( !this->is_feasible() && other.is_feasible() ) {
|
||||
// yes, a feasible fitness is always better than an unfeasible one
|
||||
return true;
|
||||
|
||||
|
|
@ -322,7 +353,7 @@ public:
|
|||
friend
|
||||
std::ostream& operator<<( std::ostream& os, const eoDualFitness<BaseType,Compare> & fitness )
|
||||
{
|
||||
os << fitness._value << " " << fitness._is_feasible;
|
||||
os << fitness._value << " " << fitness.is_feasible();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
|
@ -337,7 +368,7 @@ public:
|
|||
is >> feasible;
|
||||
|
||||
fitness._value = value;
|
||||
fitness._is_feasible = feasible;
|
||||
fitness.is_feasible( feasible );
|
||||
return is;
|
||||
}
|
||||
};
|
||||
|
|
@ -355,35 +386,24 @@ template< class EOT>
|
|||
bool eoIsFeasible ( const EOT & sol ) { return sol.fitness().is_feasible(); }
|
||||
|
||||
|
||||
/** Embed two eoStat and call the first one on the feasible individuals and
|
||||
* the second one on the unfeasible ones, merge the two resulting value in
|
||||
* a string, separated by a given marker.
|
||||
/** Separate the population into two: one with only feasible individuals, the other with unfeasible ones.
|
||||
*/
|
||||
//template<class EOT, class T>
|
||||
template<class EOT, class EOSTAT>
|
||||
class eoDualStatSwitch : public eoStat< EOT, std::string >
|
||||
template<class EOT>
|
||||
class eoDualPopSplit : public eoUF<const eoPop<EOT>&, void>
|
||||
{
|
||||
protected:
|
||||
eoPop<EOT> _pop_feasible;
|
||||
eoPop<EOT> _pop_unfeasible;
|
||||
|
||||
public:
|
||||
using eoStat<EOT,std::string>::value;
|
||||
|
||||
// eoDualStatSwitch( eoStat<EOT,T> & stat_feasible, eoStat<EOT,T> & stat_unfeasible, std::string sep=" " ) :
|
||||
eoDualStatSwitch( EOSTAT & stat_feasible, EOSTAT & stat_unfeasible, std::string sep=" " ) :
|
||||
eoStat<EOT,std::string>(
|
||||
"?"+sep+"?",
|
||||
stat_feasible.longName()+sep+stat_unfeasible.longName()
|
||||
),
|
||||
_stat_feasible(stat_feasible),
|
||||
_stat_unfeasible(stat_unfeasible),
|
||||
_sep(sep)
|
||||
{ }
|
||||
|
||||
virtual void operator()( const eoPop<EOT> & pop )
|
||||
//! Split the pop and keep them in members
|
||||
void operator()( const eoPop<EOT>& pop )
|
||||
{
|
||||
eoPop<EOT> pop_feasible;
|
||||
pop_feasible.reserve(pop.size());
|
||||
_pop_feasible.clear();
|
||||
_pop_feasible.reserve(pop.size());
|
||||
|
||||
eoPop<EOT> pop_unfeasible;
|
||||
pop_unfeasible.reserve(pop.size());
|
||||
_pop_unfeasible.clear();
|
||||
_pop_unfeasible.reserve(pop.size());
|
||||
|
||||
for( typename eoPop<EOT>::const_iterator ieot=pop.begin(), iend=pop.end(); ieot!=iend; ++ieot ) {
|
||||
/*
|
||||
|
|
@ -392,28 +412,71 @@ public:
|
|||
}
|
||||
*/
|
||||
if( ieot->fitness().is_feasible() ) {
|
||||
pop_feasible.push_back( *ieot );
|
||||
_pop_feasible.push_back( *ieot );
|
||||
} else {
|
||||
pop_unfeasible.push_back( *ieot );
|
||||
_pop_unfeasible.push_back( *ieot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_stat_feasible( pop_feasible );
|
||||
_stat_unfeasible( pop_unfeasible );
|
||||
//! Merge feasible and unfeasible populations into a new one
|
||||
eoPop<EOT> merge() const
|
||||
{
|
||||
eoPop<EOT> merged;
|
||||
merged.reserve( _pop_feasible.size() + _pop_unfeasible.size() );
|
||||
std::copy( _pop_feasible.begin(), _pop_feasible.end(), std::back_inserter<eoPop<EOT> >(merged) );
|
||||
std::copy( _pop_unfeasible.begin(), _pop_unfeasible.end(), std::back_inserter<eoPop<EOT> >(merged) );
|
||||
return merged;
|
||||
}
|
||||
|
||||
eoPop<EOT>& feasible() { return _pop_feasible; }
|
||||
eoPop<EOT>& unfeasible() { return _pop_unfeasible; }
|
||||
};
|
||||
|
||||
|
||||
/** Embed two eoStat and call the first one on the feasible individuals and
|
||||
* the second one on the unfeasible ones, merge the two resulting value in
|
||||
* a string, separated by a given marker.
|
||||
*/
|
||||
template<class EOSTAT>
|
||||
class eoDualStatSwitch : public eoStat< typename EOSTAT::EOType, std::string >
|
||||
{
|
||||
public:
|
||||
typedef typename EOSTAT::EOType EOType;
|
||||
protected:
|
||||
EOSTAT & _stat_feasible;
|
||||
EOSTAT & _stat_unfeasible;
|
||||
|
||||
std::string _sep;
|
||||
|
||||
eoDualPopSplit<EOType> _pop_split;
|
||||
|
||||
public:
|
||||
using eoStat<EOType,std::string>::value;
|
||||
|
||||
eoDualStatSwitch( EOSTAT & stat_feasible, EOSTAT & stat_unfeasible, std::string sep=" " ) :
|
||||
eoStat<EOType,std::string>(
|
||||
"?"+sep+"?",
|
||||
stat_feasible.longName()+sep+stat_unfeasible.longName()
|
||||
),
|
||||
_stat_feasible(stat_feasible),
|
||||
_stat_unfeasible(stat_unfeasible),
|
||||
_sep(sep)
|
||||
{ }
|
||||
|
||||
virtual void operator()( const eoPop<EOType> & pop )
|
||||
{
|
||||
// create two separated pop in this operator
|
||||
_pop_split( pop );
|
||||
|
||||
_stat_feasible( _pop_split.feasible() );
|
||||
_stat_unfeasible( _pop_split.unfeasible() );
|
||||
|
||||
std::ostringstream out;
|
||||
out << _stat_feasible.value() << _sep << _stat_unfeasible.value();
|
||||
|
||||
value() = out.str();
|
||||
}
|
||||
|
||||
protected:
|
||||
// eoStat<EOT,T> & _stat_feasible;
|
||||
// eoStat<EOT,T> & _stat_unfeasible;
|
||||
EOSTAT & _stat_feasible;
|
||||
EOSTAT & _stat_unfeasible;
|
||||
|
||||
std::string _sep;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ Contact: http://eodev.sourceforge.net
|
|||
#include <eoPop.h>
|
||||
#include <utils/eoMonitor.h>
|
||||
//#include <utils/eoCheckPoint.h>
|
||||
#include <utils/eoLogger.h>
|
||||
|
||||
/** @defgroup Stats Statistics computation
|
||||
*
|
||||
|
|
@ -84,6 +85,7 @@ template <class EOT, class T>
|
|||
class eoStat : public eoValueParam<T>, public eoStatBase<EOT>
|
||||
{
|
||||
public:
|
||||
typedef EOT EOType;
|
||||
|
||||
eoStat(T _value, std::string _description)
|
||||
: eoValueParam<T>(_value, _description)
|
||||
|
|
@ -120,6 +122,7 @@ template <class EOT, class ParamType>
|
|||
class eoSortedStat : public eoSortedStatBase<EOT>, public eoValueParam<ParamType>
|
||||
{
|
||||
public :
|
||||
typedef EOT EOType;
|
||||
eoSortedStat(ParamType _value, std::string _desc) : eoValueParam<ParamType>(_value, _desc) {}
|
||||
virtual std::string className(void) const { return "eoSortedStat"; }
|
||||
|
||||
|
|
@ -472,6 +475,51 @@ public :
|
|||
};
|
||||
*/
|
||||
|
||||
//! A robust measure of the mass (generally used to compute the median). Do not alter the given pop.
|
||||
template<class EOT>
|
||||
class eoNthElementStat : public eoStat< EOT, typename EOT::Fitness >
|
||||
{
|
||||
protected:
|
||||
int _nth;
|
||||
double _ratio;
|
||||
|
||||
public:
|
||||
using eoStat<EOT, typename EOT::Fitness>::value;
|
||||
|
||||
eoNthElementStat( int nth = 0, std::string description = "NthElement")
|
||||
: eoStat<EOT,typename EOT::Fitness>( 0.0, description ), _nth(nth), _ratio(-1.0)
|
||||
{}
|
||||
|
||||
eoNthElementStat( double ratio = 0.5, std::string description = "Median" )
|
||||
: eoStat<EOT,typename EOT::Fitness>( 0.0, description ), _nth(-1), _ratio(ratio)
|
||||
{}
|
||||
|
||||
virtual void operator()( const eoPop<EOT> & _pop )
|
||||
{
|
||||
if( _nth == -1 ) { // asked for a ratio
|
||||
_nth = static_cast<int>( std::floor(_pop.size() * _ratio) );
|
||||
} else {
|
||||
assert( _ratio == -1 ); // asked for a position
|
||||
}
|
||||
|
||||
if( _pop.size() == 0 ) {
|
||||
//FIXME how to implement value() = 0 ?
|
||||
eo::log << eo::warnings << "Called " << className() << " on an empty pop, value unchanged" << std::endl;
|
||||
|
||||
} else {
|
||||
eoPop<EOT> pop = _pop; // copy, thus no sorting of the original pop
|
||||
|
||||
std::nth_element( pop.begin(), pop.begin()+_nth, pop.end() );
|
||||
value() = pop[_nth].fitness();
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "eoNthElementStat"; }
|
||||
};
|
||||
/** @example t-eoIQRStat.cpp
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//! A robust measure of dispersion (also called midspread or middle fifty) that is the difference between the third and the first quartile.
|
||||
template<class EOT>
|
||||
|
|
@ -480,12 +528,13 @@ class eoInterquartileRangeStat : public eoStat< EOT, typename EOT::Fitness >
|
|||
public:
|
||||
using eoStat<EOT, typename EOT::Fitness>::value;
|
||||
|
||||
eoInterquartileRangeStat( typename EOT::Fitness start, std::string description = "IQR" ) : eoStat<EOT,typename EOT::Fitness>( start, description ) {}
|
||||
eoInterquartileRangeStat( std::string description = "IQR" ) : eoStat<EOT,typename EOT::Fitness>( 0.0, description ) {}
|
||||
|
||||
virtual void operator()( const eoPop<EOT> & _pop )
|
||||
{
|
||||
if( _pop.size() == 0 ) {
|
||||
// how to implement value() = 0 ?
|
||||
//FIXME how to implement value() = 0 ?
|
||||
eo::log << eo::warnings << "Called " << className() << " on an empty pop, value unchanged" << std::endl;
|
||||
|
||||
} else {
|
||||
eoPop<EOT> pop = _pop;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{}
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
121
moeo/src/continue/moeoDualHypContinue.h
Normal file
121
moeo/src/continue/moeoDualHypContinue.h
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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... ;-)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,21 +46,6 @@ 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.
|
||||
|
|
@ -41,42 +53,51 @@ public:
|
|||
*/
|
||||
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());
|
||||
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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
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_
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
|
|
|
|||
117
moeo/src/metric/moeoDualHyperVolumeDifferenceMetric.h
Normal file
117
moeo/src/metric/moeoDualHyperVolumeDifferenceMetric.h
Normal 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_*/
|
||||
|
|
@ -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_*/
|
||||
|
|
|
|||
|
|
@ -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_*/
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue