PaGMO  1.1.5
mga_target_event.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 <boost/math/constants/constants.hpp>
27 #include <vector>
28 #include <numeric>
29 #include <cmath>
30 #include <boost/lexical_cast.hpp>
31 #include <keplerian_toolbox/core_functions/propagate_lagrangian.h>
32 #include <keplerian_toolbox/astro_constants.h>
33 #include <keplerian_toolbox/lambert_problem.h>
34 #include <keplerian_toolbox/core_functions/array3D_operations.h>
35 
36 #include "mga_target_event.h"
37 
38 
39 namespace pagmo { namespace problem {
40 
41 mga_target_event::mga_target_event(
42  const kep_toolbox::plantes::planet_ptr start,
43  const kep_toolbox::planet::planet_ptr end,
44  const kep_toolbox::epoch t_end,
45  double T_max,
46  bool discount_launcher
47  ):base(6), m_start(start), m_end(end), m_t_end(t_end), m_T_max(T_max), m_discount_launcher(discount_launcher)
48 {
49  // We check that all planets have equal central body
50  if (start->get_mu_central_body() != end->get_mu_central_body()) {
51  pagmo_throw(value_error,"The planets do not all have the same mu_central_body");
52  }
53 
54  // We check that T_max is positive
55  if (T_max <= 0) {
56  pagmo_throw(value_error,"T_max must be larger than zero");
57  }
58 
59  // Now setting the problem bounds
60  decision_vector lb(6,0.0), ub(6,1.0);
61  lb[0] = 1.; lb[5] = 1e-5;
62  ub[0] = T_max; ub[2] = 12000.0; ub[5] = 1-1e-5;
63 
64  set_bounds(lb,ub);
65 }
66 
68 mga_target_event::mga_target_event(const mga_target_event &p) : base(p.get_dimension()), m_t_end(p.m_t_end), m_T_max(p.m_T_max), m_discount_launcher(p.m_discount_launcher)
69 {
70  set_bounds(p.get_lb(),p.get_ub());
71  m_start = p.m_start->clone();
72  m_end = p.m_end->clone();
73 }
74 
77 {
78  return base_ptr(new mga_target_event(*this));
79 }
80 
83 {
84  //1 - we 'decode' the chromosome
85  double tw = x[0]*x[1]; //transforms the waiting time from a fraction to days
86 
87  //2 - We compute the epochs and ephemerides of the planetary encounters
88  kep_toolbox::epoch t0 = kep_toolbox::epoch(m_t_end.mjd2000() - x[0]); //epoch of departure
89  double tof = (x[0] - tw); //in days
90 //std::cout << "tof: " << tof << std::endl;
91  kep_toolbox::epoch t1 = kep_toolbox::epoch(t0.mjd2000() + tof); //epoch
92 
93  kep_toolbox::array3D r0,v0,r1,v1,v_inf_vett,v0_sc;
94  m_start->eph(t0,r0,v0);
95  m_end->eph(t1,r1,v1);
96 //std::cout << "r0: " << r0 << std::endl;
97 //std::cout << "v0: " << v0 << std::endl;
98 //std::cout << "r1: " << r1 << std::endl;
99 //std::cout << "v1: " << v1 << std::endl;
100 
101  //3 - We compute the absolute velocity at departure
102  double theta = 2*M_PI*x[3];
103  double phi = acos(2. * x[4]-1.) - M_PI / 2.;
104  v_inf_vett[0] = x[2]*cos(phi)*cos(theta);
105  v_inf_vett[1] = x[2]*cos(phi)*sin(theta);
106  v_inf_vett[2] = x[2]*sin(phi);
107  kep_toolbox::sum(v0_sc,v0,v_inf_vett);
108 
109 //std::cout << "v_inf_vett: " << v_inf_vett << std::endl;
110 //std::cout << "v_sc: " << v0_sc << std::endl;
111 //std::cout << "tof: " << tof << std::endl;
112 //std::cout << "x[5]: " << x[5] << std::endl;
113 //std::cout << "x: " << x << std::endl;
114 
115  //4 - And we propagate up to the DSM positon to then solve a Lambert problem
116  kep_toolbox::propagate_lagrangian(r0,v0_sc,tof*x[5]*ASTRO_DAY2SEC, ASTRO_MU_SUN);
117  kep_toolbox::lambert_problem l(r0,r1,tof*(1-x[5])*ASTRO_DAY2SEC,ASTRO_MU_SUN, false,0);
118 
119 //std::cout << "r0: " << r0 << std::endl;
120 //std::cout << "v0: " << v0_sc << std::endl;
121 
122  double DV1 = x[2];
123  kep_toolbox::array3D dv2,dv3;
124  kep_toolbox::diff(dv2,v0_sc,l.get_v1()[0]);
125  double DV2 = kep_toolbox::norm(dv2);
126  kep_toolbox::diff (dv3,v1,l.get_v2()[0]);
127  double DV3 = kep_toolbox::norm(dv3);
128  if (m_discount_launcher) {
129  DV1 = std::max(0.,DV1-6000.);
130  }
131  f[0] = DV1+DV2+DV3;
132 // std::cout << "DV1: " << DV1 << std::endl;
133 // std::cout << "DV2: " << DV2 << std::endl;
134 // std::cout << "DV3: " << DV3 << std::endl;
135 }
136 
137 std::string mga_target_event::get_name() const
138 {
139  return "MGA-Target-Event";
140 }
141 
142 
144 
149 {
150  std::ostringstream oss;
151  oss << "\n\tStart: " << m_start->get_name();
152  oss << "\n\tEnd: " + m_end->get_name();
153  oss << "\n\tFinal epoch: " << boost::lexical_cast<std::string>(m_t_end.mjd2000());
154  oss << "\n\tDiscount launcher dv?: " << (m_discount_launcher ? "True" : "False");
155  return oss.str();
156 }
157 
158 }} //namespaces
159 
160 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::mga_target_event)
161 
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
Implementation of the objective function.
base_ptr clone() const
Clone method.
Base problem class.
Definition: problem/base.h:148
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
const decision_vector & get_ub() const
Upper bounds getter.
std::string get_name() const
Get problem's name.
const decision_vector & get_lb() const
Lower bounds getter.
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
std::string human_readable_extra() const
Extra human readable info for the problem.