PaGMO  1.1.5
normalized.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 "base.h"
31 #include "normalized.h"
32 
33 namespace pagmo { namespace problem {
34 
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_normalization_center(p.get_dimension(),0),
53  m_normalization_scale(p.get_dimension(),0)
54 {
55  configure_new_bounds();
56 }
57 
60 {
61  return base_ptr(new normalized(*this));
62 }
63 
65 void normalized::configure_new_bounds()
66 {
67  for(base::size_type i = 0; i < get_lb().size(); ++i){
68  double center = (m_original_problem->get_ub()[i] + m_original_problem->get_lb()[i]) / 2;
69  double spread = m_original_problem->get_ub()[i] - m_original_problem->get_lb()[i];
70  m_normalization_center[i] = center; // Center to origin
71  m_normalization_scale[i] = spread/2; // Scale to [-1, 1] centered at origin
72  }
73  set_bounds(-1, 1);
74 }
75 
78 {
79  decision_vector retval(x.size(), 0);
80  for(base::size_type i = 0; i < x.size(); ++i){
81  retval[i] = (x[i] * m_normalization_scale[i]) + m_normalization_center[i];
82  }
83  return retval;
84 }
85 
89 {
90  decision_vector x_original = denormalize(x);
91  m_original_problem->objfun(f, x_original);
92 }
93 
97 {
98  decision_vector x_original = denormalize(x);
99  m_original_problem->compute_constraints(c, x_original);
100 }
101 
102 
103 std::string normalized::get_name() const
104 {
105  return m_original_problem->get_name() + " [Normalized]";
106 }
107 
109 {
110  std::ostringstream oss;
111  oss << m_original_problem->human_readable_extra() << std::endl;
112  return oss.str();
113 }
114 }}
115 
116 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::normalized)
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
Definition: normalized.cpp:88
base_ptr clone() const
Clone method.
Definition: normalized.cpp:59
Base problem class.
Definition: problem/base.h:148
decision_vector denormalize(const decision_vector &) const
Returns the de-normalized version of the decision variables.
Definition: normalized.cpp:77
Meta=problems base class.
Definition: base_meta.h:50
normalized(const base &=ackley(1))
Definition: normalized.cpp:43
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 compute_constraints_impl(constraint_vector &, const decision_vector &) const
Definition: normalized.cpp:96
std::string get_name() const
Get problem's name.
Definition: normalized.cpp:103
const decision_vector & get_lb() const
Lower bounds getter.
std::string human_readable_extra() const
Extra information in human readable format.
Definition: normalized.cpp:108
Normalized meta-problem.
Definition: normalized.h:45
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.
Definition: problem/base.h:160
base_ptr m_original_problem
Smart pointer to the original problem instance.
Definition: base_meta.h:80