PaGMO  1.1.5
scaled.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 <cmath>
26 
27 #include "../exceptions.h"
28 #include "../types.h"
29 #include "../population.h"
30 #include "scaled.h"
31 
32 namespace pagmo { namespace problem {
33 
43 scaled::scaled(const base & p, const decision_vector & units):
44  base_meta(
45  p,
46  p.get_dimension(),
47  p.get_i_dimension(),
48  p.get_f_dimension(),
49  p.get_c_dimension(),
50  p.get_ic_dimension(),
51  p.get_c_tol()),
52  m_units(units)
53 {
54  if (units.size() != p.get_f_dimension()) {
55  pagmo_throw(value_error,"The size of the provided units vector does not match the fitness dimension of the provided problem");
56  }
57 }
58 
61 {
62  return base_ptr(new scaled(*this));
63 }
64 
71 {
72  fitness_vector retval(f);
73  for (fitness_vector::size_type i=0; i< f.size();++i) {
74  retval[i] *= m_units[i];
75  }
76  return retval;
77 }
78 
86  return m_units;
87 }
88 
91 {
92  m_original_problem->objfun(f, x);
93  for (fitness_vector::size_type i=0; i< f.size();++i) {
94  f[i] /= m_units[i];
95  }
96 
97 }
98 
101 {
102  m_original_problem->compute_constraints(c, x);
103 }
104 
105 
106 std::string scaled::get_name() const
107 {
108  return m_original_problem->get_name() + " [Scaled]";
109 }
110 
112 
115 std::string scaled::human_readable_extra() const
116 {
117  std::ostringstream oss;
118  oss << m_original_problem->human_readable_extra() << std::endl;
119  oss << "\n\tScaled units vector: " << m_units << std::endl;
120  return oss.str();
121 }
122 }}
123 
124 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::scaled)
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
scaled(const base &=ackley(1), const fitness_vector &units=std::vector< double >(1))
Definition: scaled.cpp:43
fitness_vector descale(const fitness_vector &) const
Definition: scaled.cpp:70
base_ptr clone() const
Clone method.
Definition: scaled.cpp:60
Base problem class.
Definition: problem/base.h:148
Meta=problems base class.
Definition: base_meta.h:50
std::string get_name() const
Get problem's name.
Definition: scaled.cpp:106
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
const fitness_vector & get_units() const
Definition: scaled.cpp:85
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of the constraints computation.
Definition: scaled.cpp:100
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
Definition: scaled.cpp:90
f_size_type get_f_dimension() const
Return fitness dimension.
std::string human_readable_extra() const
Extra human readable info for the problem.
Definition: scaled.cpp:115
Scaled meta-problem.
Definition: scaled.h:44
base_ptr m_original_problem
Smart pointer to the original problem instance.
Definition: base_meta.h:80