PaGMO  1.1.5
pressure_vessel.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 "pressure_vessel.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 pressure_vessel::pressure_vessel():base(4,0,1,4,4,__constraint_tolerances__(4,4))
54 {
55  // initialize best solution
56  initialize_best();
57 
58  // set the bounds for the current problem
59  const double lb[] = {1.,1.,10.,10.};
60  const double ub[] = {99.,99.,200.,200.};
61  set_bounds(lb,ub);
62 }
63 
66 {
67  return base_ptr(new pressure_vessel(*this));
68 }
69 
72 {
73  /* objective function */
74  f[0] = 0.6224 * x[0] * x[2] * x[3] +
75  1.7781 * x[1] * x[2]*x[2] +
76  3.1661 * x[0]*x[0] * x[3] +
77  19.84 * x[0]*x[0] * x[2];
78 }
79 
82 {
83  /* constraints g<=0 */
84  c[0] = - x[0] + 0.0193 * x[2];
85  c[1] = - x[1] + 0.00954 * x[2];
86  c[2] = - boost::math::constants::pi<double>() * x[2]*x[2] * x[3] -
87  (4./3.) * boost::math::constants::pi<double>() * x[2]*x[2]*x[2] + 1296000.;
88  c[3] = x[3] - 240.;
89 }
90 
91 std::string pressure_vessel::get_name() const
92 {
93  std::string retval("Pressure vessel");
94  return retval;
95 }
96 
97 void pressure_vessel::initialize_best(void)
98 {
99  std::vector<decision_vector> best_x;
100 
101  int x_dimension = 4;
102  // Coello and Montes
103  const double x_vector[] = {0.812500, 0.437500, 42.097398, 176.654050};
104 
105  decision_vector x(x_dimension);
106  std::copy(x_vector,x_vector + x_dimension,x.begin());
107  best_x.push_back(x);
108 
109  set_best_x(best_x);
110 }
111 
112 }} //namespaces
113 
114 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::pressure_vessel)
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 objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
base_ptr clone() const
Clone method.
void set_best_x(const std::vector< decision_vector > &)
Sets the best known decision vectors.
Base problem class.
Definition: problem/base.h:148
std::string get_name() const
Get problem's name.
The pressure vessel design problem: Constrained Real-Parameter Optimization.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of the constraint function.
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
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.