PaGMO  1.1.5
tsp_ds.h
1 /*****************************************************************************
2  * Copyright (C) 2004-2014 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_PROBLEM_TSP_DS_H
26 #define PAGMO_PROBLEM_TSP_DS_H
27 
28 #include <vector>
29 #include <string>
30 #include <keplerian_toolbox/planet/base.h>
31 #include <keplerian_toolbox/planet/jpl_low_precision.h>
32 #include <keplerian_toolbox/astro_constants.h>
33 
34 #include "../types.h"
35 #include "./base_tsp.h"
36 #include "../serialization.h"
37 
38 
39 namespace pagmo { namespace problem {
40 
42 
57 class __PAGMO_VISIBLE tsp_ds: public base_tsp
58 {
59  public:
60 
62  tsp_ds(
63  const std::vector<kep_toolbox::planet::planet_ptr>& planets = {kep_toolbox::planet::jpl_lp("venus").clone(), kep_toolbox::planet::jpl_lp("earth").clone(), kep_toolbox::planet::jpl_lp("mars").clone()},
64  const std::vector<double>& values = {1.,1.,1.},
65  const double max_DV = 30000,
66  const std::vector<double>& epochs = {1200, 1550, 1940},
67  const base_tsp::encoding_type & encoding = CITIES
68  );
69 
71  base_ptr clone() const;
72 
74  void find_subsequence(const decision_vector &, double &, double &, decision_vector::size_type &, decision_vector::size_type &, const bool = false) const;
75 
78  const std::vector<kep_toolbox::planet::planet_ptr>& get_planets() const;
79  const std::vector<double>& get_values() const;
80  double get_max_DV() const;
81  const decision_vector& get_epochs() const;
83 
86  std::string get_name() const;
87  std::string human_readable_extra() const;
88  double distance(decision_vector::size_type, decision_vector::size_type) const;
90 
91  private:
92  static boost::array<int, 2> compute_dimensions(decision_vector::size_type n_cities, base_tsp::encoding_type);
93  void check_weights(const std::vector<std::vector<double> >&) const;
94  size_t compute_idx(const size_t i, const size_t j, const size_t n) const;
95 
96  void objfun_impl(fitness_vector&, const decision_vector&) const;
97  void compute_constraints_impl(constraint_vector&, const decision_vector&) const;
98 
99  double three_impulses(double, double, double, double, double, double, double, double) const;
100  void precompute_ephemerides() const;
101  void compute_DVs(const decision_vector&, bool = false) const;
102  double distance_3_imp(const decision_vector::size_type, const decision_vector::size_type, const size_t) const;
103 
104  friend class boost::serialization::access;
105  template <class Archive>
106  void serialize(Archive &ar, const unsigned int)
107  {
108  ar & boost::serialization::base_object<base_tsp>(*this);
109  ar & const_cast<std::vector<kep_toolbox::planet::planet_ptr> &>(m_planets);
110  ar & const_cast<std::vector<double> &>(m_values);
111  ar & const_cast<double &>(m_max_DV);
112  ar & const_cast<std::vector<double> &>(m_epochs);
113  precompute_ephemerides();
114  }
115 
116  private:
117  const std::vector<kep_toolbox::planet::planet_ptr> m_planets;
118  const std::vector<double> m_values;
119  const double m_max_DV;
120  const decision_vector m_epochs;
121  const double m_mu;
122 
123  // These are to pre-allocate memory
124  mutable std::vector<double> m_DV;
125  mutable std::vector<std::vector<kep_toolbox::array3D> >m_eph_r;
126  mutable std::vector<std::vector<kep_toolbox::array3D> >m_eph_v;
127  mutable std::vector<std::vector<kep_toolbox::array6D> >m_eph_el;
128 };
129 
130 }} //namespaces
131 
132 BOOST_CLASS_EXPORT_KEY(pagmo::problem::tsp_ds)
133 
134 #endif //PAGMO_PROBLEM_TSP_DS_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
encoding_type
Mechanism used to encode the sequence of vertices to be visited.
Definition: base_tsp.h:68
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
Base TSP (Travelling Salesman Problem).
Definition: base_tsp.h:64
The TSP - Debris Selection Problem.
Definition: tsp_ds.h:57