Generic ObjectiveVector types

This commit is contained in:
Johann Dreo 2013-06-07 12:43:09 +02:00 committed by LPTK
commit 0a9e4151ef
5 changed files with 40 additions and 8 deletions

View file

@ -80,7 +80,7 @@ public:
bestCurrentParetoSet.push_back(arch[i].objectiveVector()); bestCurrentParetoSet.push_back(arch[i].objectiveVector());
} }
AtomType hypervolume= metric(bestCurrentParetoSet,OptimSet ); double hypervolume= metric(bestCurrentParetoSet,OptimSet );
if (hypervolume==0) { if (hypervolume==0) {
eo::log << eo::logging << "STOP in moeoHypContinue: Best ParetoSet has been reached " eo::log << eo::logging << "STOP in moeoHypContinue: Best ParetoSet has been reached "

View file

@ -43,9 +43,9 @@ class moeoDualRealObjectiveVector : public moeoScalarObjectiveVector<ObjectiveVe
public: public:
moeoDualRealObjectiveVector(double value=0.0) moeoDualRealObjectiveVector(double value=0.0, bool feasible = false)
: moeoScalarObjectiveVector<ObjectiveVectorTraits, eoMinimizingDualFitness > : moeoScalarObjectiveVector<ObjectiveVectorTraits, eoMinimizingDualFitness >
( T(value, false) ) {} ( T(value, feasible) ) {}
bool is_feasible() const bool is_feasible() const
{ {
@ -113,4 +113,36 @@ class moeoDualRealObjectiveVector : public moeoScalarObjectiveVector<ObjectiveVe
}; };
/**
* Output for a moeoDualRealObjectiveVector object
* @param _os output stream
* @param _objectiveVector the objective vector to write
*/
template < class ObjectiveVectorTraits >
std::ostream & operator<<(std::ostream & _os, const moeoDualRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
{
for (unsigned int i=0; i<_objectiveVector.size()-1; i++)
_os << _objectiveVector[i] << " ";
_os << _objectiveVector[_objectiveVector.size()-1];
return _os;
}
/**
* Input for a moeoDualRealObjectiveVector object
* @param _is input stream
* @param _objectiveVector the objective vector to read
*/
template < class ObjectiveVectorTraits >
std::istream & operator>>(std::istream & _is, moeoDualRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
{
_objectiveVector = moeoDualRealObjectiveVector < ObjectiveVectorTraits > ();
for (unsigned int i=0; i<_objectiveVector.size(); i++)
{
_is >> _objectiveVector[i];
}
return _is;
}
#endif /*_DUALREALOBJECTIVEVECTOR_H_*/ #endif /*_DUALREALOBJECTIVEVECTOR_H_*/

View file

@ -56,7 +56,7 @@ class moeoHyperVolumeDifferenceMetric : public moeoVectorVsVectorBinaryMetric <
* @param _normalize allow to normalize data (default true) * @param _normalize allow to normalize data (default true)
* @param _rho coefficient to determine the reference point. * @param _rho coefficient to determine the reference point.
*/ */
moeoHyperVolumeDifferenceMetric(bool _normalize=true, double _rho=1.1): normalize(_normalize), rho(_rho), ref_point(NULL){ moeoHyperVolumeDifferenceMetric(bool _normalize=true, double _rho=1.1): normalize(_normalize), rho(_rho), ref_point(/*NULL*/){
bounds.resize(ObjectiveVector::Traits::nObjectives()); bounds.resize(ObjectiveVector::Traits::nObjectives());
// initialize bounds in case someone does not want to use them // initialize bounds in case someone does not want to use them
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
@ -70,7 +70,7 @@ class moeoHyperVolumeDifferenceMetric : public moeoVectorVsVectorBinaryMetric <
* @param _normalize allow to normalize data (default true) * @param _normalize allow to normalize data (default true)
* @param _ref_point the reference point * @param _ref_point the reference point
*/ */
moeoHyperVolumeDifferenceMetric(bool _normalize=true, ObjectiveVector& _ref_point=NULL): normalize(_normalize), rho(0.0), ref_point(_ref_point){ moeoHyperVolumeDifferenceMetric(bool _normalize/*=true*/, ObjectiveVector& _ref_point/*=NULL*/): normalize(_normalize), rho(0.0), ref_point(_ref_point){
bounds.resize(ObjectiveVector::Traits::nObjectives()); bounds.resize(ObjectiveVector::Traits::nObjectives());
// initialize bounds in case someone does not want to use them // initialize bounds in case someone does not want to use them
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++) for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
@ -149,7 +149,7 @@ class moeoHyperVolumeDifferenceMetric : public moeoVectorVsVectorBinaryMetric <
} }
#endif #endif
double min, max; typename ObjectiveVector::Type min, max;
unsigned int nbObj=ObjectiveVector::Traits::nObjectives(); unsigned int nbObj=ObjectiveVector::Traits::nObjectives();
bounds.resize(nbObj); bounds.resize(nbObj);
for (unsigned int i=0; i<nbObj; i++){ for (unsigned int i=0; i<nbObj; i++){

View file

@ -152,7 +152,7 @@ class moeoHyperVolumeMetric : public moeoVectorUnaryMetric < ObjectiveVector , d
if(_set.size() < 1) if(_set.size() < 1)
throw("Error in moeoHyperVolumeUnaryMetric::setup -> argument1: vector<ObjectiveVector> size must be greater than 0"); throw("Error in moeoHyperVolumeUnaryMetric::setup -> argument1: vector<ObjectiveVector> size must be greater than 0");
else{ else{
double min, max; typename ObjectiveVector::Type min, max;
unsigned int nbObj=ObjectiveVector::Traits::nObjectives(); unsigned int nbObj=ObjectiveVector::Traits::nObjectives();
bounds.resize(nbObj); bounds.resize(nbObj);
for (unsigned int i=0; i<nbObj; i++){ for (unsigned int i=0; i<nbObj; i++){

View file

@ -109,7 +109,7 @@ public:
* @param _set2 the second vector of objective vectors * @param _set2 the second vector of objective vectors
*/ */
void setup(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2){ void setup(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2){
double min, max; typename ObjectiveVector::Type min, max;
unsigned int nbObj=ObjectiveVector::Traits::nObjectives(); unsigned int nbObj=ObjectiveVector::Traits::nObjectives();
bounds.resize(nbObj); bounds.resize(nbObj);
for (unsigned int i=0; i<nbObj; i++){ for (unsigned int i=0; i<nbObj; i++){