PaGMO  1.1.5
luksan_vlcek_3.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/integer_traits.hpp>
26 #include <cmath>
27 #include <stdexcept>
28 #include <string>
29 #include <vector>
30 
31 #include "../exceptions.h"
32 #include "../types.h"
33 #include "base.h"
34 #include "luksan_vlcek_3.h"
35 
36 static int __check__(int N){
37  if (N < 8 || (N) % 4)
38  {
39  pagmo_throw(value_error,"problem dimension N needs to be at least 8 and a multiple of 4");
40  }
41  return N;
42 }
43 
44 namespace pagmo { namespace problem {
45 
47 
60 luksan_vlcek_3::luksan_vlcek_3(int N, const double &clb, const double &cub):base(__check__(N), 0, 1, 2 * 2, 2 * 2, 1e-14)
61 {
62  if (clb > cub)
63  {
64  pagmo_throw(value_error,"constraints lower bound is higher than the upper bound");
65  }
66  set_lb(-5);
67  set_ub(5);
68  m_clb = std::vector<double>(2,clb);
69  m_cub = std::vector<double>(2,cub);
70 }
71 
74 {
75  return base_ptr(new luksan_vlcek_3(*this));
76 }
77 
80 {
81  f[0] = 0.;
82  for (decision_vector::size_type i=0; i<(x.size()-2)/2; i++)
83  {
84  double a1 = x[2*i]+10.*x[2*i+1];
85  double a2 = x[2*i+2] - x[2*i+3];
86  double a3 = x[2*i+1] - 2.*x[2*i+2];
87  double a4 = x[2*i] - x[2*i+3];
88  f[0] += a1*a1 + 5.*a2*a2 + std::pow(a3,4)+ 10.*std::pow(a4,4);
89  }
90 
91 }
94 {
95  int n = x.size();
96  c[0] = 3.*std::pow(x[0],3) + 2.*x[1] - 5. + std::sin(x[0]-x[1])*std::sin(x[0]+x[1]) - m_cub[0];
97  c[1] = m_clb[0] - ( 3.*std::pow(x[0],3) + 2.*x[1] - 5. + std::sin(x[0]-x[1])*std::sin(x[0]+x[1]) );
98  c[2] = 4.*x[n-3] - x[n-4]*std::exp(x[n-4]-x[n-3]) - 3 - m_cub[1];
99  c[3] = m_clb[1] - ( 4.*x[n-3] - x[n-4]*std::exp(x[n-4]-x[n-3]) - 3 );
100 }
101 
103 void luksan_vlcek_3::set_sparsity(int &lenG, std::vector<int> &iGfun, std::vector<int> &jGvar) const
104 {
105  //Initial point
107  //Numerical procedure
108  estimate_sparsity(x0, lenG, iGfun, jGvar);
109 }
110 
111 std::string luksan_vlcek_3::get_name() const
112 {
113  return "Luksan-Vlcek 3";
114 }
115 
116 }}
117 
118 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::luksan_vlcek_3)
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
void set_sparsity(int &, std::vector< int > &, std::vector< int > &) const
Implementation of the sparsity structure.
Base problem class.
Definition: problem/base.h:148
size_type get_dimension() const
Return global dimension.
void set_lb(const decision_vector &)
Set lower bounds from pagmo::decision_vector.
std::string get_name() const
Get problem's name.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of the constraint function.
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
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
void estimate_sparsity(const decision_vector &, int &lenG, std::vector< int > &iGfun, std::vector< int > &jGvar) const
Heuristics to estimate the sparsity pattern of the problem.
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
Test problem from the Luksan and Vlcek book.
luksan_vlcek_3(int=8, const double &=0, const double &=0)
Constructor.
base_ptr clone() const
Clone method.