PaGMO  1.1.5
welded_beam.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 
27 #include "../exceptions.h"
28 #include "../types.h"
29 #include "base.h"
30 #include "welded_beam.h"
31 
32 static const std::vector<double> __constraint_tolerances__(int c_dimension, int ic_dimension)
33 {
34  std::vector<double> constraint_tolerances(c_dimension);
35  // equality constraints
36  for(int i=0; i<c_dimension-ic_dimension; i++) {
37  constraint_tolerances[i] = 0.0001;
38  }
39  // inequality constraints
40  for(int i=c_dimension-ic_dimension; i<c_dimension; i++) {
41  constraint_tolerances[i] = 0.;
42  }
43  return constraint_tolerances;
44 }
45 
46 namespace pagmo { namespace problem {
47 
49 
53 welded_beam::welded_beam():base(4,0,1,7,7,__constraint_tolerances__(7,7))
54 {
55  // initialize best solution
56  initialize_best();
57 
58  // set the bounds for the current problem
59  const double lb[] = {0.1,0.1,0.1,0.1};
60  const double ub[] = {2.,10.,10.,2.};
61  set_bounds(lb,ub);
62 }
63 
66 {
67  return base_ptr(new welded_beam(*this));
68 }
69 
72 {
73  /* objective function */
74  f[0] = 1.10471 * x[0]*x[0] * x[1] + 0.04811 * x[2] * x[3] * (14. + x[1]);
75 }
76 
79 {
80  double P = 6000.;
81  double L = 14.;
82  double E = 30e+6;
83  double G = 12e+6;
84  double t_max = 13600.;
85  double s_max = 30000.;
86  double d_max = 0.25;
87 
88  double M = P*(L + x[1] / 2.);
89  double R = std::sqrt(0.25 * (x[1]*x[1] + (x[0] + x[2]) * (x[0] + x[2])));
90  double J = 2. / std::sqrt(2.) * x[0] * x[1] * (x[1]*x[1] / 12. + 0.25 *
91  (x[0] + x[2])*(x[0] + x[2]));
92  double P_c = (4.013 * E / (6. * L*L)) * x[2] * x[3]*x[3]*x[3] *
93  (1 - 0.25 * x[2] * std::sqrt(E / G) / L);
94  double t1 = P / (std::sqrt(2.) * x[0] * x[1]);
95  double t2 = M * R / J;
96  double t = sqrt(t1*t1 + t1 * t2 * x[1] / R + t2*t2);
97  double s = 6. * P * L / (x[3] * x[2]*x[2]);
98  double d = 4. * P * L*L*L / (E*x[3] * x[2]*x[2]*x[2]);
99 
100  c[0] = t - t_max;
101  c[1] = s - s_max;
102  c[2] = x[0] - x[3];
103  c[3] = 0.10471 * x[0]*x[0] + 0.04811 * x[2] * x[3] * (14.0 + x[1]) - 5.0;
104  c[4] = 0.125 - x[0];
105  c[5] = d - d_max;
106  c[6] = P - P_c;
107 }
108 
109 std::string welded_beam::get_name() const
110 {
111  std::string retval("Welded beam");
112  return retval;
113 }
114 
115 void welded_beam::initialize_best(void)
116 {
117  std::vector<decision_vector> best_x;
118 
119  int x_dimension = 4;
120  // Coello and Montes
121  const double x_vector[] = {0.202369, 3.544214, 9.048210, 0.205723};
122 
123  decision_vector x(x_dimension);
124  std::copy(x_vector,x_vector + x_dimension,x.begin());
125  best_x.push_back(x);
126 
127  set_best_x(best_x);
128 }
129 
130 }} //namespaces
131 
132 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::welded_beam)
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_best_x(const std::vector< decision_vector > &)
Sets the best known decision vectors.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of the constraint function.
Definition: welded_beam.cpp:78
Base problem class.
Definition: problem/base.h:148
std::string get_name() const
Get problem's name.
base_ptr clone() const
Clone method.
Definition: welded_beam.cpp:65
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
Definition: welded_beam.cpp:71
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
The welded beam design problem: Constrained Real-Parameter Optimization.
Definition: welded_beam.h:45
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.