ParetoDominance.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Implementation of the Pareto-Dominance relation.
5  *
6  *
7  * \author T. Glasmachers (based on old version by T. Voß)
8  * \date 2011-2016
9  *
10  *
11  * \par Copyright 1995-2017 Shark Development Team
12  *
13  * <BR><HR>
14  * This file is part of Shark.
15  * <http://shark-ml.org/>
16  *
17  * Shark is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Lesser General Public License as published
19  * by the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * Shark is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
29  *
30  */
31 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_OPERATORS_DOMINATION_PARETODOMINANCE_H
32 #define SHARK_ALGORITHMS_DIRECTSEARCH_OPERATORS_DOMINATION_PARETODOMINANCE_H
33 
34 
35 #include <shark/LinAlg/Base.h>
36 
37 
38 namespace shark {
39 
40 
41 /// \brief Result of comparing two objective vectors w.r.t. Pareto dominance.
43 {
44  INCOMPARABLE = 0, // LHS and RHS are incomparable
45  LHS_DOMINATES_RHS = 1, // LHS strictly dominates RHS
46  RHS_DOMINATES_LHS = 2, // RHS strictly dominates LHS
47  EQUIVALENT = 3, // LHS and RHS are equally good
48 };
49 
50 /// \brief Pareto dominance relation for two objective vectors.
51 template<class VectorTypeA, class VectorTypeB>
52 inline DominanceRelation dominance(VectorTypeA const& lhs, VectorTypeB const& rhs)
53 {
54  SHARK_ASSERT(lhs.size() == rhs.size());
55  std::size_t l = 0, r = 0;
56  for (std::size_t i=0; i<lhs.size(); i++)
57  {
58  if (lhs(i) < rhs(i)) l++;
59  else if (lhs(i) > rhs(i)) r++;
60  }
61 
62  if (l > 0)
63  {
64  if (r > 0) return INCOMPARABLE;
65  else return LHS_DOMINATES_RHS;
66  }
67  else
68  {
69  if (r > 0) return RHS_DOMINATES_LHS;
70  else return EQUIVALENT;
71  }
72 }
73 
74 
75 }; // namespace shark
76 #endif