30 #ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_MULTIOBJECTIVEBENCHMARK_H 31 #define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_MULTIOBJECTIVEBENCHMARK_H 45 template<
int...>
struct integer_sequence {
using type = integer_sequence; };
46 template<
typename T1,
typename T2>
struct integer_sequence_concat;
47 template<
int... I1,
int... I2>
struct integer_sequence_concat<integer_sequence<I1...>, integer_sequence<I2...>>: integer_sequence<I1..., (sizeof...(I1) + I2)...> {};
50 template<
int N>
struct generate_integer_sequence;
51 template<
int N>
struct generate_integer_sequence: integer_sequence_concat<typename generate_integer_sequence<N/2>::type, typename generate_integer_sequence<N-N/2>::type>::type {};
52 template <>
struct generate_integer_sequence<0>: integer_sequence<>{};
53 template <>
struct generate_integer_sequence<1>: integer_sequence<0>{};
69 template<
class ... Objectives>
73 m_features |= CAN_PROPOSE_STARTING_POINT;
74 m_features |= HAS_FIRST_DERIVATIVE;
75 setupRotations(
typename detail::generate_integer_sequence<
sizeof...(Objectives)>::type());
76 setNumberOfVariables(numVariables);
77 for(
auto& f: m_rotations){
79 if(!f.hasFirstDerivative())
80 m_features.reset(HAS_FIRST_DERIVATIVE);
89 return generateName(
typename detail::generate_integer_sequence<
sizeof...(Objectives)>::type());
98 for(
auto& f: m_rotations){
100 f.setNumberOfVariables(numberOfVariables);
105 return sizeof...(Objectives);
109 return get<0>().numberOfVariables();
113 typename std::tuple_element<N, std::tuple<Objectives...> >::type&
get(){
114 return std::get<N>(m_objectives);
117 typename std::tuple_element<N, std::tuple<Objectives...> >::type
const&
get()
const{
118 return std::get<N>(m_objectives);
123 m_translations.clear();
125 for(
auto& f: m_rotations)
127 RealVector translation(numberOfVariables());
128 for(
double& v: translation){
129 v=
random::gauss(*mep_rng, 0,1)/std::sqrt(
double(numberOfVariables()));
131 m_translations.push_back(translation);
138 RealVector x(numberOfVariables());
141 for (std::size_t i = 0; i < x.size(); i++) {
142 x(i) = m_translations[index](i)+
random::gauss(*mep_rng, 0,1)/std::sqrt(
double(numberOfVariables()));
149 m_evaluationCounter++;
152 for(std::size_t i = 0; i != value.size(); ++i){
153 value(i) = m_rotations[i].eval( x - m_translations[i]);
159 derivative.resize(numberOfObjectives(), numberOfVariables());
160 RealVector singleDerivative;
161 RealVector value(numberOfObjectives());
162 for(std::size_t i = 0; i != value.size(); ++i){
163 value(i) = m_rotations[i].evalDerivative( x - m_translations[i],singleDerivative);
164 noalias(row(derivative,i)) = singleDerivative;
172 void setupRotations(detail::integer_sequence<I...>){
177 std::string generateName(detail::integer_sequence<I...>)
const{
179 for(
auto const& fname:{std::get<I>(m_objectives).name()... }){
186 std::tuple<Objectives...> m_objectives;
187 std::vector<RotatedObjectiveFunction> m_rotations;
188 std::vector<RealVector> m_translations;