def _get_penalty_data_part(self,x): from PyKEP import epoch, lambert_problem, DAY2SEC, fb_prop, propagate_lagrangian from math import pi, acos,cos,sin,sqrt from scipy.linalg import norm from copy import deepcopy from _mass_penalty import get_rp_ra_Trev import numpy as np """ This method returns the data needed to compute the score of a trajectory. """ Trajectory = []; #1 - we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience T = x[3::4] nlegs = len(x)/4 seq = self.get_sequence() common_mu = seq[0].mu_central_body t0 = self.t0.mjd2000 vinf_in = deepcopy(self.vinf_in) #2 - We compute the epochs and ephemerides of the planetary encounters ep_list = list([None] * (nlegs+1)) t_P = list([None] * (nlegs+1)) r_P = list([None] * (nlegs+1)) v_P = list([None] * (nlegs+1)) DV = list([None] * nlegs) for i,planet in enumerate(seq): ep_list[i] = t0+sum(T[:i]) t_P[i] = epoch(t0+sum(T[:i])) r_P[i],v_P[i] = seq[i].eph(t_P[i]) v_end_l = [a+b for a,b in zip(vinf_in, v_P[0])] #3 - And we proceed with each successive leg for i in xrange(nlegs): #Fly-by v_out = fb_prop(v_end_l,v_P[i],x[1+4*i]*seq[i].radius,x[4*i],seq[i].mu_self) #s/c propagation before the DSM r,v = propagate_lagrangian(r_P[i],v_out,x[4*i+2]*T[i]*DAY2SEC,common_mu) # append r, v, etc. to the Trajectory: Tr = [r_P[i-1], v_out, r, v, x[4*i+2]*T[i]*DAY2SEC]; rPvec = np.asarray(r); vPvec = np.asarray(v); Tr = Tr + get_rp_ra_Trev(rPvec, vPvec); vinf = []; Tr = Tr + [vinf]; Trajectory.append(Tr); #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1-x[4*i+2])*T[i]*DAY2SEC l = lambert_problem(r,r_P[i+1],dt,common_mu, False, False) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # append r, v, etc. to the Trajectory: Tr = [r, v_beg_l, r_P[i], v_end_l, (1-x[4*i+2])*T[i]*DAY2SEC]; rPvec = np.asarray(r_P[i]); vPvec = np.asarray(v_end_l); Tr = Tr + get_rp_ra_Trev(rPvec, vPvec); vinf = vPvec - np.asarray(v_P[i]); Tr = Tr + [vinf]; Trajectory.append(Tr); return Trajectory;
def _get_penalty_data_part(self, x): from PyKEP import epoch, lambert_problem, DAY2SEC, fb_prop, propagate_lagrangian from math import pi, acos, cos, sin, sqrt from scipy.linalg import norm from copy import deepcopy from _mass_penalty import get_rp_ra_Trev import numpy as np """ This method returns the data needed to compute the score of a trajectory. """ Trajectory = [] #1 - we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience T = x[3::4] nlegs = len(x) / 4 seq = self.get_sequence() common_mu = seq[0].mu_central_body t0 = self.t0.mjd2000 vinf_in = deepcopy(self.vinf_in) #2 - We compute the epochs and ephemerides of the planetary encounters ep_list = list([None] * (nlegs + 1)) t_P = list([None] * (nlegs + 1)) r_P = list([None] * (nlegs + 1)) v_P = list([None] * (nlegs + 1)) DV = list([None] * nlegs) for i, planet in enumerate(seq): ep_list[i] = t0 + sum(T[:i]) t_P[i] = epoch(t0 + sum(T[:i])) r_P[i], v_P[i] = seq[i].eph(t_P[i]) v_end_l = [a + b for a, b in zip(vinf_in, v_P[0])] #3 - And we proceed with each successive leg for i in xrange(nlegs): #Fly-by v_out = fb_prop(v_end_l, v_P[i], x[1 + 4 * i] * seq[i].radius, x[4 * i], seq[i].mu_self) #s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu) # append r, v, etc. to the Trajectory: Tr = [r_P[i - 1], v_out, r, v, x[4 * i + 2] * T[i] * DAY2SEC] rPvec = np.asarray(r) vPvec = np.asarray(v) Tr = Tr + get_rp_ra_Trev(rPvec, vPvec) vinf = [] Tr = Tr + [vinf] Trajectory.append(Tr) #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, common_mu, False, False) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # append r, v, etc. to the Trajectory: Tr = [ r, v_beg_l, r_P[i], v_end_l, (1 - x[4 * i + 2]) * T[i] * DAY2SEC ] rPvec = np.asarray(r_P[i]) vPvec = np.asarray(v_end_l) Tr = Tr + get_rp_ra_Trev(rPvec, vPvec) vinf = vPvec - np.asarray(v_P[i]) Tr = Tr + [vinf] Trajectory.append(Tr) return Trajectory
def _get_penalty_data(self,x): """ getTrajectory takes a genome x, and returns a Trajectory variable that is a list of all r, v, and time of flights Trajectory = [[r0, v0_out, r1, v1_in, tof, rp, ra, Trev, vinf], [r1, v1_out, r2, v2_in, tof, rp, ra, Trev, vinf], [...]] tof in days """ from PyKEP import epoch, lambert_problem, propagate_lagrangian, fb_prop, DAY2SEC; from math import pi, acos, cos, sin; import numpy as np; from _mass_penalty import get_rp_ra_Trev Trajectory = []; #1 - we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience T = x[3::4] # reconstruct properties that are known in _mga_incipit: self.seq = self.get_sequence(); self.__n_legs = len(self.seq); self.common_mu = self.seq[0].mu_central_body #2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (self.__n_legs)) r_P = list([None] * (self.__n_legs)) v_P = list([None] * (self.__n_legs)) DV = list([None] * (self.__n_legs)) for i,planet in enumerate(self.seq): t_P[i] = epoch(x[0]+sum(T[:i+1])) r_P[i],v_P[i] = self.seq[i].eph(t_P[i]) #3 - We start with the first leg: a lambert arc theta = 2*pi*x[1] phi = acos(2*x[2]-1)-pi/2 r = [cos(phi)*sin(theta), cos(phi)*cos(theta), sin(phi)] #phi close to zero is in the moon orbit plane injection r = [JR*1000*d for d in r] l = lambert_problem(r,r_P[0],T[0]*DAY2SEC,self.common_mu, False, False) #Lambert arc to reach seq[1] v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] Tr = [tuple(r), v_beg_l, r_P[0], v_end_l, T[0]*DAY2SEC]; rPvec = np.asarray(r_P[0]); vPvec = np.asarray(v_end_l); Tr = Tr + get_rp_ra_Trev(rPvec, vPvec); vinf = vPvec - np.asarray(v_P[0]); Tr = Tr + [vinf]; Trajectory.append(Tr); #First DSM occuring at the very beginning (will be cancelled by the optimizer) DV[0] = abs(np.linalg.norm(v_beg_l) - 3400) #4 - And we proceed with each successive leg for i in xrange(1,self.__n_legs): #Fly-by v_out = fb_prop(v_end_l,v_P[i-1],x[1+4*i]*self.seq[i-1].radius,x[4*i],self.seq[i-1].mu_self) #s/c propagation before the DSM r,v = propagate_lagrangian(r_P[i-1],v_out,x[4*i+2]*T[i]*DAY2SEC,self.common_mu) # append r, v, etc. to the Trajectory: Tr = [r_P[i-1], v_out, r, v, x[4*i+2]*T[i]*DAY2SEC]; rPvec = np.asarray(r); vPvec = np.asarray(v); Tr = Tr + get_rp_ra_Trev(rPvec, vPvec); vinf = []; Tr = Tr + [vinf]; Trajectory.append(Tr); #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1-x[4*i+2])*T[i]*DAY2SEC l = lambert_problem(r,r_P[i],dt,self.common_mu, False, False) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # append r, v, etc. to the Trajectory: Tr = [r, v_beg_l, r_P[i], v_end_l, (1-x[4*i+2])*T[i]*DAY2SEC]; rPvec = np.asarray(r_P[i]); vPvec = np.asarray(v_end_l); Tr = Tr + get_rp_ra_Trev(rPvec, vPvec); vinf = vPvec - np.asarray(v_P[i]); Tr = Tr + [vinf]; Trajectory.append(Tr); #DSM occuring at time nu2*T2 DV[i] = np.linalg.norm([a-b for a,b in zip(v_beg_l,v)]) return Trajectory;
def _get_penalty_data(self, x): """ getTrajectory takes a genome x, and returns a Trajectory variable that is a list of all r, v, and time of flights Trajectory = [[r0, v0_out, r1, v1_in, tof, rp, ra, Trev, vinf], [r1, v1_out, r2, v2_in, tof, rp, ra, Trev, vinf], [...]] tof in days """ from PyKEP import epoch, lambert_problem, propagate_lagrangian, fb_prop, DAY2SEC from math import pi, acos, cos, sin import numpy as np from _mass_penalty import get_rp_ra_Trev Trajectory = [] #1 - we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience T = x[3::4] # reconstruct properties that are known in _mga_incipit: self.seq = self.get_sequence() self.__n_legs = len(self.seq) self.common_mu = self.seq[0].mu_central_body #2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (self.__n_legs)) r_P = list([None] * (self.__n_legs)) v_P = list([None] * (self.__n_legs)) DV = list([None] * (self.__n_legs)) for i, planet in enumerate(self.seq): t_P[i] = epoch(x[0] + sum(T[:i + 1])) r_P[i], v_P[i] = self.seq[i].eph(t_P[i]) #3 - We start with the first leg: a lambert arc theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 r = [cos(phi) * sin(theta), cos(phi) * cos(theta), sin(phi)] #phi close to zero is in the moon orbit plane injection r = [JR * 1000 * d for d in r] l = lambert_problem(r, r_P[0], T[0] * DAY2SEC, self.common_mu, False, False) #Lambert arc to reach seq[1] v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] Tr = [tuple(r), v_beg_l, r_P[0], v_end_l, T[0] * DAY2SEC] rPvec = np.asarray(r_P[0]) vPvec = np.asarray(v_end_l) Tr = Tr + get_rp_ra_Trev(rPvec, vPvec) vinf = vPvec - np.asarray(v_P[0]) Tr = Tr + [vinf] Trajectory.append(Tr) #First DSM occuring at the very beginning (will be cancelled by the optimizer) DV[0] = abs(np.linalg.norm(v_beg_l) - 3400) #4 - And we proceed with each successive leg for i in xrange(1, self.__n_legs): #Fly-by v_out = fb_prop(v_end_l, v_P[i - 1], x[1 + 4 * i] * self.seq[i - 1].radius, x[4 * i], self.seq[i - 1].mu_self) #s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i - 1], v_out, x[4 * i + 2] * T[i] * DAY2SEC, self.common_mu) # append r, v, etc. to the Trajectory: Tr = [r_P[i - 1], v_out, r, v, x[4 * i + 2] * T[i] * DAY2SEC] rPvec = np.asarray(r) vPvec = np.asarray(v) Tr = Tr + get_rp_ra_Trev(rPvec, vPvec) vinf = [] Tr = Tr + [vinf] Trajectory.append(Tr) #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i], dt, self.common_mu, False, False) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # append r, v, etc. to the Trajectory: Tr = [ r, v_beg_l, r_P[i], v_end_l, (1 - x[4 * i + 2]) * T[i] * DAY2SEC ] rPvec = np.asarray(r_P[i]) vPvec = np.asarray(v_end_l) Tr = Tr + get_rp_ra_Trev(rPvec, vPvec) vinf = vPvec - np.asarray(v_P[i]) Tr = Tr + [vinf] Trajectory.append(Tr) #DSM occuring at time nu2*T2 DV[i] = np.linalg.norm([a - b for a, b in zip(v_beg_l, v)]) return Trajectory