Esempio n. 1
0
def _mga_part_plot(self, x):
    """
	Plots the trajectory represented by the decision vector x
	
	Example::
	
	  prob.plot(x)
	"""
    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler
    from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC
    from math import pi, acos, cos, sin
    from scipy.linalg import norm

    mpl.rcParams["legend.fontsize"] = 10
    fig = plt.figure()
    ax = fig.gca(projection="3d", aspect="equal")
    ax.scatter(0, 0, 0, color="y")

    JR = 71492000.0
    legs = len(x) / 4
    seq = self.get_sequence()
    common_mu = seq[0].mu_central_body
    start_mjd2000 = self.t0.mjd2000

    # 1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
    T = x[3::4]

    # 2 - We compute the epochs and ephemerides of the planetary encounters
    t_P = list([None] * (legs + 1))
    r_P = list([None] * (legs + 1))
    v_P = list([None] * (legs + 1))

    for i, planet in enumerate(seq):
        t_P[i] = epoch(start_mjd2000 + sum(T[:i]))
        r_P[i], v_P[i] = planet.eph(t_P[i])
        plot_planet(ax, planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=JR)

    v_end_l = [a + b for a, b in zip(v_P[0], self.vinf_in)]
    # 4 - And we iterate on the legs
    for i in xrange(0, legs):
        # Fly-by
        v_out = fb_prop(v_end_l, v_P[i], x[1 + 4 * i] * seq[i - 1].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)
        plot_kepler(
            ax, r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu, N=500, color="b", legend=False, units=JR
        )
        # 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)
        plot_lambert(ax, l, sol=0, color="r", legend=False, units=JR, N=500)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]
    plt.show()
    return ax
Esempio n. 2
0
def _compute_DV_DT_incipit(self,x):
	"""
	This method computes, for each leg, all the velocity increments coming from
	deep space manoeuvres and all the transfer times.
	
	Use: 
		DV,DT = prob.compute_DV_DT(x)
		
	* x: trajectory encoding
	"""
	from PyKEP import epoch, lambert_problem, DAY2SEC, fb_prop, propagate_lagrangian
	from math import pi, acos,cos,sin,sqrt
	from scipy.linalg import norm
	
	#1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
	T = x[3::4]
	n_legs = len(x)/4
	seq = self.get_sequence()
	common_mu = seq[0].mu_central_body
	#2 - We compute the 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))
	
	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])

	#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,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,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)
		#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]
		#DSM occuring at time nu2*T2
		DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])
	return (DV,T)   
Esempio n. 3
0
def _get_score_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
    """
	This method returns the data needed to compute the score of a 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])

    #init lists for fly-by parameters
    vinf_list = []
    rp_list = []
    beta_list = []

    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)
        vinf_list.append([a - b for a, b in zip(v_end_l, v_P[i])])
        rp_list.append(x[1 + 4 * i] * seq[i].radius)
        beta_list.append(x[4 * i])

        #s/c propagation before the DSM
        r, v = propagate_lagrangian(r_P[i], v_out,
                                    x[4 * i + 2] * T[i] * DAY2SEC, 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 + 1], dt, common_mu, False, False)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]

    vinf_list.append([a - b for a, b in zip(v_end_l, v_P[-1])])
    rp_list.append(None)
    beta_list.append(None)
    return zip(ep_list, seq, vinf_list, rp_list, beta_list)
Esempio n. 4
0
def _get_score_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
	"""
	This method returns the data needed to compute the score of a 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])

	#init lists for fly-by parameters
	vinf_list = []
	rp_list = []
	beta_list = []

	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)
		vinf_list.append( [a-b for a,b in zip(v_end_l,v_P[i])] )
		rp_list.append(x[1+4*i]*seq[i].radius)
		beta_list.append(x[4*i])

		#s/c propagation before the DSM
		r,v = propagate_lagrangian(r_P[i],v_out,x[4*i+2]*T[i]*DAY2SEC,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+1],dt,common_mu, False, False)
		v_end_l = l.get_v2()[0]
		v_beg_l = l.get_v1()[0]

        vinf_list.append([a-b for a,b in zip(v_end_l,v_P[-1])])
        rp_list.append(None)
        beta_list.append(None)
	return zip(ep_list, seq, vinf_list, rp_list, beta_list)
Esempio n. 5
0
def _part_plot(x, units, ax, seq, start_mjd2000, vinf_in):
    """
    Plots the trajectory represented by a decision vector x = [beta,rp,eta,T] * N
    associated to a sequence seq, a start_mjd2000 and an incoming vinf_in
    """
    from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler
    from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC
    from math import pi, acos, cos, sin
    from scipy.linalg import norm

    legs = len(x) / 4
    common_mu = seq[0].mu_central_body

    # 1 -  we 'decode' the chromosome recording the various times of flight
    # (days) in the list T
    T = x[3::4]

    # 2 - We compute the epochs and ephemerides of the planetary encounters
    t_P = list([None] * (legs + 1))
    r_P = list([None] * (legs + 1))
    v_P = list([None] * (legs + 1))

    for i, planet in enumerate(seq):
        t_P[i] = epoch(start_mjd2000 + sum(T[:i]))
        r_P[i], v_P[i] = planet.eph(t_P[i])
        plot_planet(ax,
                    planet,
                    t0=t_P[i],
                    color=(0.8, 0.6, 0.8),
                    legend=True,
                    units=units)

    v_end_l = [a + b for a, b in zip(v_P[0], vinf_in)]
    # 4 - And we iterate on the legs
    for i in range(0, legs):
        # 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)
        plot_kepler(ax,
                    r_P[i],
                    v_out,
                    x[4 * i + 2] * T[i] * DAY2SEC,
                    common_mu,
                    N=500,
                    color='b',
                    legend=False,
                    units=units)
        # 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)
        plot_lambert(ax, l, sol=0, color='r', legend=False, units=units, N=500)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]
Esempio n. 6
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 = 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))

        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[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)
            #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]
            #DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
        return (sum(DV), )
Esempio n. 7
0
def _part_plot(x, units, axis, seq, start_mjd2000, vinf_in):
    """
    Plots the trajectory represented by a decision vector x = [beta,rp,eta,T] * N
    associated to a sequence seq, a start_mjd2000 and an incoming vinf_in
    """
    from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler
    from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC
    from math import pi, acos, cos, sin
    from scipy.linalg import norm

    legs = len(x) // 4
    common_mu = seq[0].mu_central_body

    # 1 -  we 'decode' the chromosome recording the various times of flight
    # (days) in the list T
    T = x[3::4]

    # 2 - We compute the epochs and ephemerides of the planetary encounters
    t_P = list([None] * (legs + 1))
    r_P = list([None] * (legs + 1))
    v_P = list([None] * (legs + 1))

    for i, planet in enumerate(seq):
        t_P[i] = epoch(start_mjd2000 + sum(T[:i]))
        r_P[i], v_P[i] = planet.eph(t_P[i])
        plot_planet(planet, t0=t_P[i], color=(
            0.8, 0.6, 0.8), legend=True, units = units, ax=axis)

    v_end_l = [a + b for a, b in zip(v_P[0], vinf_in)]
    # 4 - And we iterate on the legs
    for i in range(0, legs):
        # 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)
        plot_kepler(r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC,
                    common_mu, N=500, color='b', legend=False, units=units, ax=axis)
        # 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)
        plot_lambert(
            l, sol=0, color='r', legend=False, units=units, N=500, ax=axis)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]
Esempio n. 8
0
def get_coordinates(ep, planet, vinf_in, rp, beta):
	""" Computes the intersection between the vector of the spacecraft to the surface of the moon.

		USAGE: ms.get_coordinates(62500, gtoc6.europa, (0,0,10000), gtoc6.europa.radius + 10000, 0.3)

		@param ep epoch of fly-by
		@param planet the jupiter moon, i.e. gtoc6.io
		@param vinf_in relative entry velocity
		@param rp fly-by radius
		@param beta fly-by-plane orientation
		@return 3-tuple of cartesian coordinates of the periapsis vector in the body fixed reference frame"""
        
	# getting coordinates and speed of the moon
	eph = planet.eph(epoch(ep,epoch.epoch_type.MJD))
	print eph

	# compute outgoing velocity
	v_in_abs = tuple(map(operator.add, vinf_in, eph[1]))
	print v_in_abs
	v_out_abs = fb_prop(v_in_abs, eph[1], rp, beta, planet.mu_self)
	print v_out_abs
	v_diff = np.array(tuple(map(operator.sub, v_in_abs, v_out_abs)))

	# constraint check
	vinf_out = tuple(map(operator.sub, v_out_abs, eph[1]))
	
	if np.linalg.norm(vinf_in) - np.linalg.norm(vinf_out) > 1.0:
		print 'WARNING: Constraint violation! Difference between vinf_in and vinf_out is larger than 1!'

	# compute periapsis vector
	peri = rp * v_diff / np.linalg.norm(v_diff)

	# body-fixed coordinate frame
	x, v = np.array(eph[0]), np.array(eph[1])
	bhat1 = x * -1.0 / np.linalg.norm(x)
	bhat3 = np.cross(x, v) / np.linalg.norm(np.cross(x,v))
	bhat2 = np.cross(bhat3, bhat1)
    
	# use dot product to get coordinates of periapsis vector in the body-fixed reference frame
	peri_hat = np.array( (np.dot(peri, bhat1), np.dot(peri, bhat2), np.dot(peri, bhat3)) )

	# vector is now normalized to the sphere which has the soccer ball inside.
	# radius of this sphere is given by problem description as sqrt(9 * golden + 10)
	return tuple((peri_hat / np.linalg.norm(peri_hat)) * np.sqrt(9 * golden + 10))
Esempio n. 9
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 = 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))
		
		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[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)
			#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]
			#DSM occuring at time nu2*T2
			DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])
		return (sum(DV),)   
Esempio n. 10
0
def _mga_1dsm_tof_plot_old(self, x):
    """
    Plots the trajectory represented by the decision vector x
    """
    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler
    from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC
    from math import pi, acos, cos, sin
    from scipy.linalg import norm

    mpl.rcParams['legend.fontsize'] = 10
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.scatter(0, 0, 0, color='y')

    seq = self.get_sequence()

    n = (len(seq) - 1)
    # 1 -  we 'decode' the chromosome recording the various times of flight
    # (days) in the list T
    T = x[5::4]

    # 2 - We compute the epochs and ephemerides of the planetary encounters
    t_P = list([None] * (n + 1))
    r_P = list([None] * (n + 1))
    v_P = list([None] * (n + 1))
    DV = list([None] * (n + 1))

    for i, planet in enumerate(seq):
        t_P[i] = epoch(x[0] + sum(T[0:i]))
        r_P[i], v_P[i] = planet.eph(t_P[i])
        plot_planet(ax, planet, t0=t_P[i], color=(
            0.8, 0.6, 0.8), legend=True, units = AU)

    # 3 - We start with the first leg
    theta = 2 * pi * x[1]
    phi = acos(2 * x[2] - 1) - pi / 2

    Vinfx = x[3] * cos(phi) * cos(theta)
    Vinfy = x[3] * cos(phi) * sin(theta)
    Vinfz = x[3] * sin(phi)

    v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])]
    r, v = propagate_lagrangian(
        r_P[0], v0, x[4] * T[0] * DAY2SEC, seq[0].mu_central_body)
    plot_kepler(
        ax,
        r_P[0],
        v0,
        x[4] *
        T[0] *
        DAY2SEC,
        seq[0].mu_central_body,
        N=100,
        color='b',
        legend=False,
        units=AU)

    # Lambert arc to reach seq[1]
    dt = (1 - x[4]) * T[0] * DAY2SEC
    l = lambert_problem(r, r_P[1], dt, seq[0].mu_central_body)
    plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU)
    v_end_l = l.get_v2()[0]
    v_beg_l = l.get_v1()[0]

    # First DSM occuring at time nu1*T1
    DV[0] = norm([a - b for a, b in zip(v_beg_l, v)])

    # 4 - And we proceed with each successive leg
    for i in range(1, n):
        # Fly-by
        v_out = fb_prop(v_end_l,
                        v_P[i],
                        x[7 + (i - 1) * 4] * seq[i].radius,
                        x[6 + (i - 1) * 4],
                        seq[i].mu_self)
        # s/c propagation before the DSM
        r, v = propagate_lagrangian(
            r_P[i], v_out, x[8 + (i - 1) * 4] * T[i] * DAY2SEC, seq[0].
            mu_central_body)
        plot_kepler(ax,
                    r_P[i],
                    v_out,
                    x[8 + (i - 1) * 4] * T[i] * DAY2SEC,
                    seq[0].mu_central_body,
                    N=100,
                    color='b',
                    legend=False,
                    units=AU)
        # Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
        dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC
        l = lambert_problem(r, r_P[i + 1], dt, seq[0].mu_central_body)
        plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]
        # DSM occurring at time nu2*T2
        DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
    return ax
Esempio n. 11
0
def _mga_incipit_plot_old(self, x, plot_leg_0=False):
    """
    Plots the trajectory represented by the decision vector x

    Example::

      prob.plot(x)
    """
    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler
    from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC
    from math import pi, acos, cos, sin
    from scipy.linalg import norm

    mpl.rcParams['legend.fontsize'] = 10
    fig = plt.figure()
    ax = fig.gca(projection='3d', aspect='equal')
    ax.scatter(0, 0, 0, color='y')

    JR = 71492000.0
    legs = len(x) / 4
    seq = self.get_sequence()
    common_mu = seq[0].mu_central_body

    # 1 -  we 'decode' the chromosome recording the various times of flight
    # (days) in the list T
    T = x[3::4]

    # 2 - We compute the epochs and ephemerides of the planetary encounters
    t_P = list([None] * legs)
    r_P = list([None] * legs)
    v_P = list([None] * legs)
    DV = list([None] * legs)

    for i, planet in enumerate(seq):
        t_P[i] = epoch(x[0] + sum(T[:i + 1]))
        r_P[i], v_P[i] = planet.eph(t_P[i])
        plot_planet(ax,
                    planet,
                    t0=t_P[i],
                    color=(0.8, 0.6, 0.8),
                    legend=True,
                    units=JR)

    # 3 - We start with the first leg: a lambert arc
    theta = 2 * pi * x[1]
    phi = acos(2 * x[2] - 1) - pi / 2
    # phi close to zero is in the moon orbit plane injection
    r = [cos(phi) * sin(theta), cos(phi) * cos(theta), sin(phi)]
    r = [JR * 1000 * d for d in r]

    l = lambert_problem(r, r_P[0], T[0] * DAY2SEC, common_mu, False, False)
    if (plot_leg_0):
        plot_lambert(ax, l, sol=0, color='k', legend=False, units=JR, N=500)

    # Lambert arc to reach seq[1]
    v_end_l = l.get_v2()[0]
    v_beg_l = l.get_v1()[0]

    # 4 - And we proceed with each successive leg
    for i in range(1, 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)
        plot_kepler(ax,
                    r_P[i - 1],
                    v_out,
                    x[4 * i + 2] * T[i] * DAY2SEC,
                    common_mu,
                    N=500,
                    color='b',
                    legend=False,
                    units=JR)
        # 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)
        plot_lambert(ax, l, sol=0, color='r', legend=False, units=JR, N=500)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]
    plt.show()
    return ax
Esempio n. 12
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()
Esempio n. 13
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 = 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))
Esempio n. 14
0
    def _objfun_impl(self,x):
        #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
        T = list([0]*(self.__n))
        #a[-i] = x[-1-(i-1)*4]
        for i in xrange(self.__n-1):
            j = i+1;
            T[-j] = (x[5] - sum(T[-(j-1):])) * x[-1-(j-1)*4]
        T[0] = x[5] - sum(T)

        #2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n+1))
        r_P = list([None] * (self.__n+1))
        v_P = list([None] * (self.__n+1))
        DV = list([None] * (self.__n+1))

        for i,planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i],v_P[i] = self.seq[i].eph(t_P[i])

        #3 - We start with the first leg
        theta = 2*pi*x[1]
        phi = acos(2*x[2]-1)-pi/2

        Vinfx = x[3]*cos(phi)*cos(theta)
        Vinfy = x[3]*cos(phi)*sin(theta)
        Vinfz = x[3]*sin(phi)

        v0 = [a+b for a,b in zip(v_P[0], [Vinfx,Vinfy,Vinfz])]
        r,v = propagate_lagrangian(r_P[0], v0, x[4]*T[0]*DAY2SEC, MU_SUN)

        #Lambert arc to reach seq[1]
        dt = (1-x[4])*T[0]*DAY2SEC
        l = lambert_problem(r,r_P[1],dt,MU_SUN)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]

        #First DSM occuring at time nu1*T1
        DV[0] = norm([a-b for a,b in zip(v_beg_l, v)])

        #4 - And we proceed with each successive leg
        for i in range(1,self.__n):
            #Fly-by
            v_out = fb_prop(v_end_l, v_P[i] ,x[7+(i-1)*4]*self.seq[i].radius, x[6+(i-1)*4], self.seq[i].mu_self)
            #s/c propagation before the DSM
            r,v = propagate_lagrangian(r_P[i], v_out, x[8+(i-1)*4]*T[i]*DAY2SEC, MU_SUN)
            #Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1-x[8+(i-1)*4])*T[i]*DAY2SEC
            l = lambert_problem(r, r_P[i+1], dt, MU_SUN)
            v_end_l = l.get_v2()[0]
            v_beg_l = l.get_v1()[0]
            #DSM occuring at time nu2*T2
            DV[i] = norm([a-b for a,b in zip(v_beg_l, v)])

        #Last Delta-v
        DV[-1] = norm([a-b for a,b in zip(v_end_l,v_P[-1])])

        #moje
        Eh56500 = 61933310.95
        #Eh100000 = 61517435.56
        entry_Vel = (DV[-1]**2 + 2*Eh56500)**0.5
        entry_Vel2 = entry_Vel
        #axtl = 23.43929*DEG2RAD
        #DEC = abs(asin( sin(axtl)*cos(phi)*sin(theta) + cos(axtl)*sin(phi) ))*RAD2DEG # deklinacja asymptoty ucieczkowej
        sum_dv = sum(DV[:-1])
        eff_C3 = (x[3])**2

        if entry_Vel < self.entry_vel_barrier:
            entry_Vel2 = 0.0
            del DV[-1]

        #~ if eff_C3 < self.C3_barrier:
            #~ #eff_C3 = 0
            #~ pass

        if sum_dv < self.dsm_dv_barrier:
            sum_dv = 0+entry_Vel2
        else:
            sum_dv = sum(DV)

        if self.f_dimension == 1:
            return (sum_dv,)
        else:
            return (sum_dv, eff_C3, entry_Vel2) #,
Esempio n. 15
0
	def plot(self,x):
		"""
		Plots the trajectory represented by the decision vector x
		
		Example::
		
		  prob.plot(x)
		"""
		import matplotlib as mpl
		from mpl_toolkits.mplot3d import Axes3D
		import matplotlib.pyplot as plt
		from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler

		mpl.rcParams['legend.fontsize'] = 10
		fig = plt.figure()
		axis = fig.gca(projection='3d')
		axis.scatter(0,0,0, color='y')
		
		#1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
		
		T = list([0]*(self.__n_legs))
		for i in range(0, self.__n_legs):
			T[i] = x[4+3*(self.__n_legs - 1) + i+1]
		
		#2 - We compute the epochs and ephemerides of the planetary encounters
		t_P = list([None] * (self.__n_legs+1))
		r_P = list([None] * (self.__n_legs+1))
		v_P = list([None] * (self.__n_legs+1))
		DV = list([None] * (self.__n_legs+1))
		
		for i,planet in enumerate(self.seq):
			t_P[i] = epoch(x[0] + sum(T[0:i]))
			r_P[i],v_P[i] = planet.eph(t_P[i])
			plot_planet(planet, t0=t_P[i], color=(0.8,0.6,0.8), legend=True, units = AU, ax=axis)

		#3 - We start with the first leg
		theta = 2*pi*x[1]
		phi = acos(2*x[2]-1)-pi/2

		Vinfx = x[3]*cos(phi)*cos(theta)
		Vinfy =	x[3]*cos(phi)*sin(theta)
		Vinfz = x[3]*sin(phi)

		v0 = [a+b for a,b in zip(v_P[0],[Vinfx,Vinfy,Vinfz])]
		r,v = propagate_lagrangian(r_P[0],v0,x[4]*T[0]*DAY2SEC,self.common_mu)
		plot_kepler(r_P[0],v0,x[4]*T[0]*DAY2SEC,self.common_mu,N = 100, color='b', legend=False, units = AU, ax=axis)

		#Lambert arc to reach seq[1]
		dt = (1-x[4])*T[0]*DAY2SEC
		l = lambert_problem(r,r_P[1],dt,self.common_mu, False, False)
		plot_lambert(l, sol = 0, color='r', legend=False, units = AU, ax=axis)
		v_end_l = l.get_v2()[0]
		v_beg_l = l.get_v1()[0]

		#First DSM occurring at time nu1*T1
		DV[0] = norm([a-b for a,b in zip(v_beg_l,v)])

		#4 - And we proceed with each successive leg
		for i in range(1,self.__n_legs):
			#Fly-by 
			v_out = fb_prop(v_end_l,v_P[i],x[6+(i-1)*3]*self.seq[i].radius,x[5+(i-1)*3],self.seq[i].mu_self)
			#s/c propagation before the DSM
			r,v = propagate_lagrangian(r_P[i],v_out,x[7+(i-1)*3]*T[i]*DAY2SEC,self.common_mu)
			plot_kepler(r_P[i],v_out,x[7+(i-1)*3]*T[i]*DAY2SEC,self.common_mu,N = 100, color='b', legend=False, units = AU, ax=axis)
			#Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
			dt = (1-x[7+(i-1)*3])*T[i]*DAY2SEC

			l = lambert_problem(r,r_P[i+1],dt,self.common_mu, False, False)
			plot_lambert(l, sol = 0, color='r', legend=False, units = AU, N=1000, ax=axis)

			v_end_l = l.get_v2()[0]
			v_beg_l = l.get_v1()[0]
			#DSM occurring at time nu2*T2
			DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])
		plt.show()
		return axis
Esempio n. 16
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
		T = list([0]*(self.__n_legs))
		for i in range(0, self.__n_legs):
			T[i] = x[4+3*(self.__n_legs - 1) + i+1]
		
		#2 - We compute the epochs and ephemerides of the planetary encounters
		t_P = list([None] * (self.__n_legs+1))
		r_P = list([None] * (self.__n_legs+1))
		v_P = list([None] * (self.__n_legs+1))
		DV = list([None] * (self.__n_legs+1))
		
		for i,planet in enumerate(self.seq):
			t_P[i] = epoch(x[0] + sum(T[0:i]))
			r_P[i],v_P[i] = self.seq[i].eph(t_P[i])

		#3 - We start with the first leg
		print "First Leg: " + self.seq[0].name + " to " + self.seq[1].name 
		
		theta = 2*pi*x[1]
		phi = acos(2*x[2]-1)-pi/2

		Vinfx = x[3]*cos(phi)*cos(theta)
		Vinfy =	x[3]*cos(phi)*sin(theta)
		Vinfz = x[3]*sin(phi)
		
		print "Departure: " + str(t_P[0]) + " (" + str(t_P[0].mjd2000) + " mjd2000) " 
		print "Duration: " + str(T[0]) + "days"
		print "VINF: " + str(x[3] / 1000) + " km/sec"

		v0 = [a+b for a,b in zip(v_P[0],[Vinfx,Vinfy,Vinfz])]
		r,v = propagate_lagrangian(r_P[0],v0,x[4]*T[0]*DAY2SEC,self.common_mu)
		
		print "DSM after " + str(x[4]*T[0]) + " days"

		#Lambert arc to reach seq[1]
		dt = (1-x[4])*T[0]*DAY2SEC
		l = lambert_problem(r,r_P[1],dt,self.common_mu, False, False)
		v_end_l = l.get_v2()[0]
		v_beg_l = l.get_v1()[0]

		#First DSM occuring at time nu1*T1
		DV[0] = norm([a-b for a,b in zip(v_beg_l,v)])
		print "DSM magnitude: " + str(DV[0]) + "m/s"

		#4 - And we proceed with each successive leg
		for i in range(1,self.__n_legs):
			print "\nleg no. " + str(i+1) + ": " + self.seq[i].name + " to " + self.seq[i+1].name 
			print "Duration: " + str(T[i]) + "days"
			#Fly-by 
			v_out = fb_prop(v_end_l,v_P[i],x[6+(i-1)*3]*self.seq[i].radius,x[5+(i-1)*3],self.seq[i].mu_self)
			print "Fly-by epoch: " + str(t_P[i]) + " (" + str(t_P[i].mjd2000) + " mjd2000) " 
			print "Fly-by radius: " + str(x[6+(i-1)*3]) + " planetary radii"
			#s/c propagation before the DSM
			r,v = propagate_lagrangian(r_P[i],v_out,x[7+(i-1)*3]*T[i]*DAY2SEC,self.common_mu)
			print "DSM after " + str(x[7+(i-1)*3]*T[i]) + " days"
			#Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
			dt = (1-x[7+(i-1)*3])*T[i]*DAY2SEC
			l = lambert_problem(r,r_P[i+1],dt,self.common_mu, False, False)
			v_end_l = l.get_v2()[0]
			v_beg_l = l.get_v1()[0]
			#DSM occuring at time nu2*T2
			DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])
			print "DSM magnitude: " + str(DV[i]) + "m/s"

		#Last Delta-v
		print "\nArrival at " + self.seq[-1].name
		DV[-1] = norm([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: " + str(DV[-1]) + "m/s"
		print "Total mission time: " + str(sum(T)/365.25) + " years"
Esempio n. 17
0
    def _objfun_impl(self, x):
        #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
        T = list([0] * (self.__n_legs))

        for i in xrange(self.__n_legs - 1):
            j = i + 1
            T[-j] = (x[5] - sum(T[-(j - 1):])) * x[-1 - (j - 1) * 4]
        T[0] = x[5] - sum(T)

        #2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))
        DV = list([0.0] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i], v_P[i] = self.seq[i].eph(t_P[i])

        #3 - We start with the first leg
        theta = 2 * pi * x[1]
        phi = acos(2 * x[2] - 1) - pi / 2

        Vinfx = x[3] * cos(phi) * cos(theta)
        Vinfy = x[3] * cos(phi) * sin(theta)
        Vinfz = x[3] * sin(phi)

        v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])]
        r, v = propagate_lagrangian(r_P[0], v0, x[4] * T[0] * DAY2SEC,
                                    self.common_mu)

        #Lambert arc to reach seq[1]
        dt = (1 - x[4]) * T[0] * DAY2SEC
        l = lambert_problem(r, r_P[1], dt, self.common_mu, False, False)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]

        #First DSM occuring at time nu1*T1
        DV[0] = norm([a - b for a, b in zip(v_beg_l, v)])

        #4 - And we proceed with each successive leg
        for i in range(1, self.__n_legs):
            #Fly-by
            v_out = fb_prop(v_end_l, v_P[i],
                            x[7 + (i - 1) * 4] * self.seq[i].radius,
                            x[6 + (i - 1) * 4], self.seq[i].mu_self)
            #s/c propagation before the DSM
            r, v = propagate_lagrangian(r_P[i], v_out,
                                        x[8 + (i - 1) * 4] * T[i] * DAY2SEC,
                                        self.common_mu)
            #Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC
            l = lambert_problem(r, r_P[i + 1], dt, self.common_mu, False,
                                False)
            v_end_l = l.get_v2()[0]
            v_beg_l = l.get_v1()[0]
            #DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])

        #Last Delta-v
        if self.__add_vinf_arr:
            DV[-1] = norm([a - b for a, b in zip(v_end_l, v_P[-1])])

        if self.__add_vinf_dep:
            DV[0] += x[3]

        if self.f_dimension == 1:
            return (sum(DV), )
        else:
            return (sum(DV), sum(T))
Esempio n. 18
0
    def plot(self, x):
        """
		Plots the trajectory represented by the decision vector x
		
		Example::
		
		  prob.plot(x)
		"""
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler

        mpl.rcParams['legend.fontsize'] = 10
        fig = plt.figure()
        ax = fig.gca(projection='3d')
        ax.scatter(0, 0, 0, color='y')

        #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
        T = list([0] * (self.__n_legs))
        #a[-i] = x[-1-(i-1)*4]
        for i in xrange(self.__n_legs - 1):
            j = i + 1
            T[-j] = (x[5] - sum(T[-(j - 1):])) * x[-1 - (j - 1) * 4]
        T[0] = x[5] - sum(T)

        #2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))
        DV = list([None] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i], v_P[i] = planet.eph(t_P[i])
            plot_planet(ax,
                        planet,
                        t0=t_P[i],
                        color=(0.8, 0.6, 0.8),
                        legend=True,
                        units=AU)

        #3 - We start with the first leg
        theta = 2 * pi * x[1]
        phi = acos(2 * x[2] - 1) - pi / 2

        Vinfx = x[3] * cos(phi) * cos(theta)
        Vinfy = x[3] * cos(phi) * sin(theta)
        Vinfz = x[3] * sin(phi)

        v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])]
        r, v = propagate_lagrangian(r_P[0], v0, x[4] * T[0] * DAY2SEC,
                                    self.common_mu)
        plot_kepler(ax,
                    r_P[0],
                    v0,
                    x[4] * T[0] * DAY2SEC,
                    self.common_mu,
                    N=100,
                    color='b',
                    legend=False,
                    units=AU)

        #Lambert arc to reach seq[1]
        dt = (1 - x[4]) * T[0] * DAY2SEC
        l = lambert_problem(r, r_P[1], dt, self.common_mu, False, False)
        plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]

        #First DSM occuring at time nu1*T1
        DV[0] = norm([a - b for a, b in zip(v_beg_l, v)])

        #4 - And we proceed with each successive leg
        for i in range(1, self.__n_legs):
            #Fly-by
            v_out = fb_prop(v_end_l, v_P[i],
                            x[7 + (i - 1) * 4] * self.seq[i].radius,
                            x[6 + (i - 1) * 4], self.seq[i].mu_self)
            #s/c propagation before the DSM
            r, v = propagate_lagrangian(r_P[i], v_out,
                                        x[8 + (i - 1) * 4] * T[i] * DAY2SEC,
                                        self.common_mu)
            plot_kepler(ax,
                        r_P[i],
                        v_out,
                        x[8 + (i - 1) * 4] * T[i] * DAY2SEC,
                        self.common_mu,
                        N=100,
                        color='b',
                        legend=False,
                        units=AU)
            #Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC

            l = lambert_problem(r, r_P[i + 1], dt, self.common_mu, False,
                                False)
            plot_lambert(ax,
                         l,
                         sol=0,
                         color='r',
                         legend=False,
                         units=AU,
                         N=1000)

            v_end_l = l.get_v2()[0]
            v_beg_l = l.get_v1()[0]
            #DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])

        plt.show()
Esempio n. 19
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
        T = list([0] * (self.__n_legs))
        #a[-i] = x[-1-(i-1)*4]
        for i in xrange(self.__n_legs - 1):
            j = i + 1
            T[-j] = (x[5] - sum(T[-(j - 1):])) * x[-1 - (j - 1) * 4]
        T[0] = x[5] - sum(T)

        #2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))
        DV = list([None] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i], v_P[i] = self.seq[i].eph(t_P[i])

        #3 - We start with the first leg
        print "First Leg: " + self.seq[0].name + " to " + self.seq[1].name

        theta = 2 * pi * x[1]
        phi = acos(2 * x[2] - 1) - pi / 2

        Vinfx = x[3] * cos(phi) * cos(theta)
        Vinfy = x[3] * cos(phi) * sin(theta)
        Vinfz = x[3] * sin(phi)

        print "Departure: " + str(t_P[0]) + " (" + str(
            t_P[0].mjd2000) + " mjd2000) "
        print "Duration: " + str(T[0]) + "days"
        print "VINF: " + str(x[3] / 1000) + " km/sec"

        v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])]
        r, v = propagate_lagrangian(r_P[0], v0, x[4] * T[0] * DAY2SEC,
                                    self.common_mu)

        print "DSM after " + str(x[4] * T[0]) + " days"

        #Lambert arc to reach seq[1]
        dt = (1 - x[4]) * T[0] * DAY2SEC
        l = lambert_problem(r, r_P[1], dt, self.common_mu, False, False)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]

        #First DSM occuring at time nu1*T1
        DV[0] = norm([a - b for a, b in zip(v_beg_l, v)])
        print "DSM magnitude: " + str(DV[0]) + "m/s"

        #4 - And we proceed with each successive leg
        for i in range(1, self.__n_legs):
            print "\nleg no. " + str(
                i + 1) + ": " + self.seq[i].name + " to " + self.seq[i +
                                                                     1].name
            print "Duration: " + str(T[i]) + "days"
            #Fly-by
            v_out = fb_prop(v_end_l, v_P[i],
                            x[7 + (i - 1) * 4] * self.seq[i].radius,
                            x[6 + (i - 1) * 4], self.seq[i].mu_self)
            print "Fly-by epoch: " + str(t_P[i]) + " (" + str(
                t_P[i].mjd2000) + " mjd2000) "
            print "Fly-by radius: " + str(x[7 +
                                            (i - 1) * 4]) + " planetary radii"
            #s/c propagation before the DSM
            r, v = propagate_lagrangian(r_P[i], v_out,
                                        x[8 + (i - 1) * 4] * T[i] * DAY2SEC,
                                        self.common_mu)
            print "DSM after " + str(x[8 + (i - 1) * 4] * T[i]) + " days"
            #Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC
            l = lambert_problem(r, r_P[i + 1], dt, self.common_mu, False,
                                False)
            v_end_l = l.get_v2()[0]
            v_beg_l = l.get_v1()[0]
            #DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
            print "DSM magnitude: " + str(DV[i]) + "m/s"

        #Last Delta-v
        print "\nArrival at " + self.seq[-1].name
        DV[-1] = norm([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: " + str(DV[-1]) + "m/s"
        print "Total mission time: " + str(sum(T) / 365.25) + " years"
Esempio n. 20
0
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;  		
Esempio n. 21
0
	def _objfun_impl(self,x):
		#1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T

		T = list([0]*(self.__n_legs))
		for i in range(0,self.__n_legs):
			T[i] = x[4+3*(self.__n_legs - 1) + i+1]
  
		#2 - We compute the epochs and ephemerides of the planetary encounters
		t_P = list([None] * (self.__n_legs+1))
		r_P = list([None] * (self.__n_legs+1))
		v_P = list([None] * (self.__n_legs+1))
		DV = list([0.0] * (self.__n_legs+1))
		
		for i,planet in enumerate(self.seq):
			t_P[i] = epoch(x[0] + sum(T[0:i]))
			r_P[i],v_P[i] = self.seq[i].eph(t_P[i])
			

		#3 - We start with the first leg
		theta = 2*pi*x[1]
		phi = acos(2*x[2]-1)-pi/2

		Vinfx = x[3]*cos(phi)*cos(theta)
		Vinfy = x[3]*cos(phi)*sin(theta)
		Vinfz = x[3]*sin(phi)

		v0 = [a+b for a,b in zip(v_P[0],[Vinfx,Vinfy,Vinfz])]
		r,v = propagate_lagrangian(r_P[0],v0,x[4]*T[0]*DAY2SEC,self.common_mu)

		#Lambert arc to reach seq[1]
		dt = (1-x[4])*T[0]*DAY2SEC
		l = lambert_problem(r,r_P[1],dt,self.common_mu, False, False)
		v_end_l = l.get_v2()[0]
		v_beg_l = l.get_v1()[0]

		#First DSM occuring at time nu1*T1
		DV[0] = norm([a-b for a,b in zip(v_beg_l,v)])

		#4 - And we proceed with each successive leg
		for i in range(1,self.__n_legs):
			#Fly-by 
			v_out = fb_prop(v_end_l,v_P[i],x[6+(i-1)*3]*self.seq[i].radius,x[5+(i-1)*3],self.seq[i].mu_self)
			#s/c propagation before the DSM
			r,v = propagate_lagrangian(r_P[i],v_out,x[7+(i-1)*3]*T[i]*DAY2SEC,self.common_mu)
			#Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
			dt = (1-x[7+(i-1)*3])*T[i]*DAY2SEC
			l = lambert_problem(r,r_P[i+1],dt,self.common_mu, False, False)
			v_end_l = l.get_v2()[0]
			v_beg_l = l.get_v1()[0]
			#DSM occuring at time nu2*T2
			DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])


		#Last Delta-v
		if self.__add_vinf_arr:
			DV[-1] = norm([a-b for a,b in zip(v_end_l,v_P[-1])])
		
		if self.__add_vinf_dep:
			DV[0] += x[3]

		if self.f_dimension == 1:
			return (sum(DV),)
		else:
			return (sum(DV), sum(T))
Esempio n. 22
0
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
Esempio n. 23
0
    def ic_from_mga_1dsm(self, x):
        """
        x_lt = prob.ic_from_mga_1dsm(x_mga)

        - x_mga: compatible trajectory as encoded by an mga_1dsm problem

        Returns an initial guess for the low-thrust trajectory, converting the mga_1dsm solution x_dsm. The user
        is responsible that x_mga makes sense (i.e. it is a viable mga_1dsm representation). The conversion is done by importing in the
        low-thrust encoding a) the launch date b) all the legs durations, c) the in and out relative velocities at each planet.
        All throttles are put to zero.

        Example::

          x_lt= prob.ic_from_mga_1dsm(x_mga)
        """
        from math import pi, cos, sin, acos
        from scipy.linalg import norm
        from PyKEP import propagate_lagrangian, lambert_problem, DAY2SEC, fb_prop

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

        for i in range(len(T)):
            T[i] = log(x[2 + 4 * i])
        total = sum(T)
        T = [x[1] * time / total for time in T]

        retval[0] = x[0]
        for i in range(self.__n_legs):
            retval[1 + 8 * i] = T[i]
            retval[2 + 8 * i] = self.__sc.mass

        # 2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))
        DV = list([None] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i], v_P[i] = self.seq[i].eph(t_P[i])

        # 3 - We start with the first leg
        theta = 2 * pi * x[1]
        phi = acos(2 * x[2] - 1) - pi / 2

        Vinfx = x[3] * cos(phi) * cos(theta)
        Vinfy = x[3] * cos(phi) * sin(theta)
        Vinfz = x[3] * sin(phi)

        retval[3:6] = [Vinfx, Vinfy, Vinfz]

        v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])]
        r, v = propagate_lagrangian(r_P[0], v0, x[4] * T[0] * DAY2SEC, MU_SUN)

        # Lambert arc to reach seq[1]
        dt = (1 - x[4]) * T[0] * DAY2SEC
        l = lambert_problem(r, r_P[1], dt, MU_SUN)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]

        retval[6:9] = [a - b for a, b in zip(v_end_l, v_P[1])]

        # 4 - And we proceed with each successive leg
        for i in range(1, self.__n_legs):
            # Fly-by
            v_out = fb_prop(v_end_l, v_P[i], x[7 + (i - 1) * 4] * self.seq[i].radius, x[6 + (i - 1) * 4], self.seq[i].mu_self)
            retval[3 + i * 8:6 + i * 8] = [a - b for a, b in zip(v_out, v_P[i])]
            # s/c propagation before the DSM
            r, v = propagate_lagrangian(r_P[i], v_out, x[8 + (i - 1) * 4] * T[i] * DAY2SEC, MU_SUN)
            # Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC
            l = lambert_problem(r, r_P[i + 1], dt, MU_SUN)
            v_end_l = l.get_v2()[0]
            v_beg_l = l.get_v1()[0]
            # DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
            retval[6 + i * 8:9 + i * 8] = [a - b for a, b in zip(v_end_l, v_P[i + 1])]
        return retval
Esempio n. 24
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))
Esempio n. 25
0
	def plot(self,x):
		"""
		Plots the trajectory represented by the decision vector x
		
		Example::
		
		  prob.plot(x)
		"""
		import matplotlib as mpl
		from mpl_toolkits.mplot3d import Axes3D
		import matplotlib.pyplot as plt
		from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler

		mpl.rcParams['legend.fontsize'] = 10
		fig = plt.figure()
		ax = fig.gca(projection='3d')
		ax.scatter(0,0,0, color='y')
		
		#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))
		
		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])
			plot_planet(ax, planet, t0=t_P[i], color=(0.8,0.6,0.8), legend=True, units = JR)

		#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)
		plot_lambert(ax,l, sol = 0, color='k', legend=False, units = JR, N=500)

		#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[4*i+3]*T[i]*DAY2SEC,self.common_mu)
			plot_kepler(ax,r_P[i-1],v_out,x[7+(i-1)*4]*T[i]*DAY2SEC,self.common_mu,N = 500, color='b', legend=False, units = JR)
			#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)
			plot_lambert(ax,l, sol = 0, color='r', legend=False, units = JR, N=500)
			v_end_l = l.get_v2()[0]
			v_beg_l = l.get_v1()[0]
			#DSM occuring at time nu2*T2
			DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])
 
		plt.show()
Esempio n. 26
0
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
Esempio n. 27
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)) 
Esempio n. 28
0
def _compute_DV_DT_incipit(self, x):
    """
	This method computes, for each leg, all the velocity increments coming from
	deep space manoeuvres and all the transfer times.
	
	Use: 
		DV,DT = prob.compute_DV_DT(x)
		
	* x: trajectory encoding
	"""
    from PyKEP import epoch, lambert_problem, DAY2SEC, fb_prop, propagate_lagrangian
    from math import pi, acos, cos, sin, sqrt
    from scipy.linalg import norm

    #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
    T = x[3::4]
    n_legs = len(x) / 4
    seq = self.get_sequence()
    common_mu = seq[0].mu_central_body
    #2 - We compute the 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))

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

    #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, 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, 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)
        #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]
        #DSM occuring at time nu2*T2
        DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
    return (DV, T)
Esempio n. 29
0
    def ic_from_mga_1dsm(self, x):
        """
        x_lt = prob.ic_from_mga_1dsm(x_mga)

        - x_mga: compatible trajectory as encoded by an mga_1dsm problem

        Returns an initial guess for the low-thrust trajectory, converting the mga_1dsm solution x_dsm. The user
        is responsible that x_mga makes sense (i.e. it is a viable mga_1dsm representation). The conversion is done by importing in the
        low-thrust encoding a) the launch date b) all the legs durations, c) the in and out relative velocities at each planet.
        All throttles are put to zero.

        Example::

          x_lt= prob.ic_from_mga_1dsm(x_mga)
        """
        from math import pi, cos, sin, acos
        from scipy.linalg import norm
        from PyKEP import propagate_lagrangian, lambert_problem, DAY2SEC, fb_prop

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

        for i in range(len(T)):
            T[i] = log(x[2 + 4 * i])
        total = sum(T)
        T = [x[1] * time / total for time in T]

        retval[0] = x[0]
        for i in range(self.__n_legs):
            retval[1 + 8 * i] = T[i]
            retval[2 + 8 * i] = self.__sc.mass

        # 2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))
        DV = list([None] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i], v_P[i] = self.seq[i].eph(t_P[i])

        # 3 - We start with the first leg
        theta = 2 * pi * x[1]
        phi = acos(2 * x[2] - 1) - pi / 2

        Vinfx = x[3] * cos(phi) * cos(theta)
        Vinfy = x[3] * cos(phi) * sin(theta)
        Vinfz = x[3] * sin(phi)

        retval[3:6] = [Vinfx, Vinfy, Vinfz]

        v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])]
        r, v = propagate_lagrangian(r_P[0], v0, x[4] * T[0] * DAY2SEC, MU_SUN)

        # Lambert arc to reach seq[1]
        dt = (1 - x[4]) * T[0] * DAY2SEC
        l = lambert_problem(r, r_P[1], dt, MU_SUN)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]

        retval[6:9] = [a - b for a, b in zip(v_end_l, v_P[1])]

        # 4 - And we proceed with each successive leg
        for i in range(1, self.__n_legs):
            # Fly-by
            v_out = fb_prop(v_end_l, v_P[i],
                            x[7 + (i - 1) * 4] * self.seq[i].radius,
                            x[6 + (i - 1) * 4], self.seq[i].mu_self)
            retval[3 + i * 8:6 +
                   i * 8] = [a - b for a, b in zip(v_out, v_P[i])]
            # s/c propagation before the DSM
            r, v = propagate_lagrangian(r_P[i], v_out,
                                        x[8 + (i - 1) * 4] * T[i] * DAY2SEC,
                                        MU_SUN)
            # Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC
            l = lambert_problem(r, r_P[i + 1], dt, MU_SUN)
            v_end_l = l.get_v2()[0]
            v_beg_l = l.get_v1()[0]
            # DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
            retval[6 + i * 8:9 +
                   i * 8] = [a - b for a, b in zip(v_end_l, v_P[i + 1])]
        return retval
Esempio n. 30
0
def _get_lt_problem(self, x, n_seg=[10, 10], high_fidelity=True):
    """
	This method returns the equivalent low-thrust problem of an incipit
	"""
    from PyKEP import epoch, lambert_problem, DAY2SEC, fb_prop, propagate_lagrangian
    from PyGMO import population
    from math import pi, acos, cos, sin, sqrt, exp
    from scipy.linalg import norm

    retval = []
    #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
    T = x[3::4]
    n_legs = len(x) / 4
    seq = self.get_sequence()
    common_mu = seq[0].mu_central_body
    #2 - We compute the 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))

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

    #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, common_mu, False, False)

    #Lambert arc to reach seq[1]
    v_end_l = l.get_v2()[0]
    v_beg_l = l.get_v1()[0]

    #We start appending in the lt chromosome (see mga_incipit_lt)
    retval.append(theta)
    retval.append(phi)

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

    #Start of the first lt leg encoding
    retval.append(T[0])
    retval.append(exp(-DV[0] / 9.80665 / 2000) * 2000)  #Tsiolkowsky
    retval.extend(v_beg_l)
    retval.extend([a - b for a, b in zip(v_end_l, v_P[0])])

    #4 - And we proceed with each successive leg
    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)
        #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]
        #DSM occuring at time nu2*T2
        DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])

        #lt encoding of all legs
        retval.append(T[i])
        retval.append(exp(-sum(DV[:i + 1]) / 9.80665 / 2000) *
                      2000)  #Tsiolkowsky
        retval.extend([a - b for a, b in zip(v_out, v_P[i - 1])])
        if i != n_legs - 1:
            retval.extend([a - b for a, b in zip(v_end_l, v_P[i])])

    retval = retval + [0] * sum(n_seg) * 3
    prob = mga_incipit_lt(high_fidelity=high_fidelity,
                          seq=seq,
                          n_seg=n_seg,
                          tf=epoch(x[0] + sum(T)),
                          vf=[a - b for a, b in zip(v_end_l, v_P[i])])
    # solves the problem of chemical trajectories wanting higher launch dv
    ub = list(prob.ub)
    lb = list(prob.lb)
    ub[4:7] = [5000, 5000, 5000]
    lb[4:7] = [-5000, -5000, -5000]
    prob.set_bounds(lb, ub)
    pop = population(prob)
    pop.push_back(retval)
    return (prob, pop)
Esempio n. 31
0
def _mga_1dsm_tof_plot_old(self, x):
    """
    Plots the trajectory represented by the decision vector x
    """
    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler
    from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC
    from math import pi, acos, cos, sin
    from scipy.linalg import norm

    mpl.rcParams['legend.fontsize'] = 10
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.scatter(0, 0, 0, color='y')

    seq = self.get_sequence()

    n = (len(seq) - 1)
    # 1 -  we 'decode' the chromosome recording the various times of flight
    # (days) in the list T
    T = x[5::4]

    # 2 - We compute the epochs and ephemerides of the planetary encounters
    t_P = list([None] * (n + 1))
    r_P = list([None] * (n + 1))
    v_P = list([None] * (n + 1))
    DV = list([None] * (n + 1))

    for i, planet in enumerate(seq):
        t_P[i] = epoch(x[0] + sum(T[0:i]))
        r_P[i], v_P[i] = planet.eph(t_P[i])
        plot_planet(ax,
                    planet,
                    t0=t_P[i],
                    color=(0.8, 0.6, 0.8),
                    legend=True,
                    units=AU)

    # 3 - We start with the first leg
    theta = 2 * pi * x[1]
    phi = acos(2 * x[2] - 1) - pi / 2

    Vinfx = x[3] * cos(phi) * cos(theta)
    Vinfy = x[3] * cos(phi) * sin(theta)
    Vinfz = x[3] * sin(phi)

    v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])]
    r, v = propagate_lagrangian(r_P[0], v0, x[4] * T[0] * DAY2SEC,
                                seq[0].mu_central_body)
    plot_kepler(ax,
                r_P[0],
                v0,
                x[4] * T[0] * DAY2SEC,
                seq[0].mu_central_body,
                N=100,
                color='b',
                legend=False,
                units=AU)

    # Lambert arc to reach seq[1]
    dt = (1 - x[4]) * T[0] * DAY2SEC
    l = lambert_problem(r, r_P[1], dt, seq[0].mu_central_body)
    plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU)
    v_end_l = l.get_v2()[0]
    v_beg_l = l.get_v1()[0]

    # First DSM occuring at time nu1*T1
    DV[0] = norm([a - b for a, b in zip(v_beg_l, v)])

    # 4 - And we proceed with each successive leg
    for i in range(1, n):
        # Fly-by
        v_out = fb_prop(v_end_l, v_P[i], x[7 + (i - 1) * 4] * seq[i].radius,
                        x[6 + (i - 1) * 4], seq[i].mu_self)
        # s/c propagation before the DSM
        r, v = propagate_lagrangian(r_P[i], v_out,
                                    x[8 + (i - 1) * 4] * T[i] * DAY2SEC,
                                    seq[0].mu_central_body)
        plot_kepler(ax,
                    r_P[i],
                    v_out,
                    x[8 + (i - 1) * 4] * T[i] * DAY2SEC,
                    seq[0].mu_central_body,
                    N=100,
                    color='b',
                    legend=False,
                    units=AU)
        # Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
        dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC
        l = lambert_problem(r, r_P[i + 1], dt, seq[0].mu_central_body)
        plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]
        # DSM occurring at time nu2*T2
        DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
    return ax
Esempio n. 32
0
def _get_score_data_incipit(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
    """
	This method returns the data needed to compute the score of a 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

    #2 - We compute the epochs and ephemerides of the planetary encounters
    ep_list = list([None] * nlegs)
    t_P = list([None] * nlegs)
    r_P = list([None] * nlegs)
    v_P = list([None] * nlegs)
    DV = list([None] * nlegs)

    for i, planet in enumerate(seq):
        ep_list[i] = x[0] + sum(T[:i + 1])
        t_P[i] = epoch(x[0] + sum(T[:i + 1]))
        r_P[i], v_P[i] = 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, common_mu, False, False)

    #Lambert arc to reach seq[1]
    v_end_l = l.get_v2()[0]
    v_beg_l = l.get_v1()[0]

    #init lists for fly-by parameters
    vinf_list = []
    rp_list = []
    beta_list = []

    #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, nlegs):
        #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)

        vinf_list.append([a - b for a, b in zip(v_end_l, v_P[i - 1])])
        rp_list.append(x[1 + 4 * i] * seq[i - 1].radius)
        beta_list.append(x[4 * i])

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

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

    vinf_list.append([a - b for a, b in zip(v_end_l, v_P[-1])])
    rp_list.append(None)
    beta_list.append(None)
    return zip(ep_list, seq, vinf_list, rp_list, beta_list)
Esempio n. 33
0
def _mga_part_plot_old(self, x):
    """
    Plots the trajectory represented by the decision vector x

    Example::

      prob.plot(x)
    """
    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler
    from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC
    from math import pi, acos, cos, sin
    from scipy.linalg import norm

    mpl.rcParams['legend.fontsize'] = 10
    fig = plt.figure()
    ax = fig.gca(projection='3d', aspect='equal')
    ax.scatter(0, 0, 0, color='y')

    JR = 71492000.0
    legs = len(x) / 4
    seq = self.get_sequence()
    common_mu = seq[0].mu_central_body
    start_mjd2000 = self.t0.mjd2000

    # 1 -  we 'decode' the chromosome recording the various times of flight
    # (days) in the list T
    T = x[3::4]

    # 2 - We compute the epochs and ephemerides of the planetary encounters
    t_P = list([None] * (legs + 1))
    r_P = list([None] * (legs + 1))
    v_P = list([None] * (legs + 1))

    for i, planet in enumerate(seq):
        t_P[i] = epoch(start_mjd2000 + sum(T[:i]))
        r_P[i], v_P[i] = planet.eph(t_P[i])
        plot_planet(ax,
                    planet,
                    t0=t_P[i],
                    color=(0.8, 0.6, 0.8),
                    legend=True,
                    units=JR)

    v_end_l = [a + b for a, b in zip(v_P[0], self.vinf_in)]
    # 4 - And we iterate on the legs
    for i in range(0, legs):
        # Fly-by
        v_out = fb_prop(v_end_l, v_P[i], x[1 + 4 * i] * seq[i - 1].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)
        plot_kepler(ax,
                    r_P[i],
                    v_out,
                    x[4 * i + 2] * T[i] * DAY2SEC,
                    common_mu,
                    N=500,
                    color='b',
                    legend=False,
                    units=JR)
        # 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)
        plot_lambert(ax, l, sol=0, color='r', legend=False, units=JR, N=500)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]
    plt.show()
    return ax
Esempio n. 34
0
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;
Esempio n. 35
0
def _mga_incipit_plot_old(self, x, plot_leg_0=False):
    """
    Plots the trajectory represented by the decision vector x

    Example::

      prob.plot(x)
    """
    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler
    from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC
    from math import pi, acos, cos, sin
    from scipy.linalg import norm

    mpl.rcParams['legend.fontsize'] = 10
    fig = plt.figure()
    ax = fig.gca(projection='3d', aspect='equal')
    ax.scatter(0, 0, 0, color='y')

    JR = 71492000.0
    legs = len(x) / 4
    seq = self.get_sequence()
    common_mu = seq[0].mu_central_body

    # 1 -  we 'decode' the chromosome recording the various times of flight
    # (days) in the list T
    T = x[3::4]

    # 2 - We compute the epochs and ephemerides of the planetary encounters
    t_P = list([None] * legs)
    r_P = list([None] * legs)
    v_P = list([None] * legs)
    DV = list([None] * legs)

    for i, planet in enumerate(seq):
        t_P[i] = epoch(x[0] + sum(T[:i + 1]))
        r_P[i], v_P[i] = planet.eph(t_P[i])
        plot_planet(ax, planet, t0=t_P[i], color=(
            0.8, 0.6, 0.8), legend=True, units = JR)

    # 3 - We start with the first leg: a lambert arc
    theta = 2 * pi * x[1]
    phi = acos(2 * x[2] - 1) - pi / 2
    # phi close to zero is in the moon orbit plane injection
    r = [cos(phi) * sin(theta), cos(phi) * cos(theta), sin(phi)]
    r = [JR * 1000 * d for d in r]

    l = lambert_problem(r, r_P[0], T[0] * DAY2SEC, common_mu, False, False)
    if (plot_leg_0):
        plot_lambert(ax, l, sol=0, color='k', legend=False, units=JR, N=500)

    # Lambert arc to reach seq[1]
    v_end_l = l.get_v2()[0]
    v_beg_l = l.get_v1()[0]

    # 4 - And we proceed with each successive leg
    for i in range(1, 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)
        plot_kepler(ax,
                    r_P[i - 1],
                    v_out,
                    x[4 * i + 2] * T[i] * DAY2SEC,
                    common_mu,
                    N=500,
                    color='b',
                    legend=False,
                    units=JR)
        # 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)
        plot_lambert(ax, l, sol=0, color='r', legend=False, units=JR, N=500)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]
    plt.show()
    return ax
Esempio n. 36
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
Esempio n. 37
0
def _get_lt_problem(self,x,n_seg=[10,10], high_fidelity=True):
	"""
	This method returns the equivalent low-thrust problem of an incipit
	"""
	from PyKEP import epoch, lambert_problem, DAY2SEC, fb_prop, propagate_lagrangian
	from PyGMO import population
	from math import pi, acos,cos,sin,sqrt, exp
	from scipy.linalg import norm
	
	retval = []
	#1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T for convenience
	T = x[3::4]
	n_legs = len(x)/4
	seq = self.get_sequence()
	common_mu = seq[0].mu_central_body
	#2 - We compute the 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))
	
	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])

	#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,common_mu, False, False)

	#Lambert arc to reach seq[1]
	v_end_l = l.get_v2()[0]
	v_beg_l = l.get_v1()[0]
	
	#We start appending in the lt chromosome (see mga_incipit_lt)
	retval.append(theta)
	retval.append(phi)
	
	#First DSM occuring at the very beginning (will be cancelled by the optimizer)
	DV[0] = abs(norm(v_beg_l) - 3400)
	
	#Start of the first lt leg encoding 
	retval.append(T[0])
	retval.append(exp(-DV[0]/9.80665/2000)*2000) #Tsiolkowsky
	retval.extend(v_beg_l)
	retval.extend([a-b for a,b in zip(v_end_l,v_P[0])])

	#4 - And we proceed with each successive leg
	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)
		#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]
		#DSM occuring at time nu2*T2
		DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])
		
		#lt encoding of all legs
		retval.append(T[i])
		retval.append(exp(-sum(DV[:i+1])/9.80665/2000)*2000) #Tsiolkowsky
		retval.extend([a-b for a,b in zip(v_out,v_P[i-1])])
		if i != n_legs-1:
			retval.extend([a-b for a,b in zip(v_end_l,v_P[i])])
	
	retval = retval + [0]*sum(n_seg)*3
	prob = mga_incipit_lt(high_fidelity=high_fidelity,seq=seq, n_seg = n_seg,tf = epoch(x[0]+sum(T)), vf = [a-b for a,b in zip(v_end_l,v_P[i])])
	# solves the problem of chemical trajectories wanting higher launch dv
	ub = list(prob.ub)
	lb = list(prob.lb)
	ub[4:7] = [5000,5000,5000]
	lb[4:7] = [-5000,-5000,-5000]
	prob.set_bounds(lb, ub)
	pop = population(prob)
	pop.push_back(retval)
	return (prob,pop)  
Esempio n. 38
0
    def plot(self, x):
        """
		Plots the trajectory represented by the decision vector x
		
		Example::
		
		  prob.plot(x)
		"""
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler

        mpl.rcParams['legend.fontsize'] = 10
        fig = plt.figure()
        ax = fig.gca(projection='3d')
        ax.scatter(0, 0, 0, color='y')

        #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
        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))

        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])
            plot_planet(ax,
                        planet,
                        t0=t_P[i],
                        color=(0.8, 0.6, 0.8),
                        legend=True,
                        units=JR)

        #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)
        plot_lambert(ax, l, sol=0, color='k', legend=False, units=JR, N=500)

        #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[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)
            plot_kepler(ax,
                        r_P[i - 1],
                        v_out,
                        x[4 * i + 2] * T[i] * DAY2SEC,
                        self.common_mu,
                        N=500,
                        color='b',
                        legend=False,
                        units=JR)
            #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)
            plot_lambert(ax,
                         l,
                         sol=0,
                         color='r',
                         legend=False,
                         units=JR,
                         N=500)
            v_end_l = l.get_v2()[0]
            v_beg_l = l.get_v1()[0]
            #DSM occuring at time nu2*T2
            DV[i] = norm([a - b for a, b in zip(v_beg_l, v)])
        plt.show()
        return ax
Esempio n. 39
0
    def AIO(self,x, doplot = True, doprint = True, rtrn_desc = True, dists_class = None):
        P = doprint
        plots_datas = list([None] * (self.__n))
        PLDists = list([None] * (self.__n-1))
        FBDates = list([None] * (self.__n-1))

        #1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
        T = list([0]*(self.__n))
        #a[-i] = x[-1-(i-1)*4]
        for i in xrange(self.__n-1):
            j = i+1;
            T[-j] = (x[5] - sum(T[-(j-1):])) * x[-1-(j-1)*4]
        T[0] = x[5] - sum(T)

        #2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n+1))
        r_P = list([None] * (self.__n+1))
        v_P = list([None] * (self.__n+1))
        DV = list([None] * (self.__n+1))

        for i,planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i],v_P[i] = self.seq[i].eph(t_P[i])

        #3 - We start with the first leg
        if P: print "First Leg:        " + self.seq[0].name + " to " + self.seq[1].name

        theta = 2*pi*x[1]
        phi = acos(2*x[2]-1)-pi/2

        Vinfx = x[3]*cos(phi)*cos(theta)
        Vinfy = x[3]*cos(phi)*sin(theta)
        Vinfz = x[3]*sin(phi)

        if P:
            print("Departure:        " + str(t_P[0]) + " (" + str(t_P[0].mjd2000) + " mjd2000) \n"
                  "Duration:         " + str(T[0]) + " days\n"
                  "VINF:             " + str(x[3] / 1000) + " km/sec\n"
                  "C3:               " + str((x[3] / 1000)**2) + " km^2/s^2")

        v0 = [a+b for a,b in zip(v_P[0], [Vinfx,Vinfy,Vinfz])]
        r,v = propagate_lagrangian(r_P[0], v0, x[4]*T[0]*DAY2SEC, MU_SUN)
        if P: print "DSM after         " + str(x[4]*T[0]) + " days"

        #Lambert arc to reach seq[1]
        dt = (1-x[4])*T[0]*DAY2SEC
        l = lambert_problem(r, r_P[1], dt, MU_SUN)
        v_end_l = l.get_v2()[0]
        v_beg_l = l.get_v1()[0]

        # Append data needed for potential plot generation
        plots_datas[0] = [v0, x[4]*T[0]*DAY2SEC, l]

        #First DSM occuring at time nu1*T1
        DV[0] = norm([a-b for a,b in zip(v_beg_l,v)])
        if P: print "DSM magnitude:    " + str(DV[0]) + "m/s"

        #4 - And we proceed with each successive leg
        for i in range(1,self.__n):
            if P:
                print("\nleg no.           " + str(i+1) + ": " + self.seq[i].name + " to " + self.seq[i+1].name + "\n"
                      "Duration:         " + str(T[i]) + "days")

            #Fly-by
            v_out = fb_prop(v_end_l, v_P[i], x[7+(i-1)*4]*self.seq[i].radius, x[6+(i-1)*4], self.seq[i].mu_self)
            PLDists[i-1] = (x[7+(i-1)*4] -1)*self.seq[i].radius/1000.
            FBDates[i-1] = t_P[i]

            if P:
                print("Fly-by epoch:     " + str(t_P[i]) + " (" + str(t_P[i].mjd2000) + " mjd2000) \n"
                      "Fly-by radius:    " + str(x[7+(i-1)*4]) + " planetary radii\n"
                      "Fly-by distance:  " + str( (x[7+(i-1)*4] -1)*self.seq[i].radius/1000.) + " km")

            #s/c propagation before the DSM
            r,v = propagate_lagrangian(r_P[i], v_out, x[8+(i-1)*4]*T[i]*DAY2SEC, MU_SUN)
            if P: print "DSM after         " + str(x[8+(i-1)*4]*T[i]) + " days"

            #Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
            dt = (1-x[8+(i-1)*4])*T[i]*DAY2SEC
            l = lambert_problem(r, r_P[i+1], dt, MU_SUN)
            v_end_l = l.get_v2()[0]
            v_beg_l = l.get_v1()[0]

            # Append data needed for potential plot generation
            plots_datas[i] = [v_out, x[8+(i-1)*4]*T[i]*DAY2SEC, l]

            #DSM occuring at time nu2*T2
            DV[i] = norm([a-b for a,b in zip(v_beg_l,v)])
            if P: print "DSM magnitude:    " + str(DV[i]) + "m/s"

        #Last Delta-v
        if P:  print "\nArrival at " + self.seq[-1].name
        DV[-1] = norm([a-b for a,b in zip(v_end_l,v_P[-1])])

        if P:
            print("Arrival Vinf:     " + str(DV[-1]) + "m/s  \n"
                  "Total mission time: " + str(sum(T)/365.25) + " years (" + str(sum(T)) + " days) \n"
                  "DSMs mag:         " + str(sum(DV[:-1])) + "m/s  \n"
                  "Entry Vel:        " + str(sqrt(2*(0.5*(DV[-1])**2 + 61933310.95))) + "m/s  \n"
                  "Entry epoch:      " + str(epoch(t_P[0].mjd2000 + sum(T))) )

        if doplot:
            import matplotlib as mpl
            from mpl_toolkits.mplot3d import Axes3D
            import matplotlib.pyplot as plt
            from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler

            mpl.rcParams['legend.fontsize'] = 10
            fig = plt.figure(figsize=(8, 8), dpi=80)
            ax = fig.gca(projection='3d')
            ax.scatter(0,0,0, color='y')

            for i,planet in enumerate(self.seq):
                plot_planet(ax, planet, t0=t_P[i], color=(0.8,0.6,0.8), legend=True, units = AU)

            for i, tpl in enumerate(plots_datas):
                plot_kepler(ax, r_P[i], tpl[0], tpl[1], MU_SUN ,N = 100, color='b', legend=False, units = AU)
                plot_lambert(ax, tpl[2], sol = 0, color='r', legend=False, units = AU)

            fig.tight_layout()
            plt.show()

        if dists_class is not None:
            for i, tpl in enumerate(plots_datas):
                dists_class.positions_kepler(r_P[i], tpl[0], tpl[1], MU_SUN ,index = 2*i)
                dists_class.positions_lambert(tpl[2], sol = 0, index = 2*(i+.5))
            dists_class.set_launch_epoch(t_P[0].mjd2000)
            return dists_class

        if rtrn_desc:
            import numpy as np
            from math import atan2

            desc = dict()
            for i in range(len(x)):
                desc[i] = x[i]

            theta = 2*pi*x[1]
            phi = acos(2*x[2]-1)-pi/2

            axtl = 23.43929*DEG2RAD # Earth axial tlit
            mactran = np.matrix([ [1,         0,          0],
                                  [0, cos(axtl), -sin(axtl)],
                                  [0, sin(axtl),  cos(axtl)] ]) # Macierz przejscia z helio do ECI

            macdegs = np.matrix([ [cos(phi)*cos(theta)],
                                  [cos(phi)*sin(theta)],
                                  [sin(phi)] ])
            aaa = mactran.dot(macdegs)
            theta_earth = atan2(aaa[1,0], aaa[0,0])    # Rektascensja asym
            phi_earth = asin(aaa[2,0])                 # Deklinacja asym
            desc['RA'] = 360+RAD2DEG*theta_earth
            desc['DEC'] = phi_earth*RAD2DEG

            desc['Ldate'] = str(t_P[0])
            desc['C3'] = (x[3] / 1000)**2

            desc['dVmag'] = sum(DV[:-1])
            desc['VinfRE'] = DV[-1]
            desc['VRE'] = (DV[-1]**2 + 2*61933310.95)**.5
            desc['REDate'] = str(epoch(t_P[0].mjd2000 + sum(T)))

            for i in range(1,self.__n):
                desc[self.seq[i].name[0].capitalize()+'Dist'] = PLDists[i-1]
                desc[self.seq[i].name[0].capitalize()+'FBDate'] = str(FBDates[i-1])

            return desc
Esempio n. 40
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))
Esempio n. 41
0
def _get_score_data_incipit(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
	"""
	This method returns the data needed to compute the score of a 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
	
	#2 - We compute the epochs and ephemerides of the planetary encounters
	ep_list = list([None] * nlegs)
	t_P = list([None] * nlegs)
	r_P = list([None] * nlegs)
	v_P = list([None] * nlegs)
	DV  = list([None] * nlegs)
	
	for i,planet in enumerate(seq):
		ep_list[i] = x[0]+sum(T[:i+1])
		t_P[i] = epoch(x[0]+sum(T[:i+1]))
		r_P[i],v_P[i] = 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,common_mu, False, False)

	#Lambert arc to reach seq[1]
	v_end_l = l.get_v2()[0]
	v_beg_l = l.get_v1()[0]

	#init lists for fly-by parameters
	vinf_list = []
	rp_list = []
	beta_list = []

	#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,nlegs):
		#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)
		
		vinf_list.append( [a-b for a,b in zip(v_end_l,v_P[i-1])] )
		rp_list.append(x[1+4*i]*seq[i-1].radius)
		beta_list.append(x[4*i])

		#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)
		
		#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]
		
        vinf_list.append([a-b for a,b in zip(v_end_l,v_P[-1])])
        rp_list.append(None)
        beta_list.append(None)
	return zip(ep_list, seq, vinf_list, rp_list, beta_list)
Esempio n. 42
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()