Example #1
0
def _get_penalty_leg(r0, v0_in, v0_out, r1, v1_in, tof, rp, ra, Trev, vinf, verbose=True):
	"""	Get penalty for a single leg
	
		Add a penalty:
		(a) at the first fly-by, if v_in and v_out make it a local minimum (undifferentiable or when r0 is exactly at periapsis)
		(b) at each local minimum in the case of multiple revolutions
		(c) when in the remaining trajectory the closest distance is smaller than r0 and r1
	"""
	
	penalty = 0;
	eps = 1E-5;
	
	v = np.linalg.norm(v0_out);
	ri = np.linalg.norm(r0);
	
	# (a) at the first fly-by, if v_in and v_out make it a local minimum
	if(v0_in != []):
		[local_minimum, dp_in, dp_out] = _flyby_is_local_minimum(v0_in, v0_out, r0);
		if(local_minimum):
			# undifferentiable local minimum:
			penalty += _calculate_single_penalty(ri, ra);
			if verbose:
				print 'Undifferentiable minimum'
		elif(np.abs(dp_in) < eps and np.abs(dp_out) < eps and np.abs(r0 - rp) < eps):
			# we assume to be at the periapsis:
			penalty += _calculate_single_penalty(rp, ra);
			if verbose:
				print 'At periapsis'
		
	
	
	# (b) at each local minimum in the case of multiple revolutions
	# get vector norms:
	energy = 0.5*(v*v) - gt6.MU_JUPITER / ri;
	a = -gt6.MU_JUPITER / (2*energy);
	# look at the trajectory after r0:
	if(a > 0):
		# number of full revolutions:
		# print 'TOF = %f, Trev = %f' % (tof, Trev)
		n_full_revs = math.floor(tof / Trev);
		penalty += n_full_revs * _calculate_single_penalty(rp, ra);
		#if(n_full_revs > 0):
		#	print '%d revs * %f penalty' % (n_full_revs,  _calculate_single_penalty(rp, ra))
	# very hypothetical case that we do exactly n_full_revs:
	rf = np.linalg.norm(r1);
	if(rf == rp):
		penalty -= _calculate_single_penalty(rp, ra);
		
	# (c) when in the remaining trajectory the closest distance is smaller than r0 and r1
	[cd, ra] = closest_distance(list(r0),list(v0_out),list(r1),list(v1_in), gt6.MU_JUPITER);
	if(cd < ri and cd < rf):
		penalty += _calculate_single_penalty(cd, ra);
	
	if(penalty < 0):
		print 'Negative penalty?'
		pdb.set_trace();
	
	return penalty;
	def _objfun_impl(self,x):
		#1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
		T = list([0]*(self.__n_legs))

		#sum_alpha = 0
		#for i in range(self.__n_legs-1):
		#	sum_alpha = sum_alpha+x[4+4*i]

		#for i in xrange(self.__n_legs-1):
		#	T[i] = (x[4+4*i]/sum_alpha)*x[3]


		for i in xrange(0,self.__n_legs):
			T[i] = (x[4+4*i]/sum(x[4::4]))*x[3]

		

		#print "\tDuration: " + str(T) + "days"
		#return(T,)

		#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]

		#First DSM occuring at the very beginning (will be cancelled by the optimizer)
		DV[0] = abs(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[6+(i-1)*4]*self.seq[i-1].radius,x[5+(i-1)*4],self.seq[i-1].mu_self)
			#s/c propagation before the DSM
			r,v = propagate_lagrangian(r_P[i-1],v_out,x[7+(i-1)*4]*T[i]*DAY2SEC,self.common_mu)
			#Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
			dt = (1-x[7+(i-1)*4])*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]
			tmp2, ra2 = closest_distance(r,v_beg_l, r_P[i], v_end_l, self.common_mu)
			if tmp < tmp2:
				close_d[i] = tmp/JR
				ra = ra/JR
			else:
				close_d[i] = tmp2/JR
				ra = ra2/JR
			#DSM occuring at time nu2*T2
			DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])


		coeff = 0.3
		for i in xrange(0,self.__n_legs):
			ratio[i] = (DV[i]/(T[i]*DAY2SEC))
			DV_2rj[i] = DV[i] + max((2.0-close_d[i]),0.0)*1000 + max((ratio[i]-coeff*(0.1/2000)),0.0)*100
			T_2rj[i] = T[i] + max((2.0-close_d[i]),0.0)*1000 + max((ratio[i]-coeff*(0.1/2000)),0.0)*100

		#if self.f_dimension == 1:
		#	return (sum(DV)
		#else:
		#	return (sum(DV), sum(T)) 

		if self.f_dimension == 1:
			return (sum(DV_2rj))
		else:
			return (sum(DV_2rj), sum(T_2rj)) 
	def stats(self,x):
		import matplotlib as mpl
		import matplotlib.pyplot as plt

		#1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
		T = list([0]*(self.__n_legs))

		for i in xrange(self.__n_legs):
			T[i] = (x[4+4*i]/sum(x[4::4]))*x[3]

		#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))
		close_d = 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]
		close_d[0] = closest_distance(r,v_beg_l, r_P[0], v_end_l, self.common_mu)[0] / JR

		#First DSM occuring at the very beginning (will be cancelled by the optimizer)
		DV[0] = abs(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[6+(i-1)*4]*self.seq[i-1].radius,x[5+(i-1)*4],self.seq[i-1].mu_self)
			#s/c propagation before the DSM
			r,v = propagate_lagrangian(r_P[i-1],v_out,x[7+(i-1)*4]*T[i]*DAY2SEC,self.common_mu)
			tmp, ra = closest_distance(r_P[i-1],v_out, r,v, self.common_mu)
			#Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
			dt = (1-x[7+(i-1)*4])*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]
			tmp2, ra2 = closest_distance(r,v_beg_l, r_P[i], v_end_l, self.common_mu)
			if tmp < tmp2:
				close_d[i] = tmp/JR
				ra = ra/JR
			else:
				close_d[i] = tmp2/JR
				ra = ra2/JR
			#DSM occuring at time nu2*T2
			DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])


		#print "Total mission time (days): " + str(sum(T))
		#print "Total DV (m/s): " + str(sum(DV))

		symbol_dict = {
			'io' : 'yo',
			'europa' : 'bo',
			'ganymede' : 'ro',
			'callisto' : 'ko' }

		#for i in xrange(0,self.__n_legs):
		#	plt.plot(sum(DV), sum(T), symbol_dict[self.seq[0].name])

		#n = 0
		ratio = list([0]*(self.__n_legs))
		coeff = 0.3
		for i in xrange(0,self.__n_legs):
			ratio[i] = (DV[i]/(T[i]*DAY2SEC))

		if close_d[0] >= 2:
			if close_d[1] >= 2:
				if close_d[2] >= 2:
					if close_d[3] >= 2:
						if ratio[1] <= coeff*(0.1/2000):
							if ratio[2] <= coeff*(0.1/2000):
								if ratio[3] <= coeff*(0.1/2000):
									if ratio[0] <= coeff*(0.1/2000):
										plt.plot(sum(DV), sum(T), symbol_dict[self.seq[0].name])

		#for i in xrange(0,self.__n_legs):
		#	if close_d[i] > 2:
		#		plt.plot(sum(DV), sum(T), symbol_dict[self.seq[0].name])
		#	else:
		#		print "\n the closest distance is less than 2*Rj " 
		#print "\n number of sequences that do not crash " + str(n) 
		plt.show()
	def pretty(self,x):
		"""
		Prints human readable information on the trajectory represented by the decision vector x
		
		Example::
		
		  prob.pretty(x)
		"""

		#1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
		T = list([0]*(self.__n_legs))

		for i in xrange(self.__n_legs):
			T[i] = (x[4+4*i]/sum(x[4::4]))*x[3]

		#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))
		close_d = 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]
		close_d[0] = closest_distance(r,v_beg_l, r_P[0], v_end_l, self.common_mu)[0] / JR

		#First DSM occuring at the very beginning (will be cancelled by the optimizer)
		DV[0] = abs(norm(v_beg_l) - 3400)

		print "\nFirst Leg: 1000JR to " + self.seq[0].name 
		print "\tDeparture: " + str(t_P[0]) + " (" + str(t_P[0].mjd2000) + " mjd2000) " 
		print "\tDuration: " + str(T[0]) + "days"
		print "\tInitial Velocity Increment (m/s): " + str(DV[0])
		print "\tArrival relative velocity at " + self.seq[0].name +" (m/s): " + str(norm([a-b for a,b in zip(v_end_l,v_P[0])]))
		print "\tClosest approach distance: " + str(close_d[0])

		#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[6+(i-1)*4]*self.seq[i-1].radius,x[5+(i-1)*4],self.seq[i-1].mu_self)
			#s/c propagation before the DSM
			r,v = propagate_lagrangian(r_P[i-1],v_out,x[7+(i-1)*4]*T[i]*DAY2SEC,self.common_mu)
			tmp, ra = closest_distance(r_P[i-1],v_out, r,v, self.common_mu)
			#Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
			dt = (1-x[7+(i-1)*4])*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]
			tmp2, ra2 = closest_distance(r,v_beg_l, r_P[i], v_end_l, self.common_mu)
			if tmp < tmp2:
				close_d[i] = tmp/JR
				ra = ra/JR
			else:
				close_d[i] = tmp2/JR
				ra = ra2/JR
			#DSM occuring at time nu2*T2
			DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])

			print "\nleg no. " + str(i+1) + ": " + self.seq[i-1].name + " to " + self.seq[i].name 
			print "\tDuration (days): " + str(T[i])
			print "\tFly-by epoch: " + str(t_P[i]) + " (" + str(t_P[i].mjd2000) + " mjd2000) " 
			print "\tFly-by altitude (km): " + str((x[6+(i-1)*4]*self.seq[i-1].radius-self.seq[i-1].radius)/1000)
			print "\tDSM after (days): " + str(x[7+(i-1)*4]*T[i])
			print "\tDSM magnitude (m/s): " + str(DV[i]) 
			print "\tClosest approach distance: " + str(close_d[i])
			print "\tApoapsis at closest distance: " + str(ra)
			print "\tV in (m/s): " + str(v_end_l)
			print "\tV out (m/s): " + str(v_out)
		
		
		print "\nArrival at " + self.seq[-1].name
		vel_inf = [a-b for a,b in zip(v_end_l,v_P[-1])]
		print "Arrival epoch: " + str(t_P[-1]) + " (" + str(t_P[-1].mjd2000) + " mjd2000) " 
		print "Arrival Vinf (m/s): " + vel_inf.__repr__() + " - " + str(norm(vel_inf))
		print "Total mission time (days): " + str(sum(T))
		print "Total DV (m/s): " + str(sum(DV))
Example #5
0
    def pretty(self, x):
        """
		Prints human readable information on the trajectory represented by the decision vector x
		
		Example::
		
		  prob.pretty(x)
		"""
        #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
        T = x[3::4]

        #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))
        close_d = 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]
        close_d[0] = closest_distance(r, v_beg_l, r_P[0], v_end_l,
                                      self.common_mu)[0] / JR

        #First DSM occuring at the very beginning (will be cancelled by the optimizer)
        DV[0] = abs(norm(v_beg_l) - 3400)

        print "\nFirst Leg: 1000JR to " + self.seq[0].name
        print "\tDeparture: " + str(t_P[0]) + " (" + str(
            t_P[0].mjd2000) + " mjd2000) "
        print "\tDuration: " + str(T[0]) + "days"
        print "\tInitial Velocity Increment (m/s): " + str(DV[0])
        print "\tArrival relative velocity at " + self.seq[
            0].name + " (m/s): " + str(
                norm([a - b for a, b in zip(v_end_l, v_P[0])]))
        print "\tClosest approach distance: " + str(close_d[0])

        #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)
            tmp, ra = closest_distance(r_P[i - 1], v_out, r, v, self.common_mu)
            #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]
            tmp2, ra2 = closest_distance(r, v_beg_l, r_P[i], v_end_l,
                                         self.common_mu)
            if tmp < tmp2:
                close_d[i] = tmp / JR
                ra = ra / JR
            else:
                close_d[i] = tmp2 / JR
                ra = ra2 / JR
            #DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
            print "\nleg no. " + str(i + 1) + ": " + self.seq[
                i - 1].name + " to " + self.seq[i].name
            print "\tDuration (days): " + str(T[i])
            print "\tFly-by epoch: " + str(t_P[i]) + " (" + str(
                t_P[i].mjd2000) + " mjd2000) "
            print "\tFly-by altitude (km): " + str(
                (x[4 * i + 1] * self.seq[i - 1].radius -
                 self.seq[i - 1].radius) / 1000)
            print "\tDSM after (days): " + str(x[4 * i + 2] * T[i])
            print "\tDSM magnitude (m/s): " + str(DV[i])
            print "\tClosest approach distance: " + str(close_d[i])
            print "\tApoapsis at closest distance: " + str(ra)

        print "\nArrival at " + self.seq[-1].name
        vel_inf = [a - b for a, b in zip(v_end_l, v_P[-1])]
        print "Arrival epoch: " + str(t_P[-1]) + " (" + str(
            t_P[-1].mjd2000) + " mjd2000) "
        print "Arrival Vinf (m/s): " + vel_inf.__repr__() + " - " + str(
            norm(vel_inf))
        print "Total mission time (days): " + str(sum(T))
Example #6
0
def lambertization(prob, x):
	""" Does all the lambert arc construction to get you DV and stuff """
	# get sequence
	try:
		seq = prob.seq
	except AttributeError:
		seq = prob.get_sequence()
	
	# get common mu
	try:
		common_mu = prob.common_mu
	except AttributeError:
		common_mu = seq[0].mu_central_body
	
	# number of legs
	n_legs = len(seq)
	
	# time of flights (days)
	T = x[3::4]
	
	# Epochs and Ephemerides of the planetary encounters
	t_P = list([None] * (n_legs))
	r_P = list([None] * (n_legs))
	v_P = list([None] * (n_legs))
	DV  = list([None] * (n_legs))
	close_d = list([None] * (n_legs))
		
	for i,planet in enumerate(seq):
		t_P[i] = epoch(x[0]+sum(T[:i+1]))
		r_P[i],v_P[i] = seq[i].eph(t_P[i])

	# Lambert arc to 1st leg
	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,common_mu, False, False)

	v_end_l = l.get_v2()[0]
	v_beg_l = l.get_v1()[0]
	close_d[0] = closest_distance(r,v_beg_l, r_P[0], v_end_l, common_mu)[0] / JR
	
	# save the initial conditions on 1000JR
	initial = ( [epoch(x[0]), t_P[0]], [r,r_P[0]], [v_beg_l, v_end_l] )
		
	# First DSM occuring at the very beginning (will be cancelled by the optimizer)
	DV[0] = abs(norm(v_beg_l) - 3400)
	
	# creating new lists
	v_sc = []

	# Proceed with succeeding legs
	for i in xrange(1, n_legs):
		# Fly-by 
		v_out = fb_prop(v_end_l,v_P[i-1],x[1+4*i]*seq[i-1].radius,x[4*i],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,common_mu)
		tmp, ra = closest_distance(r_P[i-1],v_out, r,v, common_mu)
		# 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,common_mu, False, False)
		v_end_l = l.get_v2()[0]
		v_beg_l = l.get_v1()[0]
		tmp2, ra2 = closest_distance(r,v_beg_l, r_P[i], v_end_l, common_mu)
		if tmp < tmp2:
			close_d[i] = tmp/JR
			ra = ra/JR
		else:
			close_d[i] = tmp2/JR
			ra = ra2/JR
		# DSM occuring at time nu2*T2
		DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])
		v_sc.append( (v_out, v_end_l) ) # v_inf_out, v_inf_in

	
	return seq, common_mu, n_legs, initial, T, t_P, r_P, v_sc, DV, close_d
Example #7
0
    def _objfun_impl(self, x):
        #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
        T = list([0] * (self.__n_legs))

        #sum_alpha = 0
        #for i in range(self.__n_legs-1):
        #	sum_alpha = sum_alpha+x[4+4*i]

        #for i in xrange(self.__n_legs-1):
        #	T[i] = (x[4+4*i]/sum_alpha)*x[3]

        for i in xrange(0, self.__n_legs):
            T[i] = (x[4 + 4 * i] / sum(x[4::4])) * x[3]

        #print "\tDuration: " + str(T) + "days"
        #return(T,)

        #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]

        #First DSM occuring at the very beginning (will be cancelled by the optimizer)
        DV[0] = abs(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[6 + (i - 1) * 4] * self.seq[i - 1].radius,
                            x[5 + (i - 1) * 4], self.seq[i - 1].mu_self)
            #s/c propagation before the DSM
            r, v = propagate_lagrangian(r_P[i - 1], v_out,
                                        x[7 + (i - 1) * 4] * T[i] * DAY2SEC,
                                        self.common_mu)
            #Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1 - x[7 + (i - 1) * 4]) * 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]
            tmp2, ra2 = closest_distance(r, v_beg_l, r_P[i], v_end_l,
                                         self.common_mu)
            if tmp < tmp2:
                close_d[i] = tmp / JR
                ra = ra / JR
            else:
                close_d[i] = tmp2 / JR
                ra = ra2 / JR
            #DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])

        coeff = 0.3
        for i in xrange(0, self.__n_legs):
            ratio[i] = (DV[i] / (T[i] * DAY2SEC))
            DV_2rj[i] = DV[i] + max((2.0 - close_d[i]), 0.0) * 1000 + max(
                (ratio[i] - coeff * (0.1 / 2000)), 0.0) * 100
            T_2rj[i] = T[i] + max((2.0 - close_d[i]), 0.0) * 1000 + max(
                (ratio[i] - coeff * (0.1 / 2000)), 0.0) * 100

        #if self.f_dimension == 1:
        #	return (sum(DV)
        #else:
        #	return (sum(DV), sum(T))

        if self.f_dimension == 1:
            return (sum(DV_2rj))
        else:
            return (sum(DV_2rj), sum(T_2rj))
Example #8
0
    def stats(self, x):
        import matplotlib as mpl
        import matplotlib.pyplot as plt

        #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
        T = list([0] * (self.__n_legs))

        for i in xrange(self.__n_legs):
            T[i] = (x[4 + 4 * i] / sum(x[4::4])) * x[3]

        #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))
        close_d = 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]
        close_d[0] = closest_distance(r, v_beg_l, r_P[0], v_end_l,
                                      self.common_mu)[0] / JR

        #First DSM occuring at the very beginning (will be cancelled by the optimizer)
        DV[0] = abs(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[6 + (i - 1) * 4] * self.seq[i - 1].radius,
                            x[5 + (i - 1) * 4], self.seq[i - 1].mu_self)
            #s/c propagation before the DSM
            r, v = propagate_lagrangian(r_P[i - 1], v_out,
                                        x[7 + (i - 1) * 4] * T[i] * DAY2SEC,
                                        self.common_mu)
            tmp, ra = closest_distance(r_P[i - 1], v_out, r, v, self.common_mu)
            #Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1 - x[7 + (i - 1) * 4]) * 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]
            tmp2, ra2 = closest_distance(r, v_beg_l, r_P[i], v_end_l,
                                         self.common_mu)
            if tmp < tmp2:
                close_d[i] = tmp / JR
                ra = ra / JR
            else:
                close_d[i] = tmp2 / JR
                ra = ra2 / JR
            #DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])

        #print "Total mission time (days): " + str(sum(T))
        #print "Total DV (m/s): " + str(sum(DV))

        symbol_dict = {
            'io': 'yo',
            'europa': 'bo',
            'ganymede': 'ro',
            'callisto': 'ko'
        }

        #for i in xrange(0,self.__n_legs):
        #	plt.plot(sum(DV), sum(T), symbol_dict[self.seq[0].name])

        #n = 0
        ratio = list([0] * (self.__n_legs))
        coeff = 0.3
        for i in xrange(0, self.__n_legs):
            ratio[i] = (DV[i] / (T[i] * DAY2SEC))

        if close_d[0] >= 2:
            if close_d[1] >= 2:
                if close_d[2] >= 2:
                    if close_d[3] >= 2:
                        if ratio[1] <= coeff * (0.1 / 2000):
                            if ratio[2] <= coeff * (0.1 / 2000):
                                if ratio[3] <= coeff * (0.1 / 2000):
                                    if ratio[0] <= coeff * (0.1 / 2000):
                                        plt.plot(sum(DV), sum(T),
                                                 symbol_dict[self.seq[0].name])

        #for i in xrange(0,self.__n_legs):
        #	if close_d[i] > 2:
        #		plt.plot(sum(DV), sum(T), symbol_dict[self.seq[0].name])
        #	else:
        #		print "\n the closest distance is less than 2*Rj "
        #print "\n number of sequences that do not crash " + str(n)
        plt.show()