30 #include "Pl_Eph_An.h"
33 #include "PowSwingByInv.h"
34 #include "Astro_Functions.h"
35 #define MAX(a, b) (a > b ? a : b)
41 int MGA(vector<double> t,
52 const int n = problem.sequence.size();
53 const vector<int> sequence = problem.sequence;
54 const vector<int> rev_flag = problem.rev_flag;
55 customobject cust_obj = problem.asteroid;
68 double penalty[9] = {0,
80 double penalty_coeffs[9] = {0,
92 double Dum_Vec[3],Vin,Vout;
93 double V_Lamb[2][2][3],dot_prod;
94 double a,p,theta,alfa;
95 double DVrel, DVarr=0;
99 const double rp_target = problem.rp;
100 const double e_target = problem.e;
101 const double DVlaunch = problem.DVlaunch;
104 const double initial_mass = problem.mass;
106 const double Isp = problem.Isp;
107 const double g = 9.80665 / 1000.0;
118 int i_count, j_count, lw;
124 for ( i_count = 0; i_count < n; i_count++)
126 vec =
new double [3];
127 rec =
new double [3];
135 for (i_count = 0; i_count < n; i_count++)
138 if (sequence[i_count]<10)
139 Planet_Ephemerides_Analytical (T, sequence[i_count],
140 r[i_count], v[i_count]);
143 Custom_Eph(T+2451544.5, cust_obj.epoch, cust_obj.keplerian, r[i_count], v[i_count]);
147 vett(r[0], r[1], Dum_Vec);
150 lw = (rev_flag[0] == 0) ? 0 : 1;
152 lw = (rev_flag[0] == 0) ? 1 : 0;
154 LambertI(r[0],r[1],t[1]*24*60*60,MU[0],lw,
155 V_Lamb[0][0],V_Lamb[0][1],a,p,theta,iter);
156 DV[0] = norm(V_Lamb[0][0], v[0]);
158 for (i_count = 1; i_count <= n-2; i_count++)
160 vett(r[i_count], r[i_count+1], Dum_Vec);
163 lw = (rev_flag[i_count] == 0) ? 0 : 1;
165 lw = (rev_flag[i_count] == 0) ? 1 : 0;
168 LambertI(r[i_count],r[i_count+1],t[i_count + 1]*24*60*60,MU[0],lw,
169 V_Lamb[1][0],V_Lamb[1][1],a,p,theta,iter);
172 Vin = norm(V_Lamb[0][1], v[i_count]);
173 Vout = norm(V_Lamb[1][0], v[i_count]);
176 for (
int i = 0; i < 3; i++)
178 dot_prod += (V_Lamb[0][1][i] - v[i_count][i]) * (V_Lamb[1][0][i] - v[i_count][i]);
180 alfa = acos ( dot_prod /(Vin * Vout) );
183 PowSwingByInv(Vin, Vout, alfa, DV[i_count], rp[i_count - 1]);
185 rp[i_count - 1] *= MU[sequence[i_count]];
188 for (j_count = 0; j_count < 3; j_count++)
190 V_Lamb[0][0][j_count] = V_Lamb[1][0][j_count];
191 V_Lamb[0][1][j_count] = V_Lamb[1][1][j_count];
200 for (i_count = 0; i_count < 3; i_count++)
201 Dum_Vec[i_count] = v[n-1][i_count] - V_Lamb[1][1][i_count];
203 DVrel = norm2(Dum_Vec);
205 if (problem.type == total_DV_orbit_insertion){
207 DVper = sqrt(DVrel*DVrel + 2*MU[sequence[n-1]]/rp_target);
208 DVper2 = sqrt(2*MU[sequence[n-1]]/rp_target - MU[sequence[n-1]]/rp_target*(1-e_target));
209 DVarr = fabs(DVper - DVper2);
212 else if (problem.type == asteroid_impact){
221 for (i_count = 1; i_count < n-1; i_count++)
222 DVtot += DV[i_count];
224 if (problem.type == total_DV_orbit_insertion){
232 for (i_count = 0;i_count < n-2; i_count++)
233 if (rp[i_count] < penalty[sequence[i_count+1]])
234 DVtot += penalty_coeffs[sequence[i_count+1]]*fabs(rp[i_count] - penalty[sequence[i_count+1]]);
237 if (DV[0] > DVlaunch)
238 DVtot += (DV[0] - DVlaunch);
240 if (problem.type == total_DV_orbit_insertion){
245 else if (problem.type == asteroid_impact){
248 obj_funct = final_mass = initial_mass * exp(- DVtot/ (Isp * g));
251 for (i_count = 0; i_count < 3; i_count++)
252 Dum_Vec[i_count] = v[n-1][i_count] - V_Lamb[1][1][i_count];
255 for (i_count = 0; i_count < 3 ; i_count++)
256 dot_prod += Dum_Vec[i_count] * v[n-1][i_count];
258 obj_funct = - (final_mass)* fabs(dot_prod);
263 for ( i_count = 0;i_count < n;i_count++)
265 delete [] r[i_count];
266 delete [] v[i_count];