Esempio n. 1
0
		def _compute_constraints_impl(self,x):
			from PyKEP import epoch, AU, EARTH_VELOCITY, fb_con
			from PyKEP.sims_flanagan import leg, sc_state
			from numpy.linalg import norm
			from math import sqrt, asin, acos

			#Ephemerides
			t_E = epoch(x[0])
			t_V = epoch(x[0] + x[1])
			t_M = epoch(x[0] + x[1] + x[9])
			rE, vE = self.__earth.eph(t_E)
			rV, vV = self.__venus.eph(t_V)
			rM, vM = self.__mercury.eph(t_M)

			#First Leg
			v = [a+b for a,b in zip(vE,x[3:6])]
			x0 = sc_state(rE,v,self.__sc.mass)
			v = [a+b for a,b in zip(vV,x[6:9])]
			xe = sc_state(rV, v ,x[2])
			self.__leg1.set(t_E,x0,x[-3 * (self.__nseg1 + self.__nseg2):-self.__nseg2 * 3],t_V,xe)

			#Second leg
			v = [a+b for a,b in zip(vV,x[11:14])]
			x0 = sc_state(rV,v,x[2])
			v = [a+b for a,b in zip(vM,x[14:17])]
			xe = sc_state(rM, v ,x[10])
			self.__leg2.set(t_E,x0,x[(-3 * self.__nseg2):],t_V,xe)

			#Defining the costraints
			#departure
			v_dep_con = (x[3]  * x[3]  + x[4]  * x[4]  + x[5]  * x[5]  - self.__Vinf_dep * self.__Vinf_dep) / (EARTH_VELOCITY * EARTH_VELOCITY)
			#arrival
			v_arr_con = (x[14] * x[14] + x[15] * x[15] + x[16] * x[16] - self.__Vinf_arr * self.__Vinf_arr) / (EARTH_VELOCITY * EARTH_VELOCITY)
			#fly-by at Venus
			DV_eq, alpha_ineq = fb_con(x[6:9],x[11:14],self.__venus)

			#Assembling the constraints
			retval = list(self.__leg1.mismatch_constraints() + self.__leg2.mismatch_constraints()) + [DV_eq] + list(self.__leg1.throttles_constraints() + self.__leg2.throttles_constraints()) + [v_dep_con] + [v_arr_con] + [alpha_ineq]

			#We then scale all constraints to non dimensional values
			#leg 1
			retval[0] /= AU
			retval[1] /= AU
			retval[2] /= AU
			retval[3] /= EARTH_VELOCITY
			retval[4] /= EARTH_VELOCITY
			retval[5] /= EARTH_VELOCITY
			retval[6] /= self.__sc.mass
			#leg 2
			retval[7] /= AU
			retval[8] /= AU
			retval[9] /= AU
			retval[10] /= EARTH_VELOCITY
			retval[11] /= EARTH_VELOCITY
			retval[12] /= EARTH_VELOCITY
			retval[13] /= self.__sc.mass
			#fly-by at Venus
			retval[14] /= (EARTH_VELOCITY*EARTH_VELOCITY)

			return retval
Esempio n. 2
0
	def _compute_constraints_impl(self,x):
		# 1 - We decode the chromosome extracting the time of flights
		T = list([0]*(self.__n_legs))
		for i in range(self.__n_legs):
			T[i] = x[1+i*8]
			
		#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))
		
		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 iterate through legs to compute mismatches and throttles constraints
		ceq = list()
		cineq = list()
		m0 = self.__sc.mass
		for i in range(self.__n_legs):
			#First Leg
			v = [a+b for a,b in zip(v_P[i],x[(3 + i * 8):(6 + i * 8)])]
			x0 = sc_state(r_P[i],v,m0)
			v = [a+b for a,b in zip(v_P[i+1],x[(6 + i * 8):(9 + i * 8)])]
			xe = sc_state(r_P[i+1], v ,x[2 + i * 8])
			throttles = x[(1 + 8*self.__n_legs + 3*sum(self.__n_seg[:i])):(1 + 8*self.__n_legs + 3*sum(self.__n_seg[:i])+3*self.__n_seg[i])]
			self.__leg.set(t_P[i],x0,throttles,t_P[i+1],xe)
			#update mass!
			m0 = x[2+8*i]
			ceq.extend(self.__leg.mismatch_constraints())
			cineq.extend(self.__leg.throttles_constraints())

		#Adding the boundary constraints
		#departure
		v_dep_con = (x[3] ** 2  + x[4] ** 2  + x[5] **2  - self.__vinf_dep ** 2) / (EARTH_VELOCITY**2)
		#arrival
		v_arr_con = (x[6 + (self.__n_legs-1)*8]**2 + x[7+ (self.__n_legs-1)*8]**2 + x[8+ (self.__n_legs-1)*8]**2 - self.__vinf_arr ** 2) / (EARTH_VELOCITY**2)
		cineq.append(v_dep_con*100)
		cineq.append(v_arr_con*100)

		#We add the fly-by constraints
		for i in range(self.__n_legs-1):
			DV_eq, alpha_ineq = fb_con(x[6 + i*8:9 + i*8],x[11+ i * 8:14+ i * 8],self.seq[i+1])
			ceq.append(DV_eq / (EARTH_VELOCITY**2))
			cineq.append(alpha_ineq)

		#Making the mismatches non dimensional
		for i in range(self.__n_legs):
			ceq[0+i*7] /= AU
			ceq[1+i*7] /= AU
			ceq[2+i*7] /= AU
			ceq[3+i*7] /= EARTH_VELOCITY
			ceq[4+i*7] /= EARTH_VELOCITY
			ceq[5+i*7] /= EARTH_VELOCITY
			ceq[6+i*7] /= self.__sc.mass
			
		#We assemble the constraint vector
		retval = list()
		retval.extend(ceq)
		retval.extend(cineq)

		return retval
Esempio n. 3
0
	def _compute_constraints_impl(self,x):
	  
		# 1 - We decode the chromosome extracting the time of flights
		T = list([0]*(self.__n_legs))
		for i in range(self.__n_legs):
			T[i] = x[2+i*8]
			
		#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))
		
		for i,planet in enumerate(self.seq):
			t_P[i+1] = epoch(self.tf - sum(T[i+1:]))
			r_P[i+1],v_P[i+1] = self.seq[i].eph(t_P[i+1])
			
		#And we insert a fake planet simulating the starting position
		t_P[0] = epoch(self.tf - sum(T))
		theta = x[0]
		phi = x[1]
		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]
		r_P[0] = r
		v_P[0] = x[4:7]
		
		#3 - We iterate through legs to compute mismatches and throttles constraints
		ceq = list()
		cineq = list()
		m0 = self.__sc.mass
		for i in range(self.__n_legs):

			if i!=0: #First Leg
				v = [a+b for a,b in zip(v_P[i],x[(4 + i * 8):(7 + i * 8)])]
			else:
				v = v_P[i]
			x0 = sc_state(r_P[i],v,m0)
			v = [a+b for a,b in zip(v_P[i+1],x[(7 + i * 8):(10 + i * 8)])]
			if (i==self.__n_legs-1): #Last leg
				v = [a+b for a,b in zip(v_P[i+1],self.vf)]
			xe = sc_state(r_P[i+1], v ,x[3+8*i])
			throttles = x[(8*self.__n_legs-1 + 3*sum(self.__n_seg[:i])):(8*self.__n_legs-1 + 3*sum(self.__n_seg[:i])+3*self.__n_seg[i])]
			self.__leg.set(t_P[i],x0,throttles,t_P[i+1],xe)

			#update mass!
			m0 = x[3+8*i]
			ceq.extend(self.__leg.mismatch_constraints())
			cineq.extend(self.__leg.throttles_constraints())
			#raise Exception    

		#Adding the boundary constraints
		#departure
		v_dep_con = (x[4] ** 2  + x[5] ** 2  + x[6] **2  - 3400.0 ** 2) / (3400.0**2)
		#arrival
		ceq.append(v_dep_con)

		#We add the fly-by constraints
		for i in range(self.__n_legs-1):
			DV_eq, alpha_ineq = fb_con(x[7 + i*8:10 + i*8],x[12+ i * 8:15+ i * 8],self.seq[i])
			ceq.append(DV_eq / (3400.0**2))
			cineq.append(alpha_ineq)

		#Making the mismatches non dimensional
		for i in range(self.__n_legs):
			ceq[0+i*7] /= JR*1000
			ceq[1+i*7] /= JR*1000
			ceq[2+i*7] /= JR*1000
			ceq[3+i*7] /= 3400
			ceq[4+i*7] /= 3400
			ceq[5+i*7] /= 3400
			ceq[6+i*7] /= 1000
			
		#We assemble the constraint vector
		retval = list()
		retval.extend(ceq)
		retval.extend(cineq)

		return retval
Esempio n. 4
0
    def _compute_constraints_impl(self, x):
        # 1 - We decode the chromosome extracting the time of flights
        T = list([0] * (self.__n_legs))
        for i in range(self.__n_legs):
            T[i] = x[1 + i * 8]

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

        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 iterate through legs to compute mismatches and throttles constraints
        ceq = list()
        cineq = list()
        m0 = self.__sc.mass
        for i in range(self.__n_legs):
            #First Leg
            v = [a + b for a, b in zip(v_P[i], x[(3 + i * 8):(6 + i * 8)])]
            x0 = sc_state(r_P[i], v, m0)
            v = [a + b for a, b in zip(v_P[i + 1], x[(6 + i * 8):(9 + i * 8)])]
            xe = sc_state(r_P[i + 1], v, x[2 + i * 8])
            throttles = x[(1 + 8 * self.__n_legs + 3 * sum(self.__n_seg[:i])):(
                1 + 8 * self.__n_legs + 3 * sum(self.__n_seg[:i]) +
                3 * self.__n_seg[i])]
            self.__leg.set(t_P[i], x0, throttles, t_P[i + 1], xe)
            #update mass!
            m0 = x[2 + 8 * i]
            ceq.extend(self.__leg.mismatch_constraints())
            cineq.extend(self.__leg.throttles_constraints())

        #Adding the boundary constraints
        #departure
        v_dep_con = (x[3]**2 + x[4]**2 + x[5]**2 -
                     self.__vinf_dep**2) / (EARTH_VELOCITY**2)
        #arrival
        v_arr_con = (x[6 +
                       (self.__n_legs - 1) * 8]**2 + x[7 +
                                                       (self.__n_legs - 1) * 8]
                     **2 + x[8 + (self.__n_legs - 1) * 8]**2 -
                     self.__vinf_arr**2) / (EARTH_VELOCITY**2)
        cineq.append(v_dep_con * 100)
        cineq.append(v_arr_con * 100)

        #We add the fly-by constraints
        for i in range(self.__n_legs - 1):
            DV_eq, alpha_ineq = fb_con(x[6 + i * 8:9 + i * 8],
                                       x[11 + i * 8:14 + i * 8],
                                       self.seq[i + 1])
            ceq.append(DV_eq / (EARTH_VELOCITY**2))
            cineq.append(alpha_ineq)

        #Making the mismatches non dimensional
        for i in range(self.__n_legs):
            ceq[0 + i * 7] /= AU
            ceq[1 + i * 7] /= AU
            ceq[2 + i * 7] /= AU
            ceq[3 + i * 7] /= EARTH_VELOCITY
            ceq[4 + i * 7] /= EARTH_VELOCITY
            ceq[5 + i * 7] /= EARTH_VELOCITY
            ceq[6 + i * 7] /= self.__sc.mass

        #We assemble the constraint vector
        retval = list()
        retval.extend(ceq)
        retval.extend(cineq)

        return retval
Esempio n. 5
0
    def _compute_constraints_impl(self, x):

        # 1 - We decode the chromosome extracting the time of flights
        T = list([0] * (self.__n_legs))
        for i in range(self.__n_legs):
            T[i] = x[2 + i * 8]

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

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

        #And we insert a fake planet simulating the starting position
        t_P[0] = epoch(self.tf - sum(T))
        theta = x[0]
        phi = x[1]
        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]
        r_P[0] = r
        v_P[0] = x[4:7]

        #3 - We iterate through legs to compute mismatches and throttles constraints
        ceq = list()
        cineq = list()
        m0 = self.__sc.mass
        for i in range(self.__n_legs):

            if i != 0:  #First Leg
                v = [a + b for a, b in zip(v_P[i], x[(4 + i * 8):(7 + i * 8)])]
            else:
                v = v_P[i]
            x0 = sc_state(r_P[i], v, m0)
            v = [
                a + b for a, b in zip(v_P[i + 1], x[(7 + i * 8):(10 + i * 8)])
            ]
            if (i == self.__n_legs - 1):  #Last leg
                v = [a + b for a, b in zip(v_P[i + 1], self.vf)]
            xe = sc_state(r_P[i + 1], v, x[3 + 8 * i])
            throttles = x[(8 * self.__n_legs - 1 + 3 * sum(self.__n_seg[:i])):(
                8 * self.__n_legs - 1 + 3 * sum(self.__n_seg[:i]) +
                3 * self.__n_seg[i])]
            self.__leg.set(t_P[i], x0, throttles, t_P[i + 1], xe)

            #update mass!
            m0 = x[3 + 8 * i]
            ceq.extend(self.__leg.mismatch_constraints())
            cineq.extend(self.__leg.throttles_constraints())
            #raise Exception

        #Adding the boundary constraints
        #departure
        v_dep_con = (x[4]**2 + x[5]**2 + x[6]**2 - 3400.0**2) / (3400.0**2)
        #arrival
        ceq.append(v_dep_con)

        #We add the fly-by constraints
        for i in range(self.__n_legs - 1):
            DV_eq, alpha_ineq = fb_con(x[7 + i * 8:10 + i * 8],
                                       x[12 + i * 8:15 + i * 8], self.seq[i])
            ceq.append(DV_eq / (3400.0**2))
            cineq.append(alpha_ineq)

        #Making the mismatches non dimensional
        for i in range(self.__n_legs):
            ceq[0 + i * 7] /= JR * 1000
            ceq[1 + i * 7] /= JR * 1000
            ceq[2 + i * 7] /= JR * 1000
            ceq[3 + i * 7] /= 3400
            ceq[4 + i * 7] /= 3400
            ceq[5 + i * 7] /= 3400
            ceq[6 + i * 7] /= 1000

        #We assemble the constraint vector
        retval = list()
        retval.extend(ceq)
        retval.extend(cineq)

        return retval
Esempio n. 6
0
        def _compute_constraints_impl(self, x):
            from PyKEP import epoch, AU, EARTH_VELOCITY, fb_con
            from PyKEP.sims_flanagan import leg, sc_state
            from numpy.linalg import norm
            from math import sqrt, asin, acos

            #Ephemerides
            t_E = epoch(x[0])
            t_V = epoch(x[0] + x[1])
            t_M = epoch(x[0] + x[1] + x[9])
            rE, vE = self.__earth.eph(t_E)
            rV, vV = self.__venus.eph(t_V)
            rM, vM = self.__mercury.eph(t_M)

            #First Leg
            v = [a + b for a, b in zip(vE, x[3:6])]
            x0 = sc_state(rE, v, self.__sc.mass)
            v = [a + b for a, b in zip(vV, x[6:9])]
            xe = sc_state(rV, v, x[2])
            self.__leg1.set(
                t_E, x0,
                x[-3 * (self.__nseg1 + self.__nseg2):-self.__nseg2 * 3], t_V,
                xe)

            #Second leg
            v = [a + b for a, b in zip(vV, x[11:14])]
            x0 = sc_state(rV, v, x[2])
            v = [a + b for a, b in zip(vM, x[14:17])]
            xe = sc_state(rM, v, x[10])
            self.__leg2.set(t_E, x0, x[(-3 * self.__nseg2):], t_V, xe)

            #Defining the constraints
            #departure
            v_dep_con = (x[3] * x[3] + x[4] * x[4] + x[5] * x[5] -
                         self.__Vinf_dep * self.__Vinf_dep) / (EARTH_VELOCITY *
                                                               EARTH_VELOCITY)
            #arrival
            v_arr_con = (x[14] * x[14] + x[15] * x[15] + x[16] * x[16] -
                         self.__Vinf_arr * self.__Vinf_arr) / (EARTH_VELOCITY *
                                                               EARTH_VELOCITY)
            #fly-by at Venus
            DV_eq, alpha_ineq = fb_con(x[6:9], x[11:14], self.__venus)

            #Assembling the constraints
            retval = list(self.__leg1.mismatch_constraints() +
                          self.__leg2.mismatch_constraints()) + [
                              DV_eq
                          ] + list(self.__leg1.throttles_constraints() +
                                   self.__leg2.throttles_constraints()) + [
                                       v_dep_con
                                   ] + [v_arr_con] + [alpha_ineq]

            #We then scale all constraints to non-dimensional values
            #leg 1
            retval[0] /= AU
            retval[1] /= AU
            retval[2] /= AU
            retval[3] /= EARTH_VELOCITY
            retval[4] /= EARTH_VELOCITY
            retval[5] /= EARTH_VELOCITY
            retval[6] /= self.__sc.mass
            #leg 2
            retval[7] /= AU
            retval[8] /= AU
            retval[9] /= AU
            retval[10] /= EARTH_VELOCITY
            retval[11] /= EARTH_VELOCITY
            retval[12] /= EARTH_VELOCITY
            retval[13] /= self.__sc.mass
            #fly-by at Venus
            retval[14] /= (EARTH_VELOCITY * EARTH_VELOCITY)

            return retval