trick to allow maximization

This commit is contained in:
Arnaud Liefooghe 2014-10-17 15:27:43 +02:00
commit 5a74f9a3c6

View file

@ -66,14 +66,6 @@ class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinar
*/ */
moeoHypervolumeBinaryMetric(double _rho = 1.1) : moeoNormalizedSolutionVsSolutionBinaryMetric<ObjectiveVector, double>(), rho(_rho) moeoHypervolumeBinaryMetric(double _rho = 1.1) : moeoNormalizedSolutionVsSolutionBinaryMetric<ObjectiveVector, double>(), rho(_rho)
{ {
// not-a-maximization problem check
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
if (ObjectiveVector::Traits::maximizing(i))
{
throw std::runtime_error("Hypervolume binary metric not yet implemented for a maximization problem in moeoHypervolumeBinaryMetric");
}
}
// consistency check // consistency check
if (rho < 1) if (rho < 1)
{ {
@ -92,6 +84,17 @@ class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinar
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2) double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
{ {
double result; double result;
// transform maximizing objectives into minimizing objectives
ObjectiveVector o1 = _o1;
ObjectiveVector o2 = _o2;
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
if (ObjectiveVector::Traits::maximizing(i))
{
o1[i] = bounds[i].maximum() - o1[i] + bounds[i].minimum();
o2[i] = bounds[i].maximum() - o2[i] + bounds[i].minimum();
}
}
// if _o2 is dominated by _o1 // if _o2 is dominated by _o1
if ( paretoComparator(_o2,_o1) ) if ( paretoComparator(_o2,_o1) )
{ {