PaGMO  1.1.5
levy5.cpp
1 /*****************************************************************************
2  * Copyright (C) 2004-2015 The PaGMO development team, *
3  * Advanced Concepts Team (ACT), European Space Agency (ESA) *
4  * *
5  * https://github.com/esa/pagmo *
6  * *
7  * act@esa.int *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  *****************************************************************************/
24 
25 #include <boost/math/constants/constants.hpp>
26 #include <cmath>
27 #include <string>
28 
29 #include "../exceptions.h"
30 #include "../types.h"
31 #include "base.h"
32 #include "levy5.h"
33 
34 namespace pagmo { namespace problem {
35 
37 
44 levy5::levy5(int n):base(n)
45 {
46  if (n < 2) {
47  pagmo_throw(value_error,"the Levy5 problem's dimension must be at least 2");
48  }
49  // Set bounds.
50  set_lb(-100);
51  set_ub(100);
52 }
53 
56 {
57  return base_ptr(new levy5(*this));
58 }
59 
62 {
63  pagmo_assert(f.size() == 1);
64  decision_vector::size_type n = x.size();
65  double isum = 0.0;
66  double jsum = 0.0;
67  f[0] = 0;
68 
69  for ( decision_vector::size_type j=0; j<n; j+=2 ) {
70  for ( int i=1; i<=5; i++ ) {
71  isum += (double)(i) * cos((double)(i-1)*x[j] + (double)(i));
72  jsum += (double)(i) * cos((double)(i+1)*x[j+1] + (double)(i));
73  }
74  }
75 
76  f[0] = isum*jsum;
77  for ( decision_vector::size_type j=0; j<n; j+=2 )
78  f[0] += pow(x[j] + 1.42513,2) + pow(x[j+1] + 0.80032,2);
79 
80 }
81 
82 std::string levy5::get_name() const
83 {
84  return "Levy5";
85 }
86 
87 }} //namespaces
88 
89 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::levy5)
Root PaGMO namespace.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
Definition: problem/base.h:62
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
The Levy5 problem.
Definition: levy5.h:56
base_ptr clone() const
Clone method.
Definition: levy5.cpp:55
Base problem class.
Definition: problem/base.h:148
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
Definition: levy5.cpp:61
void set_lb(const decision_vector &)
Set lower bounds from pagmo::decision_vector.
std::string get_name() const
Get problem's name.
Definition: levy5.cpp:82
levy5(int=2)
Constructor from dimension.
Definition: levy5.cpp:44
void set_ub(const decision_vector &)
Set upper bounds from pagmo::decision_vector.
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42