PaGMO  1.1.5
luksan_vlcek_2.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 <stdexcept>
28 #include <string>
29 #include <vector>
30 
31 #include "../exceptions.h"
32 #include "../types.h"
33 #include "base.h"
34 #include "luksan_vlcek_2.h"
35 
36 static int __check__(int N){
37  if (N - 5 >= boost::integer_traits<int>::const_max / 2) {
38  pagmo_throw(std::overflow_error,"overflow error");
39  }
40  if (N<=15 || N % 2)
41  {
42  pagmo_throw(value_error,"problem dimension needs to be at least 16 and even");
43  }
44  return N;
45 }
46 
47 namespace pagmo { namespace problem {
48 
50 
62 luksan_vlcek_2::luksan_vlcek_2(int N, const double &clb, const double &cub):base(__check__(N), 0, 1, 2 * (__check__(N) - 9), 2 * (__check__(N) - 9), 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>(2*(N-9)),clb);
72  m_cub = decision_vector(boost::numeric_cast<decision_vector::size_type>(2*(N-9)),cub);
73 }
74 
77 {
78  return base_ptr(new luksan_vlcek_2(*this));
79 }
80 
83 {
84  f[0] = 0.;
85  for (decision_vector::size_type i=0; i < (x.size()-2)/2; i++)
86  {
87  double a1 = x[2*i]*x[2*i] - x[2*i+1];
88  double a2 = x[2*i] - 1.;
89  double a3 = x[2*i+2]*x[2*i+2] - x[2*i+3];
90  double a4 = x[2*i+2] - 1.;
91  double a5 = x[2*i+1] + x[2*i+3] - 2.;
92  double a6 = x[2*i+1] - x[2*i+3];
93  f[0] += 100.*a1*a1 + a2*a2 + 90.*a3*a3 + a4*a4 + 10.*a5*a5 + .1*a6*a6;
94  }
95 }
96 
99 {
100  for (decision_vector::size_type i=0; i < x.size()-9; i++)
101  {
102  c[2*i] = (2.+5.*x[i+5]*x[i+5])*x[i+5] + 1.;
103  for (decision_vector::size_type k = (i <= 5) ? 0 : i - 5; k<=i+1; k++) {
104  c[2*i] += x[k]*(x[k]+1.);
105  }
106  c[2*i] = c[2*i] - m_cub[i];
107  c[2*i+1] = (2.+5.*x[i+5]*x[i+5])*x[i+5] + 1.;
108  for (decision_vector::size_type k = (i <= 5) ? 0 : i - 5; k<=i+1; k++) {
109  c[2*i+1] += x[k]*(x[k]+1.);
110  }
111  c[2*i+1] = m_clb[i] - c[2*i+1];
112  }
113 }
114 
116 void luksan_vlcek_2::set_sparsity(int& lenG, std::vector<int>& iGfun, std::vector<int>& jGvar) const
117 {
118  //Initial point
120  //Numerical procedure
121  estimate_sparsity(x0, lenG, iGfun, jGvar);
122 }
123 
124 std::string luksan_vlcek_2::get_name() const
125 {
126  return "Luksan-Vlcek 2";
127 }
128 
129 }}
130 
131 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::luksan_vlcek_2)
Root PaGMO namespace.
luksan_vlcek_2(int=16, const double &=0, const double &=0)
Constructor.
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
std::string get_name() const
Get problem's name.
Base problem class.
Definition: problem/base.h:148
base_ptr clone() const
Clone method.
size_type get_dimension() const
Return global dimension.
void set_lb(const decision_vector &)
Set lower bounds from pagmo::decision_vector.
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective 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 compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of the constraint 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.
void set_sparsity(int &, std::vector< int > &, std::vector< int > &) const
Implementation of the sparsity structure: automated detection.