GSP.h
Go to the documentation of this file.
1 /*!
2  * \brief GSP benchmark function for multiobjective optimization
3  *
4  * \author O. Krause
5  * \date 2015
6  *
7  *
8  * \par Copyright 1995-2017 Shark Development Team
9  *
10  * <BR><HR>
11  * This file is part of Shark.
12  * <http://shark-ml.org/>
13  *
14  * Shark is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License as published
16  * by the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * Shark is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
26  *
27  */
28 #ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_GSP_H
29 #define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_GSP_H
30 
33 #include <shark/Core/Random.h>
34 
35 namespace shark {
36 /// \brief Real-valued benchmark function with two objectives.
37 struct GSP : public MultiObjectiveFunction
38 {
39  GSP(std::size_t numVariables=5) : m_handler(SearchPointType(numVariables,0),SearchPointType(numVariables,10000)) {
40  announceConstraintHandler(&m_handler);
41  }
42 
43  /// \brief From INameable: return the class name.
44  std::string name() const
45  { return "GSP"; }
46 
47  std::size_t numberOfObjectives()const{
48  return 2;
49  }
50 
51  std::size_t numberOfVariables()const{
52  return m_handler.dimensions();
53  }
54 
56  return true;
57  }
58 
60  m_handler.setBounds(
61  SearchPointType(numberOfVariables,0),
62  SearchPointType(numberOfVariables,10000)
63  );
64  }
65 
66  ResultType eval( const SearchPointType & x ) const {
68 
69  ResultType value( 2 );
70  double alpha = 1. / ( 2. * m_gamma );
71 
72  double sum1 = 0., sum2 = 0.;
73 
74  for( std::size_t i = 0; i < x.size(); i++ ) {
75  sum1 += sqr( x( i ) );
76  sum2 += sqr( 1 - x( i ) );
77  }
78 
79  double alphaN = 1. / ( std::pow( x.size(), alpha ) );
80 
81  value[0] = alphaN * std::pow( sum1, alpha );
82  value[1] = alphaN * std::pow( sum2, alpha );
83 
84  return( value );
85  }
86 private:
88  double m_gamma;
89 };
90 
91 }
92 #endif