PaGMO  1.1.5
mga_dsm.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 MGA_DSM_H
26 #define MGA_DSM_H
27 
28 #include <vector>
29 #include "mga.h"
30 
31 class mgadsmproblem {
32 public:
33  mgadsmproblem():size(0),type(0),e(0),rp(0),AUdist(0),DVtotal(0),DVonboard(0) {};
34  mgadsmproblem(int t, const int *seq, const size_t &size_, const double &AUdist_, const double &DVtotal_, const double &DVonboard_,
35  const double &e_, const double &rp_):
36  size(size_),type(t),sequence(seq,seq + size),e(e_),rp(rp_),AUdist(AUdist_),DVtotal(DVtotal_),
37  DVonboard(DVonboard_),r(size),v(size),DV(size + 1),vrelin_vec(size-2) {
38  for (size_t i = 0; i < size; ++i) {
39  r[i] = new double[3];
40  v[i] = new double[3];
41  for (size_t j = 0; j < 3; ++j) {
42  r[i][j] = 0;
43  v[i][j] = 0;
44  }
45  }
46  }
47  mgadsmproblem(const mgadsmproblem &m):size(m.size),type(m.type),sequence(m.sequence),e(m.e),rp(m.rp),asteroid(m.asteroid),
48  AUdist(m.AUdist),DVtotal(m.DVtotal),DVonboard(m.DVonboard),r(m.size),v(m.size),DV(m.DV),vrelin_vec(m.vrelin_vec) {
49  for (size_t i = 0; i < size; ++i) {
50  r[i] = new double[3];
51  v[i] = new double[3];
52  for (size_t j = 0; j < 3; ++j) {
53  r[i][j] = m.r[i][j];
54  v[i][j] = m.v[i][j];
55  }
56  }
57  }
58  ~mgadsmproblem() {
59  for (size_t i = 0; i < size; ++i) {
60  delete[] r[i];
61  delete[] v[i];
62  }
63  }
64  const size_t size;
65  int type; //problem type
66  std::vector<int> sequence; //fly-by sequence (ex: 3,2,3,3,5,is Earth-Venus-Earth-Earth-Jupiter)
67  double e; //insertion e (only in case total_DV_orbit_insertion)
68  double rp; //insertion rp in km (only in case total_DV_orbit_insertion)
69  customobject asteroid; //asteroid data (in case fly-by sequence has a final number = 10)
70  double AUdist; //Distance to reach in AUs (only in case of time2AUs)
71  double DVtotal; //Total DV allowed in km/s (only in case of time2AUs)
72  double DVonboard; //Total DV on the spacecraft in km/s (only in case of time2AUs)
73 
74  //Pre-allocated memory, in order to remove allocation of heap space in MGA_DSM calls
75  mutable std::vector<double*> r; // = std::vector<double*>(n);
76  mutable std::vector<double*> v; // = std::vector<double*>(n);
77  mutable std::vector<double> DV; // = std::vector<double>(n+1);
78  mutable std::vector<double> vrelin_vec; // = std::vector<double>(n+1);
79 private:
80  friend class boost::serialization::access;
81  template<class Archive>
82  void serialize(Archive &ar, const unsigned int version) {
83  ar & const_cast<size_t &>(size);
84  ar & type;
85  ar & sequence;
86  ar & e;
87  ar & rp;
88  ar & asteroid;
89  ar & AUdist;
90  ar & DVtotal;
91  ar & DVonboard;
92  ar & DV;
93  ar & vrelin_vec;
94  boost::serialization::split_member(ar, *this, version); // spliting the serialization into save/load to handle "r" and "v" vectors of pointers
95  }
96  template<class Archive>
97  void save(Archive & ar, const unsigned int) const {
98  std::vector<std::vector<double> > r_values(size,std::vector<double>(3));
99  std::vector<std::vector<double> > v_values(size,std::vector<double>(3));
100  for (int i = 0; i < (int)size; ++i) {
101  for(int j = 0; j < 3; ++j){
102  r_values[(size_t)i][j] = r[i][j];
103  }
104  }
105  for (int i = 0; i < (int)size; ++i) {
106  for(int j = 0; j < 3; ++j){
107  v_values[(size_t)i][j] = v[i][j];
108  }
109  }
110  ar << static_cast<const std::vector<std::vector<double> > &>(r_values);
111  ar << static_cast<const std::vector<std::vector<double> > &>(v_values);
112  }
113  template<class Archive>
114  void load(Archive & ar, const unsigned int) {
115  std::vector<std::vector<double> > r_values;
116  std::vector<std::vector<double> > v_values;
117  ar >> r_values;
118  ar >> v_values;
119 
120  for (int i = 0; i < (int)size; ++i) {
121  for(int j = 0; j < 3; ++j){
122  r[(size_t)i][j] = r_values[i][j];
123  }
124  }
125  for (int i = 0; i < (int)size; ++i) {
126  for(int j = 0; j < 3; ++j){
127  v[(size_t)i][j] = v_values[i][j];
128  }
129  }
130  }
131 };
132 
133 
134 int MGA_DSM(
135  /* INPUT values: */
136  const std::vector<double> &x , // it is the decision vector
137  const mgadsmproblem &mgadsm, // contains the problem specific data
138 
139  /* OUTPUT values: */
140  double &J // J output
141  );
142 
143 #endif