PaGMO  1.1.5
gtoc5_launch.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 
27 #include <boost/integer_traits.hpp>
28 #include <boost/math/constants/constants.hpp>
29 #include <boost/numeric/conversion/bounds.hpp>
30 #include <boost/numeric/conversion/cast.hpp>
31 #include <cmath>
32 #include <sstream>
33 #include <stdexcept>
34 #include <vector>
35 
36 #include "../exceptions.h"
37 #include "../types.h"
38 #include "base.h"
39 #include "gtoc5_launch.h"
40 #include <keplerian_toolbox/sims_flanagan/codings.h>
41 #include <keplerian_toolbox/astro_constants.h>
42 #include <keplerian_toolbox/planet/gtoc5.h>
43 
44 using namespace kep_toolbox;
45 using namespace kep_toolbox::sims_flanagan;
46 
47 namespace pagmo { namespace problem {
49 
50 gtoc5_launch::gtoc5_launch(int segments, int target, objective obj, const double &ctol) :
51  base(segments * 3 + 6, 0, 1, 7 + segments + 1, segments + 1,ctol),
52  m_n_segments(segments),m_earth(),m_target(target),m_obj(obj)
53 {
54  std::vector<double> lb_v(get_dimension());
55  std::vector<double> ub_v(get_dimension());
56 
57  // Start (MJD).
58  lb_v[0] = 57023;
59  ub_v[0] = 61041;
60 
61  // Leg duration in days
62  lb_v[1] = 30;
63  ub_v[1] = 365.25 * 3;
64 
65  // Final mass.
66  lb_v[2] = 500;
67  ub_v[2] = 4000;
68 
69  // Start Velocity
70  lb_v[3] = -5000;
71  lb_v[4] = -5000;
72  lb_v[5] = -5000;
73  ub_v[3] = 5000;
74  ub_v[4] = 5000;
75  ub_v[5] = 5000;
76 
77  // I Throttles
78  for (int i = 6; i < segments * 3 + 6; ++i)
79  {
80  lb_v[i] = -1;
81  ub_v[i] = 1;
82  }
83 
84  //Copying the lb,ub vector into the problems bounds
85  set_bounds(lb_v,ub_v);
86 
87  // Set GTOC5 spacecraft.
88  m_leg.set_spacecraft(kep_toolbox::sims_flanagan::spacecraft(4000,0.3,3000));
89 }
90 
93 {
94  return base_ptr(new gtoc5_launch(*this));
95 }
96 
99 {
100  if (m_obj == MASS) {
101  f[0] = -x[2] / m_leg.get_spacecraft().get_mass();
102  } else {
103  f[0] = x[1] / 365.25;
104  }
105 }
106 
109 {
110  using namespace kep_toolbox;
111  // 1 - We set the leg.
112  const epoch epoch_i(x[0],epoch::MJD), epoch_f(x[1] + x[0],epoch::MJD);
113  array3D v0, r0, vf, rf;
114  m_earth.eph(epoch_i,r0,v0);
115  m_target.eph(epoch_f,rf,vf);
116 
117  v0[0] += x[3];
118  v0[1] += x[4];
119  v0[2] += x[5];
120  m_leg.set_leg(epoch_i,sc_state(r0,v0,m_leg.get_spacecraft().get_mass()),x.begin() + 6, x.end(),epoch_f,sc_state(rf,vf,x[2]),ASTRO_MU_SUN);
121 
122  // We evaluate the state mismatch at the mid-point. And we use astronomical units to scale them
123  m_leg.get_mismatch_con(c.begin(), c.begin() + 7);
124  for (int i=0; i<3; ++i) c[i]/=ASTRO_AU;
125  for (int i=3; i<6; ++i) c[i]/=ASTRO_EARTH_VELOCITY;
126  c[6] /= m_leg.get_spacecraft().get_mass();
127  // We evaluate the constraints on the throttles writing on the 7th mismatch constrant (mass is off)
128  m_leg.get_throttles_con(c.begin() + 7, c.begin() + 7 + m_n_segments);
129  c[7 + m_n_segments] = (x[3]*x[3] + x[4]*x[4] + x[5]*x[5] - 25000000) / ASTRO_EARTH_VELOCITY / ASTRO_EARTH_VELOCITY;
130 }
131 
133 void gtoc5_launch::set_sparsity(int &lenG, std::vector<int> &iGfun, std::vector<int> &jGvar) const
134 {
135  //Initial point
137  for (pagmo::decision_vector::size_type i = 0; i<x0.size(); ++i)
138  {
139  x0[i] = get_lb()[i] + (get_ub()[i] - get_lb()[i]) / 3.12345;
140  }
141  //Numerical procedure
142  estimate_sparsity(x0, lenG, iGfun, jGvar);
143 }
144 
145 std::string gtoc5_launch::get_name() const
146 {
147  return "GTOC5 Launch phase";
148 }
149 
150 std::string gtoc5_launch::pretty(const decision_vector &x) const
151 {
152  using namespace kep_toolbox;
153  // 1 - We set the leg.
154  const epoch epoch_i(x[0],epoch::MJD), epoch_f(x[1] + x[0],epoch::MJD);
155  array3D v0, r0, vf, rf;
156  m_earth.eph(epoch_i,r0,v0);
157  m_target.eph(epoch_f,rf,vf);
158 
159  v0[0] += x[2];
160  v0[1] += x[3];
161  v0[2] += x[4];
162  m_leg.set_leg(epoch_i,sc_state(r0,v0,m_leg.get_spacecraft().get_mass()),x.begin() + 6, x.end(),epoch_f,sc_state(rf,vf,x[5]),ASTRO_MU_SUN);
163 
164  std::ostringstream oss;
165  oss << m_leg << '\n' << m_earth << '\n' << m_target << '\n';
166  return oss.str();
167 }
168 
169 }}
170 
171 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::gtoc5_launch);
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 set_sparsity(int &, std::vector< int > &, std::vector< int > &) const
Implementation of the sparsity structure: automated detection.
Base problem class.
Definition: problem/base.h:148
Launch phase of the GTOC5 roblem.
Definition: gtoc5_launch.h:48
std::string pretty(const decision_vector &) const
A nice string representation of a chromosome.
size_type get_dimension() const
Return global dimension.
gtoc5_launch(int=10, int=1, objective=MASS, const double &=1E-5)
Constructor.
base_ptr clone() const
Clone method.
Propellant mass used.
Definition: gtoc5_launch.h:53
std::string get_name() const
Get problem's name.
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
void estimate_sparsity(const decision_vector &, int &lenG, std::vector< int > &iGfun, std::vector< int > &jGvar) const
Heuristics to estimate the sparsity pattern of the problem.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of the constraint function.
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
const decision_vector & get_ub() const
Upper bounds getter.
objective
Objective function to be minimized.
Definition: gtoc5_launch.h:52
const decision_vector & get_lb() const
Lower bounds getter.
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.