ParetoDominanceComparator.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Implementation of the Pareto-Dominance relation.
5  *
6  * The function is described in
7  *
8  * Christian Igel, Nikolaus Hansen, and Stefan Roth.
9  * Covariance Matrix Adaptation for Multi-objective Optimization.
10  * Evolutionary Computation 15(1), pp. 1-28, 2007
11  *
12  *
13  *
14  * \author T.Voss
15  * \date 2011-2014
16  *
17  *
18  * \par Copyright 1995-2015 Shark Development Team
19  *
20  * <BR><HR>
21  * This file is part of Shark.
22  * <http://image.diku.dk/shark/>
23  *
24  * Shark is free software: you can redistribute it and/or modify
25  * it under the terms of the GNU Lesser General Public License as published
26  * by the Free Software Foundation, either version 3 of the License, or
27  * (at your option) any later version.
28  *
29  * Shark is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32  * GNU Lesser General Public License for more details.
33  *
34  * You should have received a copy of the GNU Lesser General Public License
35  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
36  *
37  */
38 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_PARETODOMINANCECOMPARATOR_H
39 #define SHARK_ALGORITHMS_DIRECTSEARCH_PARETODOMINANCECOMPARATOR_H
40 
41 #include <shark/Core/Exception.h>
42 
43 namespace shark {
44 /**
45 * \brief Implementation of the Pareto-Dominance relation under the assumption of all objectives to be minimized.
46 * \tparam Extractor returning the fitness vector of an object
47 */
48 template<typename Extractor>
50 
52  A_STRICTLY_DOMINATES_B = 3, ///< A strictly dominates B.
53  A_WEAKLY_DOMINATES_B = 2, ///< A weakly dominates B.
54  A_EQUALS_B = 1, ///< A equals B for every coordinate.
55  TRADE_OFF = -1, ///< Both A and B are a valid trade-off.
56  B_WEAKLY_DOMINATES_A = -2, ///< B weakly dominates B.
57  B_STRICTLY_DOMINATES_A = -3, ///< B strictly dominates A.
58  };
59 
60 
61  /**
62  * \brief Compares two individuals with respect to the Pareto-Dominance relation.
63  * \tparam IndividualType The type of the individuals, needs to be a model of TypedIndividual.
64  * \param [in] A Individual A.
65  * \param [in] B Individual B.
66  * \returns An integer with values according to the constanst defined within this class.
67  */
68  template<typename IndividualType>
69  int operator()( const IndividualType & A, const IndividualType & B ) {
70  Extractor e;
71  SIZE_CHECK(e( A ).size() == e( B ).size());
72 
73  unsigned numGreater = 0;
74  unsigned numEqual = 0;
75  unsigned numSmaller = 0;
76 
77  std::size_t noOfObj = e( A ).size();
78 
79  for (std::size_t i = 0; i != noOfObj; i++) {
80  if( e( A )[i] > e( B )[i] )
81  numGreater++;
82  else if( e( A )[i] < e( B )[i] )
83  numSmaller++;
84  else
85  numEqual++;
86  }
87 
88  if (numSmaller == noOfObj)
89  return A_STRICTLY_DOMINATES_B; // A dominates B completely
90  else if (numSmaller != 0 && numGreater == 0)
91  return A_WEAKLY_DOMINATES_B; // A dominates B incompletely
92  else if (numEqual == noOfObj)
93  return A_EQUALS_B; // A equals B
94  else if (numGreater == noOfObj)
95  return B_STRICTLY_DOMINATES_A; // B dominates A completely
96  else if (numGreater != 0 && numSmaller == 0)
97  return B_WEAKLY_DOMINATES_A; // B dominates A incompletely
98 
99  return TRADE_OFF; // trade off
100  }
101 };
102 }
103 #endif