PaGMO  1.1.5
spheres.h
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 #ifndef PAGMO_SPHERES_H
26 #define PAGMO_SPHERES_H
27 
28 #include <string>
29 #include <vector>
30 #include <gsl/gsl_odeiv2.h>
31 
32 #include "../config.h"
33 #include "../serialization.h"
34 #include "../types.h"
35 #include "base_stochastic.h"
36 #include "../rng.h"
37 
38 namespace pagmo { namespace problem {
39 
41 
70 class __PAGMO_VISIBLE spheres: public base_stochastic
71 {
72  static int ode_func( double t, const double y[], double f[], void *params );
73  public:
75 
88  spheres(int n_evaluations = 10, int n_hidden = 10, double ode_prec = 1E-6, unsigned int seed = 0, bool symmetric = false, double sim_time = 50.0, const std::vector<double>& sides = std::vector<double>(3,0.5));
89 
91 
94  spheres(const spheres &);
95 
97 
100  ~spheres();
101 
103 
112  std::vector<std::vector<double> > post_evaluate(const decision_vector &x, int N = 25000, unsigned int seed = 0) const;
113 
115 
123  std::vector<std::vector<double> > simulate(const decision_vector & x, const std::vector<double> &ic, int N) const;
124  std::string get_name() const;
125  base_ptr clone() const;
126 
128  std::vector<double> get_nn_weights(decision_vector x) const;
129 
130  protected:
131  void objfun_impl(fitness_vector &, const decision_vector &) const;
132  std::string human_readable_extra() const;
133  private:
134  // Class representing a feed forward neural network
135  class ffnn {
136  friend class spheres;
137  public:
138  ffnn(const unsigned int, const unsigned int,const unsigned int);
139  void eval(double[], const double[]) const;
140  void set_weights(const std::vector<double> &);
141  private:
142  friend class boost::serialization::access;
143  template <class Archive>
144  void serialize(Archive &ar, const unsigned int)
145  {
146  ar & const_cast<unsigned int &>(m_n_inputs);
147  ar & const_cast<unsigned int &>(m_n_hidden);
148  ar & const_cast<unsigned int &>(m_n_outputs);
149  ar & m_weights;
150  ar & m_hidden;
151  }
152  const unsigned int m_n_inputs;
153  const unsigned int m_n_hidden;
154  const unsigned int m_n_outputs;
155  std::vector<double> m_weights;
156  mutable std::vector<double> m_hidden;
157  };
158  void set_nn_weights(const decision_vector& x) const;
159  double single_fitness( const std::vector<double> &, const ffnn& ) const;
160  friend class boost::serialization::access;
161  template <class Archive>
162  void serialize(Archive &ar, const unsigned int)
163  {
164  ar & boost::serialization::base_object<base_stochastic>(*this);
165  ar & m_ffnn;
166  ar & m_n_evaluations;
167  ar & m_n_hidden_neurons;
168  ar & const_cast<double &>(m_numerical_precision);
169  ar & m_ic;
170  ar & m_symm;
171  ar & m_sim_time;
172  ar & m_sides;
173  }
174  gsl_odeiv2_driver* m_gsl_drv_pntr;
175  gsl_odeiv2_system m_sys;
176  mutable ffnn m_ffnn;
177  int m_n_evaluations;
178  int m_n_hidden_neurons;
179  const double m_numerical_precision;
180  mutable std::vector<double> m_ic;
181  bool m_symm;
182  double m_sim_time;
183  std::vector<double> m_sides;
184 };
185 
186 }} //namespaces
187 
188 BOOST_CLASS_EXPORT_KEY(pagmo::problem::spheres)
189 #endif // PAGMO_SPHERES_H
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
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
Base Stochastic Optimization Problem.
Evolutionary Neuro-Controller for the MIT Spheres (perception-action defined in the absolute frame) ...
Definition: spheres.h:70