Binary Metric Epsilon added in MOEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1223 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2008-07-23 08:56:44 +00:00
commit a1956e2524
3 changed files with 342 additions and 0 deletions

View file

@ -0,0 +1,91 @@
/*
* <moeoVecVsVecAdditiveEpsilonBinaryMetric.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Jeremie Humeau
* Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOVECVSVECADDITIVEEPSILONBINARYMETRIC_H_
#define MOEOVECVSVECADDITIVEEPSILONBINARYMETRIC_H_
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <metric/moeoMetric.h>
/**
* moeoVecVsVecAdditiveEpsilonBinaryMetric is the implementation of moeoVecVsVecEpsilonBinaryMetric whose calculate an additive epsilon indicator
*/
template < class ObjectiveVector >
class moeoVecVsVecAdditiveEpsilonBinaryMetric : public moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >
{
public:
/**
* Default Constructor: inherit of moeoVecVsVecEpsilonBinaryMetric
*/
moeoVecVsVecAdditiveEpsilonBinaryMetric(bool _normalize=true): moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >(_normalize){}
private:
/**
* compute the additive epsilon indicator. Ieps+(A,B) equals the minimum factor eps such that any objective vector in B is eps-dominated by at least one objective vector in A.
* a vector z1 is said to eps+-dominate another vector z2, if we can add each objective value in z2 by eps and the resulting objective vector is still weakly dominates by z1.
* @param _o1 the first objective vector (correspond to A, must not have dominated elements)
* @param _o2 the second objective vector (correspond to B, must not have dominated elements)
* @return the additive epsilon indicator between the two objective vector _o1 and _o2
*/
double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj){
double result;
// if the objective _obj have to be minimized
if (ObjectiveVector::Traits::minimizing(_obj))
{
// _o1[_obj] - _o2[_obj]
result = ( (_o1[_obj] - moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >::bounds[_obj].minimum()) / moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >::bounds[_obj].range() ) - ( (_o2[_obj] - moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >::bounds[_obj].minimum()) / moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >::bounds[_obj].range() );
}
// if the objective _obj have to be maximized
else
{
// _o2[_obj] - _o1[_obj]
result = ( (_o2[_obj] - moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >::bounds[_obj].minimum()) / moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >::bounds[_obj].range() ) - ( (_o1[_obj] - moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >::bounds[_obj].minimum()) / moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >::bounds[_obj].range() );
}
return result;
}
};
#endif /*MOEOVECVSVECEPSILONBINARYMETRIC_H_*/

View file

@ -0,0 +1,152 @@
/*
* <moeoVecVsVecEpsilonBinaryMetric.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Jeremie Humeau
* Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOVECVSVECEPSILONBINARYMETRIC_H_
#define MOEOVECVSVECEPSILONBINARYMETRIC_H_
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <metric/moeoMetric.h>
/**
* moeoVecVsVecEpsilonBinaryMetric is an abstract class allow to calculate the epsilon indicator betweend two Pareto sets
*/
template < class ObjectiveVector >
class moeoVecVsVecEpsilonBinaryMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
{
public:
/**
* Default Construtcor
* @param _normalize allow to normalize data (default true)
*/
moeoVecVsVecEpsilonBinaryMetric(bool _normalize=true): normalize(_normalize){
bounds.resize(ObjectiveVector::Traits::nObjectives());
// initialize bounds in case someone does not want to use them
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
bounds[i] = eoRealInterval(0,1);
}
}
/**
* Returns the epsilon indicator between two pareto sets.
* @param _set1 the first Pareto set (must not have dominated element)
* @param _set2 the second Pareto set (must not have dominated element)
*/
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2)
{
if (normalize)
setup(_set1, _set2);
double eps, eps_temp, eps_j, eps_k;
unsigned i, j, k;
for (i = 0; i < _set2.size(); i++) {
for (j = 0; j < _set1.size(); j++) {
for (k = 0; k < ObjectiveVector::Traits::nObjectives(); k++) {
eps_temp=epsilon(_set1[j], _set2[i], k);
if (k == 0)
eps_k = eps_temp;
else if (eps_k < eps_temp)
eps_k = eps_temp;
}
if (j == 0)
eps_j = eps_k;
else if (eps_j > eps_k)
eps_j = eps_k;
}
if (i == 0)
eps = eps_j;
else if (eps < eps_j)
eps = eps_j;
}
return eps;
}
std::vector < eoRealInterval > getBounds(){
return bounds;
}
/**
* method caclulate bounds for the normalization
* @param _set1 the first vector of objective vectors
* @param _set2 the second vector of objective vectors
*/
void setup(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2){
double min, max;
unsigned int nbObj=ObjectiveVector::Traits::nObjectives();
bounds.resize(nbObj);
for (unsigned int i=0; i<nbObj; i++){
min = _set1[0][i];
max = _set1[0][i];
for (unsigned int j=1; j<_set1.size(); j++){
min = std::min(min, _set1[j][i]);
max = std::max(max, _set1[j][i]);
}
for (unsigned int j=0; j<_set2.size(); j++){
min = std::min(min, _set2[j][i]);
max = std::max(max, _set2[j][i]);
}
bounds[i] = eoRealInterval(min, max);
}
}
protected:
/*vectors contains bounds for normalization*/
std::vector < eoRealInterval > bounds;
/*boolean indicates if data must be normalized or not*/
bool normalize;
private :
/**
* abstract method allow to use differents epsilon indicators
* @param _o1 the first objective vector
* @parama _o2 the second objective vector
* @return an epsilon indicator between two objective vectors
*/
virtual double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj)=0;
};
#endif /*MOEOVECVSVECEPSILONBINARYMETRIC_H_*/

View file

@ -0,0 +1,99 @@
/*
* <moeoVecVsVecMultiplicativeEpsilonBinaryMetric.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Jeremie Humeau
* Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOVECVSVECMULTIPLICATIVEEPSILONBINARYMETRIC_H_
#define MOEOVECVSVECMULTIPLICATIVEEPSILONBINARYMETRIC_H_
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <metric/moeoMetric.h>
#include <exception>
/**
* moeoVecVsVecMultiplicativeEpsilonBinaryMetric is the implementation of moeoVecVsVecEpsilonBinaryMetric whose calculate a multiplicative epsilon indicator
*/
template < class ObjectiveVector >
class moeoVecVsVecMultiplicativeEpsilonBinaryMetric : public moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >
{
public:
/**
* Default Constructor: inherit of moeoVecVsVecEpsilonBinaryMetric
*/
moeoVecVsVecMultiplicativeEpsilonBinaryMetric(): moeoVecVsVecEpsilonBinaryMetric < ObjectiveVector >(false){}
private:
/**
* Precondition : for a given _obj, _o1 and _o2 must both have a strictly positive or a strictly negative value else an exception is thrown
* compute the epsilon indicator. Ieps(A,B) equals the minimum factor eps such that any objective vector in B is eps-dominated by at least one objective vector in A.
* a vector z1 is said to eps-dominate another vector z2, if we can multiply each objective value in z2 by a factor of z2 and the resulting objective vector is still weakly dominates by z1.
*
* @param _o1 the first objective vector (correspond to A, must not have dominated elements)
* @param _o2 the second objective vector (correspond to B, must not have dominated elements)
* @return the epsilon indicator between the two objective vector _o1 and _o2
*/
double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj){
double result;
//test if values are correct
if ( _o1[_obj] * _o2[_obj] <= 0.0){
std::cout << "ERROR in moeoVecVsVecMultiplicativeEpsilonBinaryMetric::epsilon -> ObjectiveVectors contains bad values";
throw("ERROR in moeoVecVsVecMultiplicativeEpsilonBinaryMetric::epsilon -> ObjectiveVectors contains bad values");
}
else{
// if the objective _obj have to be minimized
if (ObjectiveVector::Traits::minimizing(_obj))
{
// _o1[_obj] / _o2[_obj]
result = ( _o1[_obj] / _o2[_obj]);
}
// if the objective _obj have to be maximized
else
{
// _o2[_obj] / _o1[_obj]
result = (_o2[_obj] / _o1[_obj]);
}
}
return result;
}
};
#endif /*MOEOVECVSVECEPSILONBINARYMETRIC_H_*/