def __init__(self, mass=1000, Tmax=0.1, Isp=2500, Vinf=3.0, nseg=20): # First we call the constructor for the base PyGMO problem # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(mga_lt_earth_mars_sundmann, self).__init__(7 + nseg * 3, 0, 1, 9 + nseg, nseg + 1, 1e-4) # We then define some data members (we use the double underscore to # indicate they are private) from PyKEP import MU_SUN, AU from PyKEP.planets import jpl_lp from PyKEP.sims_flanagan import spacecraft, leg_s self.__earth = jpl_lp('earth') self.__mars = jpl_lp('jupiter') self.__sc = spacecraft(mass, Tmax, Isp) self.__Vinf = Vinf * 1000 # here we construct the trajectory leg in Sundman's variable t = # (r/10AU)^1.5 s self.__leg = leg_s(nseg, 1.0 / (100 * AU) ** 1.0, 1.0) self.__leg.set_mu(MU_SUN) self.__leg.set_spacecraft(self.__sc) # This is needed to use the plotting function plot_sf_leg self.__leg.high_fidelity = False self.__nseg = nseg # The bounds on Sundman's variable can be evaluated considering # circular orbits at r=1AU and r=0.7AU (for example) self.set_bounds([5000, 2400, 10000, self.__sc.mass / 10, -self.__Vinf, -self.__Vinf, -self.__Vinf] + [-1] * 3 * nseg, [8000, 2500, 150000, self.__sc.mass, self.__Vinf, self.__Vinf, self.__Vinf] + [1] * 3 * nseg)
def run_example2(): import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from PyKEP import epoch, DAY2SEC, AU, MU_SUN, lambert_problem from PyKEP.planets import jpl_lp from PyKEP.orbit_plots import plot_planet, plot_lambert mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() axis = fig.gca(projection='3d') t1 = epoch(0) t2 = epoch(640) dt = (t2.mjd2000 - t1.mjd2000) * DAY2SEC axis.scatter([0], [0], [0], color='y') pl = jpl_lp('earth') plot_planet(pl, t0=t1, color=(0.8, 0.8, 1), legend=True, units=AU, ax=axis) rE, vE = pl.eph(t1) pl = jpl_lp('mars') plot_planet(pl, t0=t2, color=(0.8, 0.8, 1), legend=True, units=AU, ax=axis) rM, vM = pl.eph(t2) l = lambert_problem(rE, rM, dt, MU_SUN) plot_lambert(l, color='b', legend=True, units=AU, ax=axis) plot_lambert(l, sol=1, color='g', legend=True, units=AU, ax=axis) plot_lambert(l, sol=2, color='g', legend=True, units=AU, ax=axis) plt.show()
def __init__(self, mass=1000, Tmax=0.1, Isp=2500, Vinf=3.0, nseg=20): # First we call the constructor for the base PyGMO problem # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(mga_lt_earth_mars_sundmann, self).__init__(7 + nseg * 3, 0, 1, 9 + nseg, nseg + 1, 1e-4) # We then define some data members (we use the double underscore to # indicate they are private) from PyKEP import MU_SUN, AU from PyKEP.planets import jpl_lp from PyKEP.sims_flanagan import spacecraft, leg_s self.__earth = jpl_lp('earth') self.__mars = jpl_lp('jupiter') self.__sc = spacecraft(mass, Tmax, Isp) self.__Vinf = Vinf * 1000 # here we construct the trajectory leg in Sundman's variable t = # (r/10AU)^1.5 s self.__leg = leg_s(nseg, 1.0 / (100 * AU)**1.0, 1.0) self.__leg.set_mu(MU_SUN) self.__leg.set_spacecraft(self.__sc) # This is needed to use the plotting function plot_sf_leg self.__leg.high_fidelity = False self.__nseg = nseg # The bounds on Sundman's variable can be evaluated considering # circular orbits at r=1AU and r=0.7AU (for example) self.set_bounds([ 5000, 2400, 10000, self.__sc.mass / 10, -self.__Vinf, -self.__Vinf, -self.__Vinf ] + [-1] * 3 * nseg, [ 8000, 2500, 150000, self.__sc.mass, self.__Vinf, self.__Vinf, self.__Vinf ] + [1] * 3 * nseg)
def __init__(self, mass=2000, Tmax=0.5, Isp=3500, Vinf_dep=3, Vinf_arr=2, nseg1=5, nseg2=20): # First we call the constructor for the base PyGMO problem # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(mga_lt_EVMe, self).__init__(17 + 3 * (nseg1 + nseg2), 0, 1, 14 + 1 + nseg1 + nseg2 + 3, nseg1 + nseg2 + 3, 1e-4) # We then define some data members (we use the double underscore to # indicate they are private) from PyKEP import MU_SUN from PyKEP.planets import jpl_lp from PyKEP.sims_flanagan import spacecraft, leg self.__earth = jpl_lp('earth') self.__venus = jpl_lp('venus') self.__mercury = jpl_lp('mercury') self.__sc = spacecraft(mass, Tmax, Isp) self.__Vinf_dep = Vinf_dep * 1000 self.__Vinf_arr = Vinf_arr * 1000 self.__leg1 = leg() self.__leg2 = leg() self.__leg1.set_mu(MU_SUN) self.__leg1.set_spacecraft(self.__sc) self.__leg2.set_mu(MU_SUN) self.__leg2.set_spacecraft(self.__sc) self.__nseg1 = nseg1 self.__nseg2 = nseg2 # And the box-bounds (launch windows, allowed velocities, etc.) lb = [3000, 100, mass / 2] + [-self.__Vinf_dep] * 3 + [-6000] * 3 + [200, mass / 9] + [-6000] * 3 + [-self.__Vinf_arr] * 3 + [-1, -1, -1] * (nseg1 + nseg2) ub = [4000, 1000, mass] + [self.__Vinf_dep] * 3 + [6000] * 3 + [2000, mass] + [6000] * 3 + [self.__Vinf_arr] * 3 + [1, 1, 1] * (nseg1 + nseg2) self.set_bounds(lb, ub)
def run_example5(): from PyGMO import archipelago, problem from PyGMO.algorithm import jde from PyGMO.topology import ring from PyKEP import epoch from PyKEP.planets import jpl_lp from PyKEP.trajopt import mga_1dsm # We define an Earth-Venus-Earth problem (single-objective) seq = [jpl_lp('earth'), jpl_lp('venus'), jpl_lp('earth')] prob = mga_1dsm(seq=seq) prob.set_tof(0.7, 3) prob.set_vinf(2.5) prob.set_launch_window(epoch(5844), epoch(6209)) prob.set_tof(0.7, 3) # We solve it!! algo = jde(100) topo = ring() archi = archipelago(algo, prob, 8, 20, topology=topo) print( "Running a Self-Adaptive Differential Evolution Algorithm .... on 8 parallel islands" ) archi.evolve(10) archi.join() isl = min(archi, key=lambda x: x.population.champion.f[0]) print("Done!! Best solution found is: " + str(isl.population.champion.f[0] / 1000) + " km / sec") prob.pretty(isl.population.champion.x) prob.plot(isl.population.champion.x)
def __init__(self, seq=[jpl_lp('earth'), jpl_lp('venus'), jpl_lp('earth')], t0=[epoch(0), epoch(1000)], tof=[1.0, 5.0], vinf=[0.5, 2.5], add_vinf_dep=False, add_vinf_arr=True, multi_objective=False): """ PyKEP.trajopt.mga_1dsm(seq = [jpl_lp('earth'), jpl_lp('venus'), jpl_lp('earth')], t0 = [epoch(0),epoch(1000)], tof = [1.0,5.0], vinf = [0.5, 2.5], multi_objective = False, add_vinf_dep = False, add_vinf_arr=True) - seq: list of PyKEP planets defining the encounter sequence (including the starting launch) - t0: list of two epochs defining the launch window - tof: list of two floats defining the minimum and maximum allowed mission lenght (years) - vinf: list of two floats defining the minimum and maximum allowed initial hyperbolic velocity (at launch), in km/sec - multi_objective: when True constructs a multiobjective problem (dv, T) - add_vinf_dep: when True the computed Dv includes the initial hyperbolic velocity (at launch) - add_vinf_arr: when True the computed Dv includes the final hyperbolic velocity (at the last planet) """ # Sanity checks ...... all planets need to have the same # mu_central_body if ([r.mu_central_body for r in seq].count(seq[0].mu_central_body) != len(seq)): raise ValueError( 'All planets in the sequence need to have exactly the same mu_central_body' ) self.__add_vinf_dep = add_vinf_dep self.__add_vinf_arr = add_vinf_arr self.__n_legs = len(seq) - 1 dim = 7 + (self.__n_legs - 1) * 4 obj_dim = multi_objective + 1 # First we call the constructor for the base PyGMO problem # As our problem is n dimensional, box-bounded (may be multi-objective), we write # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(mga_1dsm, self).__init__(dim, 0, obj_dim, 0, 0, 0) # We then define all planets in the sequence and the common central # body gravity as data members self.seq = seq self.common_mu = seq[0].mu_central_body # And we compute the bounds lb = [t0[0].mjd2000, tof[0] * 365.25] + [ 0.0, 0.0, vinf[0] * 1000, 1e-5, 1e-5 ] + [-2 * pi, 1.1, 1e-5, 1e-5] * (self.__n_legs - 1) ub = [t0[1].mjd2000, tof[1] * 365.25] + [ 1.0, 1.0, vinf[1] * 1000, 1.0 - 1e-5, 1.0 - 1e-5 ] + [2 * pi, 30.0, 1.0 - 1e-5, 1.0 - 1e-5] * (self.__n_legs - 1) # Accounting that each planet has a different safe radius...... for i, pl in enumerate(seq[1:-1]): lb[8 + 4 * i] = pl.safe_radius / pl.radius # And we set them self.set_bounds(lb, ub)
def __init__(self, seq=[jpl_lp('earth'), jpl_lp('venus'), jpl_lp('earth')], t0=[epoch(0), epoch(1000)], tof=[1.0, 5.0], vinf=[0.5, 2.5], add_vinf_dep=False, add_vinf_arr=True, multi_objective=False): """ PyKEP.trajopt.mga_1dsm(seq = [jpl_lp('earth'), jpl_lp('venus'), jpl_lp('earth')], t0 = [epoch(0),epoch(1000)], tof = [1.0,5.0], vinf = [0.5, 2.5], multi_objective = False, add_vinf_dep = False, add_vinf_arr=True) - seq: list of PyKEP planets defining the encounter sequence (including the starting launch) - t0: list of two epochs defining the launch window - tof: list of two floats defining the minimum and maximum allowed mission lenght (years) - vinf: list of two floats defining the minimum and maximum allowed initial hyperbolic velocity (at launch), in km/sec - multi_objective: when True constructs a multiobjective problem (dv, T) - add_vinf_dep: when True the computed Dv includes the initial hyperbolic velocity (at launch) - add_vinf_arr: when True the computed Dv includes the final hyperbolic velocity (at the last planet) """ # Sanity checks ...... all planets need to have the same # mu_central_body if ([r.mu_central_body for r in seq].count(seq[0].mu_central_body) != len(seq)): raise ValueError('All planets in the sequence need to have exactly the same mu_central_body') self.__add_vinf_dep = add_vinf_dep self.__add_vinf_arr = add_vinf_arr self.__n_legs = len(seq) - 1 dim = 7 + (self.__n_legs - 1) * 4 obj_dim = multi_objective + 1 # First we call the constructor for the base PyGMO problem # As our problem is n dimensional, box-bounded (may be multi-objective), we write # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(mga_1dsm, self).__init__(dim, 0, obj_dim, 0, 0, 0) # We then define all planets in the sequence and the common central # body gravity as data members self.seq = seq self.common_mu = seq[0].mu_central_body # And we compute the bounds lb = [t0[0].mjd2000, tof[0] * 365.25] + [0.0, 0.0, vinf[0] * 1000, 1e-5, 1e-5] + [-2 * pi, 1.1, 1e-5, 1e-5] * (self.__n_legs - 1) ub = [t0[1].mjd2000, tof[1] * 365.25] + [1.0, 1.0, vinf[1] * 1000, 1.0 - 1e-5, 1.0 - 1e-5] + [2 * pi, 30.0, 1.0 - 1e-5, 1.0 - 1e-5] * (self.__n_legs - 1) # Accounting that each planet has a different safe radius...... for i, pl in enumerate(seq[1:-1]): lb[8 + 4 * i] = pl.safe_radius / pl.radius # And we set them self.set_bounds(lb, ub)
def __init__(self, mass=1000, Tmax=0.05, Isp=2500, Vinf=3.0, nseg=20): # First we call the constructor for the base PyGMO problem # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(mga_lt_earth_mars, self).__init__( 6 + nseg * 3, 0, 1, 8 + nseg, nseg + 1, 1e-4) # We then define some data members (we use the double underscore to # indicate they are private) from PyKEP import MU_SUN from PyKEP.planets import jpl_lp from PyKEP.sims_flanagan import spacecraft, leg self.__earth = jpl_lp('earth') self.__mars = jpl_lp('mars') self.__sc = spacecraft(mass, Tmax, Isp) self.__Vinf = Vinf * 1000 self.__leg = leg() self.__leg.set_mu(MU_SUN) self.__leg.set_spacecraft(self.__sc) self.__nseg = nseg self.set_bounds([2480, 2400, self.__sc.mass / 10, -self.__Vinf, -self.__Vinf, -self.__Vinf] + [-1] * 3 * nseg, [2490, 2500, self.__sc.mass, self.__Vinf, self.__Vinf, self.__Vinf] + [1] * 3 * nseg)
def run_example2(): import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from PyKEP import epoch, DAY2SEC, AU, MU_SUN, lambert_problem from PyKEP.planets import jpl_lp from PyKEP.orbit_plots import plot_planet, plot_lambert mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() axis = fig.gca(projection='3d') t1 = epoch(0) t2 = epoch(640) dt = (t2.mjd2000 - t1.mjd2000) * DAY2SEC axis.scatter([0], [0], [0], color='y') pl = jpl_lp('earth') plot_planet( pl, t0=t1, color=(0.8, 0.8, 1), legend=True, units = AU, ax = axis) rE, vE = pl.eph(t1) pl = jpl_lp('mars') plot_planet( pl, t0=t2, color=(0.8, 0.8, 1), legend=True, units = AU, ax = axis) rM, vM = pl.eph(t2) l = lambert_problem(rE, rM, dt, MU_SUN) plot_lambert(l, color='b', legend=True, units=AU, ax=axis) plot_lambert(l, sol=1, color='g', legend=True, units=AU, ax=axis) plot_lambert(l, sol=2, color='g', legend=True, units=AU, ax=axis) plt.show()
def __init__(self, seq=[jpl_lp('earth'), jpl_lp('venus'), jpl_lp('earth')], n_seg=[10] * 2, t0=[epoch(0), epoch(1000)], tof=[[200, 500], [200, 500]], vinf_dep=2.5, vinf_arr=2.0, mass=4000.0, Tmax=1.0, Isp=2000.0, fb_rel_vel=6, multi_objective=False, high_fidelity=False): """ prob = mga_lt_nep(seq = [jpl_lp('earth'),jpl_lp('venus'),jpl_lp('earth')], n_seg = [10]*2, t0 = [epoch(0),epoch(1000)], tof = [[200,500],[200,500]], Vinf_dep=2.5, Vinf_arr=2.0, mass=4000.0, Tmax=1.0, Isp=2000.0, multi_objective = False, fb_rel_vel = 6, high_fidelity=False) - seq: list of PyKEP.planet defining the encounter sequence for the trajectoty (including the initial planet) - n_seg: list of integers containing the number of segments to be used for each leg (len(n_seg) = len(seq)-1) - t0: list of PyKEP epochs defining the launch window - tof: minimum and maximum time of each leg (days) - vinf_dep: maximum launch hyperbolic velocity allowed (in km/sec) - vinf_arr: maximum arrival hyperbolic velocity allowed (in km/sec) - mass: spacecraft starting mass - Tmax: maximum thrust - Isp: engine specific impulse - fb_rel_vel = determines the bounds on the maximum allowed relative velocity at all fly-bys (in km/sec) - multi-objective: when True defines the problem as a multi-objective problem, returning total DV and time of flight - high_fidelity = makes the trajectory computations slower, but actually dynamically feasible. """ # 1) We compute the problem dimensions .... and call the base problem constructor self.__n_legs = len(seq) - 1 n_fb = self.__n_legs - 1 # 1a) The decision vector length dim = 1 + self.__n_legs * 8 + sum(n_seg) * 3 # 1b) The total number of constraints (mismatch + fly-by + boundary + throttles c_dim = self.__n_legs * 7 + n_fb * 2 + 2 + sum(n_seg) # 1c) The number of inequality constraints (boundary + fly-by angle + throttles) c_ineq_dim = 2 + n_fb + sum(n_seg) # 1d) the number of objectives f_dim = multi_objective + 1 # First we call the constructor for the base PyGMO problem # As our problem is n dimensional, box-bounded (may be multi-objective), we write # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(mga_lt_nep, self).__init__(dim, 0, f_dim, c_dim, c_ineq_dim, 1e-4) # 2) We then define some class data members # public: self.seq = seq # private: self.__n_seg = n_seg self.__vinf_dep = vinf_dep * 1000 self.__vinf_arr = vinf_arr * 1000 self.__sc = spacecraft(mass, Tmax, Isp) self.__leg = leg() self.__leg.set_mu(MU_SUN) self.__leg.set_spacecraft(self.__sc) self.__leg.high_fidelity = high_fidelity fb_rel_vel *= 1000 # 3) We compute the bounds lb = [t0[0].mjd2000] + [0, mass / 2, -fb_rel_vel, -fb_rel_vel, -fb_rel_vel, -fb_rel_vel, -fb_rel_vel, -fb_rel_vel] * self.__n_legs + [-1, -1, -1] * sum(self.__n_seg) ub = [t0[1].mjd2000] + [1, mass, fb_rel_vel, fb_rel_vel, fb_rel_vel, fb_rel_vel, fb_rel_vel, fb_rel_vel] * self.__n_legs + [1, 1, 1] * sum(self.__n_seg) # 3a ... and account for the bounds on the vinfs...... lb[3:6] = [-self.__vinf_dep] * 3 ub[3:6] = [self.__vinf_dep] * 3 lb[-sum(self.__n_seg) * 3 - 3:-sum(self.__n_seg) * 3] = [-self.__vinf_arr] * 3 ub[-sum(self.__n_seg) * 3 - 3:-sum(self.__n_seg) * 3] = [self.__vinf_arr] * 3 # 3b... and for the time of flight lb[1:1 + 8 * self.__n_legs:8] = [el[0] for el in tof] ub[1:1 + 8 * self.__n_legs:8] = [el[1] for el in tof] # 4) And we set the bounds self.set_bounds(lb, ub)
def __init__(self, seq=[jpl_lp('earth'), jpl_lp('venus'), jpl_lp('earth')], n_seg=[10] * 2, t0=[epoch(0), epoch(1000)], tof=[[200, 500], [200, 500]], vinf_dep=2.5, vinf_arr=2.0, mass=4000.0, Tmax=1.0, Isp=2000.0, fb_rel_vel=6, multi_objective=False, high_fidelity=False): """ prob = mga_lt_nep(seq = [jpl_lp('earth'),jpl_lp('venus'),jpl_lp('earth')], n_seg = [10]*2, t0 = [epoch(0),epoch(1000)], tof = [[200,500],[200,500]], Vinf_dep=2.5, Vinf_arr=2.0, mass=4000.0, Tmax=1.0, Isp=2000.0, multi_objective = False, fb_rel_vel = 6, high_fidelity=False) - seq: list of PyKEP.planet defining the encounter sequence for the trajectoty (including the initial planet) - n_seg: list of integers containing the number of segments to be used for each leg (len(n_seg) = len(seq)-1) - t0: list of PyKEP epochs defining the launch window - tof: minimum and maximum time of each leg (days) - vinf_dep: maximum launch hyperbolic velocity allowed (in km/sec) - vinf_arr: maximum arrival hyperbolic velocity allowed (in km/sec) - mass: spacecraft starting mass - Tmax: maximum thrust - Isp: engine specific impulse - fb_rel_vel = determines the bounds on the maximum allowed relative velocity at all fly-bys (in km/sec) - multi-objective: when True defines the problem as a multi-objective problem, returning total DV and time of flight - high_fidelity = makes the trajectory computations slower, but actually dynamically feasible. """ # 1) We compute the problem dimensions .... and call the base problem constructor self.__n_legs = len(seq) - 1 n_fb = self.__n_legs - 1 # 1a) The decision vector length dim = 1 + self.__n_legs * 8 + sum(n_seg) * 3 # 1b) The total number of constraints (mismatch + fly-by + boundary + throttles c_dim = self.__n_legs * 7 + n_fb * 2 + 2 + sum(n_seg) # 1c) The number of inequality constraints (boundary + fly-by angle + throttles) c_ineq_dim = 2 + n_fb + sum(n_seg) # 1d) the number of objectives f_dim = multi_objective + 1 # First we call the constructor for the base PyGMO problem # As our problem is n dimensional, box-bounded (may be multi-objective), we write # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(mga_lt_nep, self).__init__(dim, 0, f_dim, c_dim, c_ineq_dim, 1e-4) # 2) We then define some class data members # public: self.seq = seq # private: self.__n_seg = n_seg self.__vinf_dep = vinf_dep * 1000 self.__vinf_arr = vinf_arr * 1000 self.__sc = spacecraft(mass, Tmax, Isp) self.__leg = leg() self.__leg.set_mu(MU_SUN) self.__leg.set_spacecraft(self.__sc) self.__leg.high_fidelity = high_fidelity fb_rel_vel *= 1000 # 3) We compute the bounds lb = [t0[0].mjd2000] + [ 0, mass / 2, -fb_rel_vel, -fb_rel_vel, -fb_rel_vel, -fb_rel_vel, -fb_rel_vel, -fb_rel_vel ] * self.__n_legs + [-1, -1, -1] * sum(self.__n_seg) ub = [t0[1].mjd2000] + [ 1, mass, fb_rel_vel, fb_rel_vel, fb_rel_vel, fb_rel_vel, fb_rel_vel, fb_rel_vel ] * self.__n_legs + [1, 1, 1] * sum(self.__n_seg) # 3a ... and account for the bounds on the vinfs...... lb[3:6] = [-self.__vinf_dep] * 3 ub[3:6] = [self.__vinf_dep] * 3 lb[-sum(self.__n_seg) * 3 - 3:-sum(self.__n_seg) * 3] = [-self.__vinf_arr] * 3 ub[-sum(self.__n_seg) * 3 - 3:-sum(self.__n_seg) * 3] = [self.__vinf_arr] * 3 # 3b... and for the time of flight lb[1:1 + 8 * self.__n_legs:8] = [el[0] for el in tof] ub[1:1 + 8 * self.__n_legs:8] = [el[1] for el in tof] # 4) And we set the bounds self.set_bounds(lb, ub)
def __init__(self, start=jpl_lp('earth'), target=jpl_lp('venus'), N_max=3, tof=[20., 400.], vinf=[0., 4.], phase_free=True, multi_objective=False, t0=None): """ prob = PyKEP.trajopt.pl2pl_N_impulses(start=jpl_lp('earth'), target=jpl_lp('venus'), N_max=3, tof=[20., 400.], vinf=[0., 4.], phase_free=True, multi_objective=False, t0=None) - start: a PyKEP planet defining the starting orbit - target: a PyKEP planet defining the target orbit - N_max: maximum number of impulses - tof: a list containing the box bounds [lower,upper] for the time of flight (days) - vinf: a list containing the box bounds [lower,upper] for each DV magnitude (km/sec) - phase_free: when True, no randezvous condition is enforced and the final orbit will be reached at an optimal true anomaly - multi_objective: when True, a multi-objective problem is constructed with DV and time of flight as objectives - t0: launch window defined as a list of two epochs [epoch,epoch] """ # Sanity checks # 1) all planets need to have the same mu_central_body if (start.mu_central_body != target.mu_central_body): raise ValueError( 'Starting and ending PyKEP.planet must have the same mu_central_body' ) # 2) Number of impulses must be at least 2 if N_max < 2: raise ValueError('Number of impulses N is less than 2') # 3) If phase_free is True, t0 does not make sense if (t0 is None and not phase_free): t0 = [epoch(0), epoch(1000)] if (t0 is not None and phase_free): raise ValueError('When phase_free is True no t0 can be specified') # We compute the PyGMO problem dimensions dim = 2 + 4 * (N_max - 2) + 1 + phase_free obj_dim = multi_objective + 1 # First we call the constructor for the base PyGMO problem # As our problem is n dimensional, box-bounded (may be multi-objective), we write # (dim, integer dim, number of obj, number of con, number of inequality con, tolerance on con violation) super(pl2pl_N_impulses, self).__init__(dim, 0, obj_dim, 0, 0, 0) # We then define all class data members self.start = start self.target = target self.N_max = N_max self.phase_free = phase_free self.multi_objective = multi_objective self.__common_mu = start.mu_central_body # And we compute the bounds if phase_free: lb = [start.ref_epoch.mjd2000, tof[0] ] + [0.0, 0.0, 0.0, vinf[0] * 1000] * (N_max - 2) + [0.0] + [ target.ref_epoch.mjd2000 ] ub = [ start.ref_epoch.mjd2000 + 2 * start.period * SEC2DAY, tof[1] ] + [1.0, 1.0, 1.0, vinf[1] * 1000] * (N_max - 2) + [1.0] + [ target.ref_epoch.mjd2000 + 2 * target.period * SEC2DAY ] else: lb = [t0[0].mjd2000, tof[0] ] + [0.0, 0.0, 0.0, vinf[0] * 1000] * (N_max - 2) + [0.0] ub = [t0[1].mjd2000, tof[1] ] + [1.0, 1.0, 1.0, vinf[1] * 1000] * (N_max - 2) + [1.0] # And we set them self.set_bounds(lb, ub)