-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
204 additions
and
13 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.. _gym: | ||
|
||
Trajectory Optimization Gym | ||
########################### | ||
|
||
.. currentmodule:: pykep.trajopt.gym | ||
|
||
MGA problems | ||
************************ | ||
|
||
.. autoattribute:: pykep.trajopt.gym.cassini1 | ||
|
||
This is an MGA problem inspired to the Cassini spacecraft interplanetary transfer to Saturn. | ||
The objective of this mission is to reach Saturn and to be captured by its gravity into an orbit having pericenter radius :math:`r_p=108950` km, | ||
and eccentricity :math:`e=0.98`. The planetary fly-by sequence considered is E-VVEJ-S (as the one used by Cassini spacecraft). | ||
As objective function we use the total :math:`\Delta V` accumulated during the mission, including the launch :math:`\Delta V` and the various :math:`\Delta V` one | ||
needs to give at the planets and upon arrival to perform the final orbit injection. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
## Copyright 2023, 2024 Dario Izzo ([email protected]), Francesco Biscani | ||
## ([email protected]) | ||
## | ||
## This file is part of the pykep library. | ||
## | ||
## This Source Code Form is subject to the terms of the Mozilla | ||
## Public License v. 2.0. If a copy of the MPL was not distributed | ||
## with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import pykep as pk | ||
import pygmo as pg | ||
|
||
import unittest as _ut | ||
|
||
def float_abs_error(a: float, b: float): | ||
return abs(a - b) | ||
|
||
def float_rel_error(a: float, b: float): | ||
return abs(a - b) / abs(a) | ||
|
||
class mga_tests(_ut.TestCase): | ||
def test_construction(self): | ||
import pykep as pk | ||
earth = pk.planet(pk.udpla.jpl_lp("earth")) | ||
venus = pk.planet(pk.udpla.jpl_lp("venus")) | ||
udp = pk.trajopt.mga( | ||
seq=[ | ||
earth, | ||
venus, | ||
earth, | ||
venus, | ||
earth | ||
], | ||
tof_encoding = "direct", | ||
t0=[0, 1000], | ||
tof=[[30, 200], [30, 300], [30, 300], [30, 300]], | ||
vinf=2.5, | ||
) | ||
prob = pg.problem(udp) | ||
pop = pg.population(prob, 100) | ||
|
||
def test_encoding_to_encoding(self): | ||
import pykep as pk | ||
udp_direct = pk.trajopt.mga(tof_encoding="direct", tof = [[30, 200], [200, 300]]) | ||
udp_alpha = pk.trajopt.mga(tof_encoding="alpha", tof = [230, 500]) | ||
udp_eta = pk.trajopt.mga(tof_encoding="eta", tof = 500) | ||
prob = pg.problem(udp_direct) | ||
pop = pg.population(prob, 100) | ||
x_direct = pop.champion_x | ||
gt = udp_direct.fitness(x_direct)[0] | ||
x_alpha = udp_alpha.direct2alpha(x_direct) | ||
x_eta = udp_eta.direct2eta(x_direct) | ||
self.assertTrue(float_rel_error(gt, udp_alpha.fitness(x_alpha)[0]) < 1e-14) | ||
self.assertTrue(float_rel_error(gt, udp_eta.fitness(x_eta)[0]) < 1e-14) | ||
self.assertTrue(float_rel_error(gt, udp_direct.fitness(udp_direct.alpha2direct(x_alpha))[0]) < 1e-14) | ||
self.assertTrue(float_rel_error(gt, udp_direct.fitness(udp_eta.eta2direct(x_eta))[0]) < 1e-14) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
set(PYKEP_TRAJOPT_PYTHON_FILES __init__.py _direct_point2point.py _direct_pl2pl.py _mga.py) | ||
install(FILES ${PYKEP_TRAJOPT_PYTHON_FILES} DESTINATION ${_PYKEP_INSTALL_DIR}/trajopt) | ||
|
||
ADD_SUBDIRECTORY(gym) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set(PYKEP_GYM_PYTHON_FILES __init__.py _cassini_mga.py) | ||
install(FILES ${PYKEP_GYM_PYTHON_FILES} DESTINATION ${_PYKEP_INSTALL_DIR}/trajopt/gym) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._cassini_mga import cassini1, cassini1_a, cassini1_n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import pykep as _pk | ||
from pykep.trajopt import mga as _mga | ||
|
||
# CASSINI | ||
_seq_cassini = [_pk.planet(_pk.udpla.jpl_lp('earth')), | ||
_pk.planet(_pk.udpla.jpl_lp('venus')), | ||
_pk.planet(_pk.udpla.jpl_lp('venus')), | ||
_pk.planet(_pk.udpla.jpl_lp('earth')), | ||
_pk.planet(_pk.udpla.jpl_lp('jupiter')), | ||
_pk.planet(_pk.udpla.jpl_lp('saturn'))] | ||
|
||
class _cassini1_udp(_mga): | ||
def __init__(self): | ||
super().__init__( | ||
seq=_seq_cassini, | ||
t0=[-1000., 0.], | ||
tof=[[30, 400], [100, 470], [30, 400], [400, 2000], [1000, 6000]], | ||
vinf=3., | ||
tof_encoding='direct', | ||
orbit_insertion=True, | ||
e_target=0.98, | ||
rp_target=108950000) | ||
|
||
def get_name(self): | ||
return "Cassini MGA direct tof encoding (Trajectory Optimisation Gym P1)" | ||
|
||
def get_extra_info(self): | ||
retval = "\tTrajectory Optimisation Gym problem (P1): Cassini MGA, single objective, direct encoding\n" | ||
retval += "\tPlanetary sequence" + \ | ||
str([pl.get_name() for pl in _seq_cassini1]) | ||
return retval | ||
|
||
def __repr__(self): | ||
return self.get_name() | ||
|
||
|
||
class _cassini1a_udp(_mga): | ||
def __init__(self): | ||
super().__init__( | ||
seq=_seq_cassini, | ||
t0=[-1000., 0.], | ||
tof=[4000., 7000.], | ||
vinf=3., | ||
tof_encoding='alpha', | ||
orbit_insertion=True, | ||
e_target=0.98, | ||
rp_target=108950000) | ||
|
||
def get_name(self): | ||
return "Cassini MGA alpha tof encoding (Trajectory Optimisation Gym P2)" | ||
|
||
def get_extra_info(self): | ||
retval = "\tTrajectory Optimisation Gym problem (P2): Cassini MGA, single objective, alpha encoding\n" | ||
retval += "\tPlanetary sequence" + \ | ||
str([pl.get_name() for pl in _seq_cassini1]) | ||
return retval | ||
|
||
def __repr__(self): | ||
return self.get_name() | ||
|
||
|
||
class _cassini1n_udp(_mga): | ||
def __init__(self): | ||
super().__init__( | ||
seq=_seq_cassini, | ||
t0=[-1000., 0.], | ||
tof=7000., | ||
vinf=3., | ||
tof_encoding='eta', | ||
orbit_insertion=True, | ||
e_target=0.98, | ||
rp_target=108950000) | ||
|
||
def get_name(self): | ||
return "Cassini1 MGA eta tof encoding (Trajectory Optimisation Gym P3)" | ||
|
||
def get_extra_info(self): | ||
retval = "\tTrajectory Optimisation Gym problem (P3): Cassini MGA, single objective, eta encoding\n" | ||
retval += "\tPlanetary sequence" + \ | ||
str([pl.get_name() for pl in _seq_cassini1]) | ||
return retval | ||
|
||
def __repr__(self): | ||
return self.get_name() | ||
|
||
# Problem P1: Cassini MGA, single objective, direct encoding | ||
cassini1 = _cassini1_udp() | ||
# Problem P2: Cassini MGA, single objective, alpha encoding | ||
cassini1_a = _cassini1a_udp() | ||
# Problem P3: Cassini MGA, single objective, eta encoding | ||
cassini1_n = _cassini1n_udp() |