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