moeoHypervolumeBinaryMetric.h

00001 /*
00002 * <moeoHypervolumeBinaryMetric.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 //-----------------------------------------------------------------------------
00037 
00038 #ifndef MOEOHYPERVOLUMEBINARYMETRIC_H_
00039 #define MOEOHYPERVOLUMEBINARYMETRIC_H_
00040 
00041 #include <stdexcept>
00042 #include <comparator/moeoParetoObjectiveVectorComparator.h>
00043 #include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
00044 
00053 template < class ObjectiveVector >
00054 class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
00055   {
00056   public:
00057 
00062     moeoHypervolumeBinaryMetric(double _rho = 1.1) : rho(_rho)
00063     {
00064       // not-a-maximization problem check
00065       for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
00066         {
00067           if (ObjectiveVector::Traits::maximizing(i))
00068             {
00069               throw std::runtime_error("Hypervolume binary metric not yet implemented for a maximization problem in moeoHypervolumeBinaryMetric");
00070             }
00071         }
00072       // consistency check
00073       if (rho < 1)
00074         {
00075           std::cout << "Warning, value used to compute the reference point rho for the hypervolume calculation must not be smaller than 1" << std::endl;
00076           std::cout << "Adjusted to 1" << std::endl;
00077           rho = 1;
00078         }
00079     }
00080 
00081 
00088     double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
00089     {
00090       double result;
00091       // if _o2 is dominated by _o1
00092       if ( paretoComparator(_o2,_o1) )
00093         {
00094           result = - hypervolume(_o1, _o2, ObjectiveVector::Traits::nObjectives()-1);
00095         }
00096       else
00097         {
00098           result = hypervolume(_o2, _o1, ObjectiveVector::Traits::nObjectives()-1);
00099         }
00100       return result;
00101     }
00102 
00103 
00104   private:
00105 
00107     double rho;
00109     using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
00111     moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
00112 
00113 
00121     double hypervolume(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj, const bool _flag = false)
00122     {
00123       double result;
00124       double range = rho * bounds[_obj].range();
00125       double max = bounds[_obj].minimum() + range;
00126       // value of _1 for the objective _obj
00127       double v1 = _o1[_obj];
00128       // value of _2 for the objective _obj (if _flag=true, v2=max)
00129       double v2;
00130       if (_flag)
00131         {
00132           v2 = max;
00133         }
00134       else
00135         {
00136           v2 = _o2[_obj];
00137         }
00138       // computation of the volume
00139       if (_obj == 0)
00140         {
00141           if (v1 < v2)
00142             {
00143               result = (v2 - v1) / range;
00144             }
00145           else
00146             {
00147               result = 0;
00148             }
00149         }
00150       else
00151         {
00152           if (v1 < v2)
00153             {
00154               result = ( hypervolume(_o1, _o2, _obj-1, true) * (v2 - v1) / range ) + ( hypervolume(_o1, _o2, _obj-1) * (max - v2) / range );
00155             }
00156           else
00157             {
00158               result = hypervolume(_o1, _o2, _obj-1) * (max - v2) / range;
00159             }
00160         }
00161       return result;
00162     }
00163 
00164   };
00165 
00166 #endif /*MOEOHYPERVOLUMEBINARYMETRIC_H_*/

Generated on Thu Mar 13 15:54:08 2008 for ParadisEO-MOEO-MultiObjectiveEvolvingObjects by  doxygen 1.4.7