PaGMO  1.1.5
cassini_2.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 <string>
26 #include <keplerian_toolbox/epoch.h>
27 
28 #include "cassini_2.h"
29 #include "../AstroToolbox/mga_dsm.h"
30 #include "../AstroToolbox/misc4Tandem.h"
31 
32 
33 namespace pagmo { namespace problem {
34 
35 const int cassini_2::sequence[6] = {3, 2, 2, 3, 5, 6};
36 
38 
41 cassini_2::cassini_2():base(22), problem(total_DV_rndv,sequence,6,0,0,0,0,0)
42 {
43  const double lb[22] = {-1000, 3, 0, 0, 100, 100, 30, 400, 800, 0.01, 0.01, 0.01, 0.01, 0.01, 1.05, 1.05, 1.15, 1.7, -M_PI, -M_PI, -M_PI, -M_PI};
44  const double ub[22] = {0, 5, 1, 1, 400, 500, 300, 1600, 2200, 0.9, 0.9, 0.9, 0.9, 0.9, 6, 6, 6.5, 291, M_PI, M_PI, M_PI, M_PI};
45  set_bounds(lb,lb+22,ub,ub+22);
46 }
47 
50 {
51  return base_ptr(new cassini_2(*this));
52 }
53 
56 {
57  MGA_DSM(x, problem,f[0]);
58 }
59 
61 
69 std::string cassini_2::pretty(const std::vector<double> &x) const
70 {
71  double obj = 0;
72  MGA_DSM(x, problem, obj);
73  std::ostringstream s;
74  s.precision(15);
75  s << std::scientific;
76  const size_t seq_size = (x.size() + 2) / 4;
77  pagmo_assert((x.size() + 2) % 4 == 0 && seq_size >= 2);
78  pagmo_assert(problem.sequence.size() == seq_size);
79  s << "Flyby sequence:\t\t\t";
80  for (size_t i = 0; i < seq_size; ++i) {
81  s << problem.sequence[i];
82  }
83  s << '\n';
84  s << "Departure epoch (mjd2000):\t" << x[0] << '\n';
85  s << "Departure epoch:\t\t" << ::kep_toolbox::epoch(x[0],::kep_toolbox::epoch::MJD2000) << '\n';
86  s << "Vinf polar components:\t\t";
87  for (size_t i = 0; i < 3; ++i) {
88  s << x[i + 1] << ' ';
89  }
90  s << '\n';
91  double totaltime = 0;
92  for (size_t i = 0; i < seq_size - 1; ++i) {
93  s << "Leg time of flight:\t\t" << x[i + 4] << '\n';
94  totaltime += x[i + 4];
95  }
96  s << "Total time of flight:\t\t" << totaltime << '\n';
97  for (size_t i = 0; i < seq_size - 2; ++i) {
98  s << "Flyby radius:\t\t\t" << x[i + 2 * (seq_size + 1)] << '\n';
99  }
100  totaltime=x[0];
101  for (size_t i = 0; i < seq_size - 2; ++i) {
102  totaltime += x[i + 4];
103  s << "Flyby date:\t\t\t" << ::kep_toolbox::epoch(totaltime,::kep_toolbox::epoch::MJD2000) << '\n';
104  }
105  for (size_t i = 0; i < seq_size - 2; ++i) {
106  s << "Vinf at flyby:\t\t\t" << std::sqrt(problem.vrelin_vec[i]) << '\n';
107  }
108  for (size_t i = 0; i < seq_size - 1; ++i) {
109  s << "dsm" << i+1 << ":\t\t\t\t" << problem.DV[i+1] << '\n';
110  }
111  s << "Final DV:\t\t\t" << problem.DV.back() << '\n';
112  return s.str();
113 }
114 
116 
119 void cassini_2::set_sparsity(int &lenG, std::vector<int> &iGfun, std::vector<int> &jGvar) const
120 {
121  lenG=22;
122  iGfun.resize(22);
123  jGvar.resize(22);
124  for (int i = 0; i<lenG; ++i)
125  {
126  iGfun[i] = 0;
127  jGvar[i] = i;
128  }
129 }
130 
131 std::string cassini_2::get_name() const
132 {
133  return "Cassini 2";
134 }
135 
136 }} //namespaces
137 
138 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::cassini_2)
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
cassini_2()
Constructor.
Definition: cassini_2.cpp:41
base_ptr clone() const
Clone method.
Definition: cassini_2.cpp:49
Base problem class.
Definition: problem/base.h:148
std::string get_name() const
Get problem's name.
Definition: cassini_2.cpp:131
std::string pretty(const std::vector< double > &x) const
Outputs a stream with the trajectory data.
Definition: cassini_2.cpp:69
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
Cassini MGA-DSM Problem.
Definition: cassini_2.h:49
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
Definition: cassini_2.cpp:55
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
void set_sparsity(int &, std::vector< int > &, std::vector< int > &) const
Implementation of the sparsity structure. (just to check the method call ... it is only used in some ...
Definition: cassini_2.cpp:119