def run_example4(): import pygmo as pg from pykep.examples import add_gradient, algo_factory N = 20 # problem udp = add_gradient(mga_lt_earth_mars_sundmann(nseg=N), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # algorithm uda = algo_factory("snopt7", False) uda2 = pg.mbh(uda, 5, 0.05) algo = pg.algorithm(uda2) algo.set_verbosity(1) # 3 - Population pop = pg.population(prob, 1) # 4 - Solve the problem (evolve) print("Running Monotonic Basin Hopping ....") pop = algo.evolve(pop) print("Is the solution found a feasible trajectory? " + str(prob.feasibility_x(pop.champion_x))) udp.udp_inner.plot(pop.champion_x)
def run_example3(): import pygmo as pg from pykep.examples import add_gradient, algo_factory # problem udp = add_gradient(mga_lt_EVMe(), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # algorithm uda = algo_factory("snopt7", False) uda2 = pg.mbh(uda, 5, 0.05) algo = pg.algorithm(uda2) algo.set_verbosity(1) # 3 - Population pop = pg.population(prob, 1) # 4 - Solve the problem (evolve) print("Running Monotonic Basin Hopping ....") pop = algo.evolve(pop) print("Is the solution found a feasible trajectory? " + str(prob.feasibility_x(pop.champion_x))) udp.udp_inner.plot(pop.champion_x)
def run_example11(n_seg=30): """ This example demonstrates the use of the class lt_margo developed for the internal ESA CDF study on the interplanetary mission named MARGO. The class was used to produce the preliminary traget selection for the mission resulting in 88 selected possible targets (http://www.esa.int/spaceinimages/Images/2017/11/Deep-space_CubeSat) (http://www.esa.int/gsp/ACT/mad/projects/lt_to_NEA.html) """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # 0 - Target asteroid from MPCORB mpcorbline = "K14Y00D 24.3 0.15 K1794 105.44160 34.12337 117.64264 1.73560 0.0865962 0.88781021 1.0721510 2 MPO369254 104 1 194 days 0.24 M-v 3Eh MPCALB 2803 2014 YD 20150618" # 1 - Algorithm algo = algo_factory("snopt7") # 2 - Problem udp = add_gradient(pk.trajopt.lt_margo( target=pk.planet.mpcorb(mpcorbline), n_seg=n_seg, grid_type="uniform", t0=[pk.epoch(8000), pk.epoch(9000)], tof=[200, 365.25 * 3], m0=20.0, Tmax=0.0017, Isp=3000.0, earth_gravity=False, sep=True, start="earth"), with_grad=False ) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 3 - Population pop = pg.population(prob, 1) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) # 5 - Inspect the solution print("Feasible?:", prob.feasibility_x(pop.champion_x)) # 6 - plot trajectory axis = udp.udp_inner.plot_traj(pop.champion_x, plot_segments=True) plt.title("The trajectory in the heliocentric frame") # 7 - plot control udp.udp_inner.plot_dists_thrust(pop.champion_x) # 8 - pretty udp.udp_inner.pretty(pop.champion_x) plt.ion() plt.show()
def run_example11(n_seg=30): """ This example demonstrates the use of the class lt_margo developed for the internal ESA CDF study on the interplanetary mission named MARGO. The class was used to produce the preliminary traget selection for the mission resulting in 88 selected possible targets (http://www.esa.int/spaceinimages/Images/2017/11/Deep-space_CubeSat) (http://www.esa.int/gsp/ACT/mad/projects/lt_to_NEA.html) """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # 0 - Target asteroid from MPCORB mpcorbline = "K14Y00D 24.3 0.15 K1794 105.44160 34.12337 117.64264 1.73560 0.0865962 0.88781021 1.0721510 2 MPO369254 104 1 194 days 0.24 M-v 3Eh MPCALB 2803 2014 YD 20150618" # 1 - Algorithm algo = algo_factory("snopt7") # 2 - Problem udp = add_gradient(pk.trajopt.lt_margo(target=pk.planet.mpcorb(mpcorbline), n_seg=n_seg, grid_type="uniform", t0=[pk.epoch(8000), pk.epoch(9000)], tof=[200, 365.25 * 3], m0=20.0, Tmax=0.0017, Isp=3000.0, earth_gravity=False, sep=True, start="earth"), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 3 - Population pop = pg.population(prob, 1) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) # 5 - Inspect the solution print("Feasible?:", prob.feasibility_x(pop.champion_x)) # 6 - plot trajectory axis = udp.udp_inner.plot_traj(pop.champion_x, plot_segments=True) plt.title("The trajectory in the heliocentric frame") # 7 - plot control udp.udp_inner.plot_dists_thrust(pop.champion_x) # 8 - pretty udp.udp_inner.pretty(pop.champion_x) plt.ion() plt.show()
def run_example8(nseg=40): """ This example demonstrates the direct method (sims-flanagan) on a planet to planet scenario. """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # 1 - Algorithm algo = algo_factory("snopt7") # 2 - Problem udp = add_gradient(pk.trajopt.direct_pl2pl( p0="earth", pf="mars", mass=1000, thrust=0.1, isp=3000, vinf_arr=1e-6, vinf_dep=3.5, hf=False, nseg=nseg, t0=[1100, 1400], tof=[200, 750]), with_grad=False ) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 3 - Population pop = pg.population(prob, 1) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) # 5 - Inspect the solution if prob.feasibility_x(pop.champion_x): print("Optimal Found!!") else: print("No solution found, try again :)") udp.udp_inner.pretty(pop.champion_x) axis = udp.udp_inner.plot_traj(pop.champion_x) plt.title("The trajectory in the heliocentric frame") axis = udp.udp_inner.plot_control(pop.champion_x) plt.title("The control profile (throttle)") plt.ion() plt.show()
def run_example8(nseg=40): """ This example demonstrates the direct method (sims-flanagan) on a planet to planet scenario. """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # 1 - Algorithm algo = algo_factory("snopt7") # 2 - Problem udp = add_gradient(pk.trajopt.direct_pl2pl(p0="earth", pf="mars", mass=1000, thrust=0.1, isp=3000, vinf_arr=1e-6, vinf_dep=3.5, hf=False, nseg=nseg, t0=[1100, 1400], tof=[200, 750]), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 3 - Population pop = pg.population(prob, 1) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) # 5 - Inspect the solution if prob.feasibility_x(pop.champion_x): print("Optimal Found!!") else: print("No solution found, try again :)") udp.udp_inner.pretty(pop.champion_x) axis = udp.udp_inner.plot_traj(pop.champion_x) plt.title("The trajectory in the heliocentric frame") axis = udp.udp_inner.plot_control(pop.champion_x) plt.title("The control profile (throttle)") plt.ion() plt.show()
def run_example6(n_seg=5): """ This example demonstrates the optimization of a multiple randezvous mission (low-thrust). Such a mission (including more asteroids) is also called asteroid hopping The spacecraft performances, as well as the three asteroids visited, are taken from the GTOC7 problem description. """ import pygmo as pg from pykep.trajopt import mr_lt_nep from pykep.planet import gtoc7 from pykep.examples import add_gradient, algo_factory from matplotlib import pyplot as plt # If you have no access to snopt7, try slsqp (multiple starts may be # necessary) algo = algo_factory("snopt7") udp = add_gradient( mr_lt_nep( t0=[9600., 9700.], seq=[gtoc7(5318), gtoc7(14254), gtoc7(7422), gtoc7(5028)], n_seg=n_seg, mass=[800., 2000.], leg_tof=[100., 365.25], rest=[30., 365.25], Tmax=0.3, Isp=3000., traj_tof=365.25 * 3., objective='mass', c_tol=1e-05 ), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() pop = pg.population(prob, 1) pop = algo.evolve(pop) solution = pop.champion_x if prob.feasibility_x(solution): print("FEASIBILE!!!") ax = udp.udp_inner.plot(solution) else: print("INFEASIBLE :(") ax = None plt.ion() plt.show()
def run_example7(solver="snopt7"): """ This example demonstrates the indirect method (cartesian) on a orbit to orbit scenario. The orbits are those of Earth and Mars. """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # Some pre-computed solutions (obtaining spending some iterations and # restarts from random initial guesses) z_mass_optimal = [397.88267909228767, 2.0719343674552215, 2.7313941033119407, 11.882803539732214, 10.567639551625298, 0.50803671389927796, -11.056641527923768, 12.176151455434058, 4.1269457596809245, 3.4434953247725324] z_quadratic_control = [381.32031472240106, 1.0102363292172423, 1.8134352964367946, 19.522442569527868, - 6.7894353762521105, -3.3749783899165928, 7.0438655057343054, 19.923912672512174, 0.93896446800741751, 3.5483645070393743] z_quadratic_control2 = [459.51623108767666, -1.616057488705803, 0.33049652475302532, -17.735981532357027, - 3.2374905349904912, 2.2249621531880934, 2.9550456430212937, -20.226761256676323, -2.9684113654904061, 3.1471248891703905] z_quadratic_control3 = [519.45371103815569, 0.39617485433378341, 2.7008977766929818, 7.9136210333255468, - 11.03747486077437, -3.0776988186969136, 9.1796869310249747, 6.5013311040515687, -0.2054349910826633, 3.0084671211666865] # A random initial solution z_random = np.hstack( [[np.random.uniform(100, 700)], 2 * np.random.randn(9)]) # We use an initial guess within 10% of a known optima, you can experiment what happens # with a different choice z = z_quadratic_control + z_quadratic_control * np.random.randn(10) * 0.1 #z = z_random # 1 - Algorithm algo = algo_factory(solver) # 2 - Problem. We define a minimum quadratic control problem (alpha=0) with free time # (hamiltonian will be forced to be 0). We provide the option for estimating the gradient numerically for # algorithms that require it. udp = add_gradient(pk.trajopt.indirect_or2or( elem0=[149598261129.93335, 0.016711230601231957, 2.640492490927786e-07, 3.141592653589793, 4.938194050401601, 0], elemf=[227943822376.03537, 0.09339409892101332, 0.032283207367640024, 0.8649771996521327, 5.000312830124232, 0], mass=1000, thrust=0.3, isp=2500, atol=1e-12, rtol=1e-12, tof=[100, 700], freetime=True, alpha=0, bound=True, mu=pk.MU_SUN), with_grad=True) prob = pg.problem(udp) prob.c_tol = [1e-7] * 10 # 3 - Population (i.e. initial guess) pop = pg.population(prob) pop.push_back(z) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) # 5 - Inspect the solution if prob.feasibility_x(pop.champion_x): print("Optimal Found!!") # We call the fitness to set the leg udp.udp_inner.fitness(pop.champion_x) arr = udp.udp_inner.leg.get_states(1e-12, 1e-12) print("Final mass is: ", arr[-1, 7]) else: print("No solution found, try again :)") # plot trajectory axis = udp.udp_inner.plot_traj( pop.champion_x, quiver=True, mark="k", length=1) plt.title("The trajectory in the heliocentric frame") # plot control udp.udp_inner.plot_control(pop.champion_x) plt.title("The control profile (throttle)") plt.ion() plt.show() # Show the trajectory data udp.udp_inner.pretty(pop.champion_x)
def run_example10(): """ This example demonstrates the indirect method (cartesian) on a point to point fixed time scenario. The boundary conditions are taken from a run of the indirect method. """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # 1 - Algorithm algo = algo_factory("snopt7") # 2 - Problem udp = add_gradient( pk.trajopt.indirect_pt2pt( x0=[ 44914296854.488266, -145307873786.94177, 1194292.6437741749, 31252.149474878544, 9873.214642584162, -317.08718075574404, 1000 ], xf=[ -30143999066.728119, -218155987244.44385, -3829753551.2279921, 24917.707565772216, -1235.74045124602, -638.05209482866155, 905.47894037275546 ], thrust=0.1, isp=3000, mu=pk.MU_SUN, tof=[616.77087591237546, 616.77087591237546], freetime=False, alpha=0, # quadratic control bound=True), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 3 - Population pop = pg.population(prob) z = np.hstack( ([np.random.uniform(udp.udp_inner.tof[0], udp.udp_inner.tof[1])], 10 * np.random.randn(7))) pop.push_back(z) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) # 5 - Continue the solution to mass optimal homotopy_path = [0.5, 0.75, 0.9, 1] for alpha in homotopy_path: z = pop.champion_x print("alpha: ", alpha) udp = add_gradient( pk.trajopt.indirect_pt2pt( x0=[ 44914296854.488266, -145307873786.94177, 1194292.6437741749, 31252.149474878544, 9873.214642584162, -317.08718075574404, 1000 ], xf=[ -30143999066.728119, -218155987244.44385, -3829753551.2279921, 24917.707565772216, -1235.74045124602, -638.05209482866155, 905.47894037275546 ], thrust=0.1, isp=3000, mu=pk.MU_SUN, tof=[616.77087591237546, 616.77087591237546], freetime=False, alpha=alpha, # quadratic control bound=True), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 7 - Solve it pop = pg.population(prob) pop.push_back(z) pop = algo.evolve(pop) # 8 - Inspect the solution print("Feasible?:", prob.feasibility_x(pop.champion_x)) # plot trajectory axis = udp.udp_inner.plot_traj(pop.champion_x, quiver=True, mark="k") plt.title("The trajectory in the heliocentric frame") # plot control udp.udp_inner.plot_control(pop.champion_x) plt.title("The control profile (throttle)") plt.ion() plt.show() udp.udp_inner.pretty(pop.champion_x) print("\nDecision vector: ", list(pop.champion_x))
def run_example10(): """ This example demonstrates the indirect method (cartesian) on a point to point fixed time scenario. The boundary conditions are taken from a run of the indirect method. """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # 1 - Algorithm algo = algo_factory("snopt7") # 2 - Problem udp = add_gradient(pk.trajopt.indirect_pt2pt( x0=[44914296854.488266, -145307873786.94177, 1194292.6437741749, 31252.149474878544, 9873.214642584162, -317.08718075574404, 1000], xf=[-30143999066.728119, -218155987244.44385, -3829753551.2279921, 24917.707565772216, -1235.74045124602, -638.05209482866155, 905.47894037275546], thrust=0.1, isp=3000, mu=pk.MU_SUN, tof=[616.77087591237546, 616.77087591237546], freetime=False, alpha=0, # quadratic control bound=True), with_grad=False ) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 3 - Population pop = pg.population(prob) z = np.hstack(([np.random.uniform(udp.udp_inner.tof[0], udp.udp_inner.tof[1])], 10 * np.random.randn(7))) pop.push_back(z) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) # 5 - Continue the solution to mass optimal homotopy_path = [0.5, 0.75, 0.9, 1] for alpha in homotopy_path: z = pop.champion_x print("alpha: ", alpha) udp = add_gradient(pk.trajopt.indirect_pt2pt( x0=[44914296854.488266, -145307873786.94177, 1194292.6437741749, 31252.149474878544, 9873.214642584162, -317.08718075574404, 1000], xf=[-30143999066.728119, -218155987244.44385, -3829753551.2279921, 24917.707565772216, -1235.74045124602, -638.05209482866155, 905.47894037275546], thrust=0.1, isp=3000, mu=pk.MU_SUN, tof=[616.77087591237546, 616.77087591237546], freetime=False, alpha=alpha, # quadratic control bound=True), with_grad=False ) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 7 - Solve it pop = pg.population(prob) pop.push_back(z) pop = algo.evolve(pop) # 8 - Inspect the solution print("Feasible?:", prob.feasibility_x(pop.champion_x)) # plot trajectory axis = udp.udp_inner.plot_traj(pop.champion_x, quiver=True, mark="k") plt.title("The trajectory in the heliocentric frame") # plot control udp.udp_inner.plot_control(pop.champion_x) plt.title("The control profile (throttle)") plt.ion() plt.show() udp.udp_inner.pretty(pop.champion_x) print("\nDecision vector: ", list(pop.champion_x))
def run_example7(solver="snopt7"): """ This example demonstrates the indirect method (cartesian) on a orbit to orbit scenario. The orbits are those of Earth and Mars. """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # Some pre-computed solutions (obtaining spending some iterations and # restarts from random initial guesses) z_mass_optimal = [397.88267909228767, 2.0719343674552215, 2.7313941033119407, 11.882803539732214, 10.567639551625298, 0.50803671389927796, -11.056641527923768, 12.176151455434058, 4.1269457596809245, 3.4434953247725324] z_quadratic_control = [381.32031472240106, 1.0102363292172423, 1.8134352964367946, 19.522442569527868, - 6.7894353762521105, -3.3749783899165928, 7.0438655057343054, 19.923912672512174, 0.93896446800741751, 3.5483645070393743] z_quadratic_control2 = [459.51623108767666, -1.616057488705803, 0.33049652475302532, -17.735981532357027, - 3.2374905349904912, 2.2249621531880934, 2.9550456430212937, -20.226761256676323, -2.9684113654904061, 3.1471248891703905] z_quadratic_control3 = [519.45371103815569, 0.39617485433378341, 2.7008977766929818, 7.9136210333255468, - 11.03747486077437, -3.0776988186969136, 9.1796869310249747, 6.5013311040515687, -0.2054349910826633, 3.0084671211666865] # A random initial solution z_random = np.hstack( [[np.random.uniform(100, 700)], 2 * np.random.randn(9)]) # We use an initial guess within 10% of a known optima, you can experiment what happens # with a different choice z = z_quadratic_control + z_quadratic_control * np.random.randn(10) * 0.1 #z = z_random # 1 - Algorithm algo = algo_factory(solver) # 2 - Problem. We define a minimum quadratic control problem (alpha=0) with free time # (hamiltonian will be forced to be 0). We provide the option for estimating the gradient numerically for # algorithms that require it. udp = add_gradient(pk.trajopt.indirect_or2or( elem0=[149598261129.93335, 0.016711230601231957, 2.640492490927786e-07, 3.141592653589793, 4.938194050401601, 0], elemf=[227943822376.03537, 0.09339409892101332, 0.032283207367640024, 0.8649771996521327, 5.000312830124232, 0], mass=1000, thrust=0.3, isp=2500, atol=1e-12, rtol=1e-12, tof=[100, 700], freetime=True, alpha=0, bound=True, mu=pk.MU_SUN), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-7] * 10 # 3 - Population (i.e. initial guess) pop = pg.population(prob) pop.push_back(z) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) # 5 - Inspect the solution if prob.feasibility_x(pop.champion_x): print("Optimal Found!!") # We call the fitness to set the leg udp.udp_inner.fitness(pop.champion_x) arr = udp.udp_inner.leg.get_states(1e-12, 1e-12) print("Final mass is: ", arr[-1, 7]) else: print("No solution found, try again :)") # plot trajectory axis = udp.udp_inner.plot_traj( pop.champion_x, quiver=True, mark="k", length=1) plt.title("The trajectory in the heliocentric frame") # plot control udp.udp_inner.plot_control(pop.champion_x) plt.title("The control profile (throttle)") plt.ion() plt.show() # Show the trajectory data udp.udp_inner.pretty(pop.champion_x)
def run_example9(): """ This example demonstrates the indirect method (cartesian) on a point to planet variable time scenario. The starting conditions are taken from a run of the indirect method. """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # 1 - Algorithm algo = algo_factory("snopt7") # 2 - Problem udp = add_gradient(pk.trajopt.indirect_pt2pl( x0=[44459220055.461708, -145448367557.6174, 1195278.0377499966, 31208.214734303529, 9931.5012318647168, -437.07278242521573, 1000], t0=1285.6637861007277, pf="mars", thrust=0.1, isp=3000, mu=pk.MU_SUN, tof=[600, 720], alpha=0, # quadratic control bound=True), with_grad=False ) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 3 - Population pop = pg.population(prob) z = np.hstack(([np.random.uniform(udp.udp_inner.tof[0], udp.udp_inner.tof[1])], 10 * np.random.randn(7))) pop.push_back(z) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) homotopy_path = [0.2, 0.4, 0.6, 0.8, 0.9, 0.98, 0.99, 0.995, 1] for alpha in homotopy_path: z = pop.champion_x print("alpha is: ", alpha) udp = add_gradient(pk.trajopt.indirect_pt2pl( x0=[44459220055.461708, -145448367557.6174, 1195278.0377499966, 31208.214734303529, 9931.5012318647168, -437.07278242521573, 1000], t0=1285.6637861007277, pf="mars", thrust=0.1, isp=3000, mu=pk.MU_SUN, tof=[600, 720], alpha=alpha, # quadratic control bound=True), with_grad=False ) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 7 - Solve it pop = pg.population(prob) pop.push_back(z) pop = algo.evolve(pop) # 8 - Inspect the solution print("Feasible?:", prob.feasibility_x(pop.champion_x)) # plot trajectory axis = udp.udp_inner.plot_traj(pop.champion_x, quiver=True, mark='k') plt.title("The trajectory in the heliocentric frame") # plot control udp.udp_inner.plot_control(pop.champion_x) plt.title("The control profile (throttle)") plt.ion() plt.show() udp.udp_inner.pretty(pop.champion_x) print("\nDecision vector: ", list(pop.champion_x))
def run_example9(): """ This example demonstrates the indirect method (cartesian) on a point to planet variable time scenario. The starting conditions are taken from a run of the indirect method. """ import pykep as pk import pygmo as pg import numpy as np from matplotlib import pyplot as plt from pykep.examples import add_gradient, algo_factory # 1 - Algorithm algo = algo_factory("snopt7") # 2 - Problem udp = add_gradient( pk.trajopt.indirect_pt2pl( x0=[ 44459220055.461708, -145448367557.6174, 1195278.0377499966, 31208.214734303529, 9931.5012318647168, -437.07278242521573, 1000 ], t0=1285.6637861007277, pf="mars", thrust=0.1, isp=3000, mu=pk.SUN_MU, tof=[600, 720], alpha=0, # quadratic control bound=True), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 3 - Population pop = pg.population(prob) z = np.hstack( ([np.random.uniform(udp.udp_inner.tof[0], udp.udp_inner.tof[1])], 10 * np.random.randn(7))) pop.push_back(z) # 4 - Solve the problem (evolve) pop = algo.evolve(pop) homotopy_path = [0.2, 0.4, 0.6, 0.8, 0.9, 0.98, 0.99, 0.995, 1] for alpha in homotopy_path: z = pop.champion_x print("alpha is: ", alpha) udp = add_gradient( pk.trajopt.indirect_pt2pl( x0=[ 44459220055.461708, -145448367557.6174, 1195278.0377499966, 31208.214734303529, 9931.5012318647168, -437.07278242521573, 1000 ], t0=1285.6637861007277, pf="mars", thrust=0.1, isp=3000, mu=pk.SUN_MU, tof=[600, 720], alpha=alpha, # quadratic control bound=True), with_grad=False) prob = pg.problem(udp) prob.c_tol = [1e-5] * prob.get_nc() # 7 - Solve it pop = pg.population(prob) pop.push_back(z) pop = algo.evolve(pop) # 8 - Inspect the solution print("Feasible?:", prob.feasibility_x(pop.champion_x)) # plot trajectory axis = udp.udp_inner.plot_traj(pop.champion_x, quiver=True, mark='k') plt.title("The trajectory in the heliocentric frame") # plot control udp.udp_inner.plot_control(pop.champion_x) plt.title("The control profile (throttle)") plt.ion() plt.show() udp.udp_inner.pretty(pop.champion_x) print("\nDecision vector: ", list(pop.champion_x))