Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pl2pl n impulses #44

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/epoch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ seamlessly both to the c++ `std::chrono <https://en.cppreference.com/w/cpp/heade
library and to the python `datetime <https://docs.python.org/3/library/datetime.html>`_ module.

.. note::
In `pykep`` the default Julian Date is the Modified Julian Date, defined as a `float` representing the number
In `pykep` the default Julian Date is the Modified Julian Date, defined as a `float` representing the number
of days since the start of 2000-1-1.

.. note::
Expand Down
28 changes: 28 additions & 0 deletions doc/gym.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Trajectory Optimization Gym
###########################

A number of interplanetary trajectory problems are provided in `pykep` in the form of
User Defined Problems (UDP) compatible with the `pygmo <https://esa.github.io/pygmo2/>`_ :cite:p:`pagmo` python package.
All of the problems are instantiated upon import of the `pykep` module and can be used directly. The collection of all
problems is called the "pykep gym" and hopes to become an established benchmark set to test the performances of evolutionary
and traditional optimisation techniques on trajectory design problems.

.. currentmodule:: pykep.trajopt.gym

MGA problems
Expand Down Expand Up @@ -89,3 +95,25 @@ This is the same MGA-1DSM problem as :class:`~pykep.trajopt.gym.juice`, but with
the alpha encoding for the time of flight variables (see :class:`~pykep.trajopt.gym.cassini1_a`).
The problem is also muulti-objective, with the total time of flight as a second objective, leveragng the
alpha encoding to control the total time of flight (at the cost of evolvability).

.. autoattribute:: pykep.trajopt.gym.messenger

This an MGA-1DSM problem inspired by the messenger mission that orbited the planet Mercury between 2011 and 2015, studying Mercury's chemical composition,
geology, and magnetic field. The name is a backronym for Mercury Surface, Space Environment, Geochemistry, and Ranging, and a reference to the messenger
god Mercury from Roman mythology. The selected fly-by sequence, E-VVMeMeMe-Me, and other parameters are concident to the actual Messenger mission.
We have only omitted the first Earth fly-by that was used to correct for launcher performances, since we here do not make use of a launcher model.
As far as chemical propelled interplanetary trajectories go, this particular one is particularly complex and difficult to design.
The time of flights among successive Mercury fly-bys allow for multiple rvolutions and resonances, making optimization techniques struggle to find the correct combination.
The amount of specialistic knowledge that needs to be used to obtain a successful design is significant.
Finding a global optimization approach able to find a good trajectory in complete autonomy without making
use of additional problem knowledge is challenging but possible, but limiting the number of fitness call is difficult.

Multiple impulse problem
************************

.. autoattribute:: pykep.trajopt.gym.e2m_3imp

.. autoattribute:: pykep.trajopt.gym.e2m_5imp

.. autoattribute:: pykep.trajopt.gym.e2m_7imp

13 changes: 13 additions & 0 deletions doc/notebooks/udp_mga.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
":::{note}\n",
"{class}`pykep.trajopt.mga` also implements different (unpublished) encodings for the time of flights, namely called $\\alpha$-encoding and $\\eta$-encoding which, albeit less studied and creating a more complex fitness landscape, are interesting in multiple ways: a) they show how the encoding influences evolvability in a drastic way b) they allow to box-bound the total trajectory time of flight c) they remove problem knowledge exploitation.\n",
"\n",
"In the $\\alpha$-encoding the $n$ time of flights $T_i$ are defined as:\n",
"\n",
"$$T_i = T \\frac{\\log\\alpha_i }{ \\sum_n\\log\\alpha_n}$$\n",
"\n",
"where $T$ is the total time of flight. This encoding ensures that all possible grids are equally probable if the $\\alpha$ are uniformly distributed in [0,1].\n",
"\n",
"In the $\\eta$ encoding $n$ time of flights $T_i$ are defined as:\n",
"\n",
"$$\n",
"T_i = \\left(T_{max} - \\sum_{j=0}^{(i-1)}T_j\\right) \\eta_i\n",
"$$\n",
"where $T_{max}$ is the maximum total time of flight, which will only happen if $\\eta_{n}=1$. This encoding DOES NOT ensure that all possible grids are equally probable if the $\\eta$ are uniformly distributed in [0,1].\n",
"\n",
"We start, as often, with some fundamental imports:"
]
},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/udp_mga_1dsm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Multiple Gravity Assist with deep space manouvres (MGA-1DSM)\n",
"# Multiple Gravity Assist with one DSM (MGA-1DSM)\n",
"\n",
"In this tutorial, we use the {class}`pykep.trajopt.mga_1dsm` to design an interplanetary trajectory. The MGA-1DSM encoding of an interplanetary trajectory models multiple (pre-defined) planetary encounters, and enables for propulsion manovures in the form of one instantaneous $\\Delta V$ at any time along each leg.\n",
"\n",
Expand Down
312 changes: 312 additions & 0 deletions doc/notebooks/udp_pl2pl_N_impulses.ipynb

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions doc/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ @article{izzo2010global
pages={178--200},
year={2010},
publisher={Cambridge University Press, New York, NY, USA}
}

@article{pagmo,
title={A parallel global multiobjective framework for optimization: pagmo},
author={Biscani, Francesco and Izzo, Dario},
journal={Journal of Open Source Software},
volume={5},
number={53},
pages={2338},
year={2020}
}
3 changes: 2 additions & 1 deletion doc/tut_trajopt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ Trajectory Optimization
notebooks/udp_point2point
notebooks/udp_pl2pl
notebooks/udp_mga
notebooks/udp_mga_1dsm
notebooks/udp_mga_1dsm
notebooks/udp_pl2pl_Nimpulses
16 changes: 16 additions & 0 deletions pykep/test_trajopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ def test_juice_mo(self):
f = udp.fitness(x)
self.assertTrue(float_rel_error(f[0], 427.31998557200325) < 1e-13)
self.assertTrue(float_rel_error(f[1], 2270.0472019876433) < 1e-13)

def test_messenger(self):
import pykep as pk

udp = pk.trajopt.gym.messenger
# Ground truth checked by the old pykep code (up to 8 digits only as per differences with constants and all)
x = [ 2.03241398e+03, 6.40762059e-01, 6.63357785e-01, 4.04989271e+03,
6.63732323e-01, 4.50068524e+02, -3.86553343e+00, 3.52631372e+00,
5.57888828e-01, 2.24619580e+02, -4.45910441e+00, 1.22736521e+00,
7.08063036e-01, 2.17965497e+02, -2.47894274e+00, 1.43586128e+00,
5.88391838e-01, 2.62423586e+02, -2.40594385e-02, 2.45470457e+00,
7.25370468e-01, 3.58067954e+02, 1.47192632e+00, 1.05000000e+00,
9.02984391e-01, 5.38436770e+02]

f = udp.fitness(x)
self.assertTrue(float_rel_error(f[0], 5855.81434335236) < 1e-13)

class trajopt_mga1dsm_tests(_ut.TestCase):
def test_construction(self):
Expand Down
5 changes: 2 additions & 3 deletions pykep/trajopt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set(PYKEP_TRAJOPT_PYTHON_FILES __init__.py _direct_point2point.py _direct_pl2pl.py _mga.py _mga_1dsm.py _launchers.py)
set(PYKEP_TRAJOPT_PYTHON_FILES __init__.py _direct_point2point.py _direct_pl2pl.py _mga.py _mga_1dsm.py _launchers.py _pl2pl_N_impulses.py)
install(FILES ${PYKEP_TRAJOPT_PYTHON_FILES} DESTINATION ${_PYKEP_INSTALL_DIR}/trajopt)

ADD_SUBDIRECTORY(gym)

ADD_SUBDIRECTORY(gym)
3 changes: 2 additions & 1 deletion pykep/trajopt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
# Evolutionary encodings for high energy transfers (chemical propulsion)
from ._mga import mga
from ._mga_1dsm import mga_1dsm
from ._pl2pl_N_impulses import pl2pl_N_impulses

# The launchers models
from ._launchers import _launchers
launchers = _launchers()

# The interplanetary trajectory gym
from . import gym
from . import gym
Loading
Loading