Optimal MGA and MGA-1DSM trajectories - PyKEP/PyGMO

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
Motivation

The goal of this article is to build upon the Python codes, and results described in [3],[4], generalise the problem of finding DeltaV-optimal and (DeltaV,T) optimal trajectories, and make Python utilities available to the Orbiter Community, which can solve a variety of optimal Multiple Gravity Assist problems, and output the plan in a format, which directly translates into a TransX plan, based on the mathematics of [2]


PyKEP/PyGMO
PaGMO/PyGMO, are powerful C++/Python frameworks for performing single-, and multi-objective nonlinear optimisation. They provide a flexible framework for defining new problems in a way, so that a whole regiment of optimisation algorithms (and combination of these) can be applied on the problem, all this built upon the Generalised Island Model, for easy distribution of the problem to multi-CPU, and multi-machine clusters.

PyKEP is a library, to help in defining astronomical problems. It provides tools and utilities, to access planet parameters, ephemerides, and solve corresponding problems (like Lambert's problem).

Big thanks for the ESA Advanced Concepts team for sharing this great tool.

MGA and MGA-1DSM problems
A short intuitive (non-mathematical) definition comes of the MGA and MGA-1DSM problems.
For a more detailed and precise definition, please refer to [1]

MGA
In the MGA (stands for Multiple Gravity Assist) problem, you have a sequence of planetary bodies (p_1, p_2, ..., p_n), and you want to find an interplanetary trajectory, which starts from p_1, ends in p_n, encounters bodies p_i (i = 2..{n-1}), while minimising total deltaV.

A multi-objective definition would attempt to find optimal (deltaV, T) pair, where T is the total time of the journey.

The legs of the MGA problem are the parts of the trajectory separated by the planetary encounters.

In the MGA problem, the vessel is allowed to make a burn only at the beginning, and end of each leg, thus powered fly-byes are possible, but no Deep Space maneuver is allowed.

The decision vector of the problem is [t0, t_1, t_2, ..., t_n], where t_i is the time of encounter with the ith planetary body.

To solve a multi-leg problem like this, it is common practice to treat the legs individually. So for a given value of the decision vector, we have n-1 problems, which say: I want to leave p_i at t_i and arrive at p_{i+1} at time t_{i+1}. The resulting problem is called Lambert's problem, which given some restrictions employs a single solution, and we saw it's utilisation in the cited works of Keithth G.

Note: The scripts shared in [2] are basically solving the MGA problem, but instead of bounding on t0 and T, it requires a common bound on all the t_i.

MGA-1DSM
In the MGA-1DSM problem, the task is the same, however the vessel is allowed to make at most 1 Deep Space Maneuver during each leg.

The concepts and mathematics are discussed in detail in [1]. The basis of my problem implementations were mainly the ESA code, as well as Keithth G's code.

Overview of my contributions
The coding I've done can be located in this Github repository

The main script performs the following:
  1. Executes a given number of MGA rounds (single-objective), and keeps hold of the best MGA solution
  2. Execute a given number of MGA_1DSM rounds (multi-objective), and keeps hold of the best MGA-1DSM solution

I found this approach beneficiary while tuning the algorithms, since seeing the best MGA and best multi-objective MGA_1DSM solution together gives us a hunch about how good our plan got to the truth.

Since if the travel time of the MGA plan is considerably higher than that of the MGA_1DSM plan, but the deltaV increase is moderate compared to the decrease of travel time, because the solutions of both MGA and MGA_1DSM are heavily clustered, we are probably in the good basin of low deltaV solutions.

But I'd like to note here the dimension of the MGA-1DSM problem is considerably higher, so both the iterations, both the convergence time are much longer. If you just want a quick plan, execute 5 rounds of MGA. If you feel it's too long, you can execute MGA-1DSM, but then you might want to go out for a coffee.

The main script to run, is OrbiterKEP.py, and the usage is something like this:
Code:
OrbiterKEP.py <comma delimited planets> <t0_min,t0_max> <T_min, T_max> <max vinf> <n_mga> <n_mga_1dsm>

t0_min, t0_max: Bounds for the launch window, in ISO date format, e.g. '20160629T151758'
  • T_min, T_max: Bounds for the travel time in years
  • max_vinf: Only or MGA_1DSM, bounds for the initial Hyperbolic Excess Velocity (depends on Launcher performance)
  • n_mga: The number of MGA executions. The best solution is selected.
  • n_mga_1dsm: The number of MGA_1DSM executions. The best solution is selected.

Notes about the current code
  • The departure is assumed to happen from 300km circular orbit
  • Arrival is assumed to happen to a 300km orbit, and fuel calculations assume that we circularise.
  • The current state of the code reflects the results of quite some heuristic experimenting, and not scientifially fine-tuned. I have no idea of the statistical significance of the minimums found by the script, but they are fairly consistent.
  • The outputted deltaVs are larger than the published minimums of some known problems, because I found that they include only capture and not circularisation at the end, and they sometimes omit the initial Vinf from the optimisation (i suppose because that depends on the Launcher, more than on the vessel.

At the end of the execution, or when it is interrupted, the (so far) best MGA and MGA-1DSM solutions are both printed out, in the format which Keithth G layed down, and which can be directly inputted into TransX to fly the plan.

Sample execution
Code:
python OrbiterKEP.py earth,jupiter,earth 20160529T000000,20200731T000000 0.1,4 10 1 1

Output:
Code:
12882.99921
Done!! Best solution found is: 12.882999206 km / sec
16828.0437288
14500.6366084
14006.4646272
13924.0551128
13884.0113768
13852.7141831
13791.7759761
13763.0262554
13736.4288525
13684.9405694
13656.0140438
13644.4253897
13634.2810758
13634.0894901
13633.8290046
13626.7727111
13622.0974784
13617.9261942
13613.5450787
13606.7856869
13606.1563411
13605.9139066
13605.7153147
13605.4892069
13601.4990365
13601.2014242
13601.1011724
13600.3886857
13599.2203557
13598.8548067
13598.6778531
13598.6736536
13597.2842989
13597.1774475
13597.0142723
13596.9133169
13596.742478
13596.5965887
13596.3932734
13596.3331935
13596.3143379
Done!! Best solution found is: 13.5962557481 km / sec
Date of earth encounter: 2018-Jan-13 21:13:52.196100
Date of jupiter encounter: 2020-Jan-24 09:35:24.244445
Date of earth encounter: 2021-Dec-09 07:20:06.195060
Transfer time from earth to jupiter:740.51 days
Transfer time from jupiter to earth:684.91 days
Total mission duration:              1425.42  days


TransX escape plan - earth escape
--------------------------------------
MJD:                 58131.8846 
Prograde:              8927.602 m/s
Outward:                -37.438 m/s
Plane:                 -154.875 m/s
Hyp. excess velocity:  8929.024 m/s
Earth escape burn:     6384.606 m/s


jupiter encounter
--------------------------------------
MJD:                 58872.3996 
Approach velocity:     7468.580 m/s
Departure velocity:    7468.580 m/s
Outward angle:         -135.564 deg
Inclination:             -1.454 deg
Turning angle:           82.924 deg
Periapsis altitude:  1087475.220 km 
dV needed:                0.000 m/s


earth arrival
--------------------------------------
MJD:                 59557.3056    
Hyp. excess velocity:  9107.778 m/s
Orbit insertion burn   6498.394 m/s


Total fuel cost:      12882.999 m/s
Date of earth encounter: 2020-Apr-09 15:39:13.116140
Date of jupiter encounter: 2022-Mar-21 21:09:42.877770
Date of earth encounter: 2024-Feb-14 06:51:18.113795
Transfer time from earth to jupiter:711.23 days
Transfer time from jupiter to earth:694.4 days
Total mission duration:              1405.63  days


TransX escape plan - earth escape
--------------------------------------
MJD:                 58948.6522 
Prograde:              8484.038 m/s
Outward:               4974.500 m/s
Plane:                 1418.920 m/s
Hyp. excess velocity:  9936.694 m/s
Earth escape burn:     7042.880 m/s


Deep Space Burn
--------------------------------------
MJD:                 59659.5309 
Prograde:                 0.128 m/s
Outward:                  0.258 m/s
Plane:                   -0.233 m/s
Hyp. excess velocity: 38538.945 m/s
DSM burn:                 0.370 m/s


jupiter encounter
--------------------------------------
MJD:                 59659.8817 
Approach velocity:     7172.166 m/s
Departure velocity:    7172.166 m/s
Outward angle:         -144.339 deg
Inclination:              2.690 deg
Turning angle:           68.305 deg
Periapsis altitude:  1852597.259 km 
dV needed:                0.000 m/s


Deep Space Burn
--------------------------------------
MJD:                 60354.2787 
Prograde:                -0.027 m/s
Outward:                 -0.096 m/s
Plane:                   -0.058 m/s
Hyp. excess velocity:  8863.420 m/s
DSM burn:                 0.115 m/s


earth arrival
--------------------------------------
MJD:                 60354.2856    
Hyp. excess velocity:  9192.657 m/s
Orbit insertion burn   6552.891 m/s


Total fuel cost:      13596.256 m/s

As you see, in this case the MGA-1DSM plan is just a very expensively obtained inferior version of the MGA plan. The DSMs are basically 0, an the deltaV we paid for 20 days shorter trip is way much. So for recreational use, I recommend the MGA only execution.

It's way faster, and the result is usually quite OK.

Possible areas of future research, to make more use of PyKEP/PyGMO (or other trajectory optimisation tools) in Orbiter
  • Possibly a plugin, which provides in-Orbiter ways to help in execution of the plan, by e.g. setting up TransX for each legs, by inputting velocities, angles, so that user only has to finalise the maneuver.
  • Improve the performance of the scripts to the degree, where it is possible to do live execution using an MFD.
  • Find better combination of algorithms to tackle the MGA and MGA-1DSM problems.

Author's notes
This article, and the corresponding code was created out of mere enthusiasm, and though I have some prior knowledge and experience with Global Optimisation, is completely empiric, and not in any way claims to be comparable with real-world trajectory planning (though it might be).

Any piece of code on Github are free to reproduce, modify, redistribute, in any way.
If you need a hand in you project where you'd use it, give me a note, I might be interested ;)

This article would not exist without

- Advanced Concepts team of ESA creating the great tools PyKEP and PyGMO are, and making it available to the research community for free
- Keithth G bringing the tools to our attention.

Bibliography

[1] Izzo - Global Optimization and Space Pruning for
Spacecraft Trajectory Design


[2] PyKEP to TransX conversion

[3] Optimal Earth-Venus-Mercury transfer - PyKEP / PyGMO

[4] Earth to Jupiter on less than 2 m/s a day, the PyKEP way!

Update: 2016-05-30
The multi-objective parts of the script are not quite good yet, and also the performance is terrible. Porting of problem definitions to C++ is in progress, and also an update to allow for nice draw-up of Pareto fronts for the Multi-objective case, which visualises the trade-off very good.
 
Last edited:

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
Update

After the initial struggling with Python, I had to realise that in case of PaGMO, the wrapper solution is adding way too much overhead, which makes the calculations terribly slow.

The performance of the Python scripts are incomparable to the speed of the full C++ solution.

Building this stuff in an MFD just got a bit closer. Actually I can totally imagine it as an IMFD Program (called MGA Program).

To get the updates, check out the Github repository.
https://github.com/tuzcsaba/orbiter-kep

If you managed to install PaGMO and PyKEP in the first place, the build process will be familiar, please refer to one of the related articles for a bit more details.
 
Last edited:

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
Installation, and sample usage of the C++ tool

Announcement
I hereby announce a pretty well usable version of the tool which I (terribly) named OrbiterKEP.

Since it's quite usable, and now on C++ base also blazing fast.

In this post, I will take a classic MGA-1DSM problem, the epic journey of Cassini to Saturn, using a 5-leg MGA with Deep Space Maneuvers allowed.

I apologise hereby for Windows users, it is possible to get things running on Windows as well, but this doc only has 1-1 correspondence to reality for UNIX based systems (Linux, Unix, OS X).

If you got through installation of PaGMO and PyKEP, then I'm sure you'll be able to use this info.

Prerequisites
I will assume that your system satisfies the following preconditions:
  1. You managed to install PaGMO and PyKEP on your computer
  2. In the process you learned how the CMake build system works, including it's 'ccmake' config interface
  3. You have 'gnuplot' installed

Fortunately getting through 1) ensures that you have all the necessary tools to build OrbiterKEP, and installation should be very easy.

Getting sources

Navigate to a folder of your choosing, which is going to be our playground for this.

Code:
$> git clone [email protected]:tuzcsaba/orbiter-kep.git

Wait for the GIT clone to finish.

Compiling the sources

Code:
$> cd orbiter-kep
$> mkdir build
$> cd build
$> ccmake ../

You'll end up in ccmake's config UI. Here you should be able to proceed by
  • Pressing 'c'
  • Navigate to CMAKE_BUILD_TYPE line with arrows, and press Enter
  • Type 'Release', then press Enter
  • Here I press 'c' again, probably unneeded
  • Press 'g'

You should be good to go to 'make' the utility
Code:
$> make -j4
[ 11%] Building CXX object src/CMakeFiles/orbiterkep_static.dir/optimise.cpp.o
[ 22%] Building CXX object src/CMakeFiles/orbiterkep_static.dir/problems/transx_problem.cpp.o
[ 33%] Building CXX object src/CMakeFiles/orbiterkep_static.dir/problems/mga_transx.cpp.o
[ 44%] Building CXX object src/CMakeFiles/orbiterkep_static.dir/problems/mga_1dsm_transx.cpp.o
[ 55%] Building CXX object src/CMakeFiles/orbiterkep_static.dir/plot/pareto.cpp.o
[ 66%] Building CXX object src/CMakeFiles/orbiterkep_static.dir/ps/renderer.cpp.o
[ 77%] Linking CXX static library liborbiterkep_static.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: liborbiterkep_static.a(renderer.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: liborbiterkep_static.a(renderer.cpp.o) has no symbols
[ 77%] Built target orbiterkep_static
Scanning dependencies of target OrbiterKEP
[ 88%] Building CXX object CMakeFiles/OrbiterKEP.dir/OrbiterKEP.cpp.o
[100%] Linking CXX executable OrbiterKEP
[100%] Built target OrbiterKEP
$>

If you see something like this, you should have a binary file 'OrbiterKEP' in the same folder, and you should also be able to run it.

Basic usage

Code:
$> ./OrbiterKEP --help

USAGE: 

   ./OrbiterKEP  [--spice] [--opt-gen <n>] [--omit-arr-vinf]
                 [--omit-dep-vinf] [--max-delta-v <m/s>] [--capture-only]
                 [--multi-obj] [--arr-altitude <f>] [--dep-altitude <f>]
                 [--n-mga-1dsm <n>] [--n-mga <n>] [--vinf-max <max_vinf>]
                 [--tof-max <max_tof>] [--tof-min <min_tof>] [--launch
                 <min_tof,max_tof>] [--planets <p_1,p_2,...,p_n>] [--]
                 [--version] [-h]


Where: 

   --spice
     use JPL SPICE toolkit for getting ephimerides

   --opt-gen <n>
     the number of generations to run each trial for

   --omit-arr-vinf
     if on, the fuel calculations won't include the initial Vinf

   --omit-dep-vinf
     if on, the fuel calculations omit the final capture burn

   --max-delta-v <m/s>
     Delta-V budget

   --capture-only
     if on, the fuel calculations at arrival assume circular target orbit

   --multi-obj
     if true, then we optimise for Delta-V and Time of Flight

   --arr-altitude <f>
     the target altitude at the target body in kms

   --dep-altitude <f>
     the ejection altitude in kms

   --n-mga-1dsm <n>
     the number of independent MGA-1DSM optimisations

   --n-mga <n>
     the number of independent MGA optimisations

   --vinf-max <max_vinf>
     maximum allowed initial Hyperbolic Excess Velocity in km/s (check
     Launcher performance)

   --tof-max <max_tof>
     maximum time of flight

   --tof-min <min_tof>
     minimum time of flight

   --launch <min_tof,max_tof>
     the bounds for the launch window

   --planets <p_1,p_2,...,p_n>
     encountered planetary bodies

   --,  --ignore_rest
     Ignores the rest of the labeled arguments following this flag.

   --version
     Displays version information and exits.

   -h,  --help
     Displays usage information and exits.


   Calculate Optimal MGA and MGA-1DSM trajectories

I think the '--help' output helps a lot on the general usage. What I will try to focus on here, is how to attack an MGA problem with the tool, what you can learn from each step, and what you can do to deepen your analysis of the problem.

A sample run

First we want to get a basic idea about the problem, so we do a multi-objective analysis first, with very unrealistic bounds, to get the basic idea of how our problem's pareto fronts look, what tradeoff we have between time and fuel cost.

Code:
$> ./OrbiterKEP --launch 19960101T000000,19980101T000000 --tof-min 0.1 --tof-max 20 --vinf-max 20 --planets "earth,venus,venus,earth,jupiter,saturn" --max-delta-v 200000 --n-mga 1 --multi-obj --opt-gen 10000 2>/dev/null

The above call picks a launch window which contains the original Cassini launch date, we basically let Time-of-Flight go up to 20 years time (which is more than what Cassini flew), and we let an unrealistically large initial V_inf as well.

This is not to obtain the actual plan we will fly, but to get a good exploration of the Pareto fronts.

I chose to use the MGA problem for this example, even though we know that Cassini did a Deep Space Maneuver between the two Venus encounters. This is to speed things up, and also MGA-1DSM suffers from the curse of dimensionality a bit, and I am concerned it might be buggy as well.

To be continued...

Most likely in a separate thread, because I am quite occupied now with the following things:
1. Since the end result is non-deterministic, I felt that I need some kind of persistence which allows the different solutions to be preserved, so that if you keep running the same problem multiple times, you won't lose the all-time best solution. I chose MongoDB.
2. Trying to figure out a way, to output for each Problem a coherent Document, which contains the drawing of the Pareto fronts, the plan itself, and some additional data.
3. As now I count 5 dependencies that need to be built and installed, I want to make whatever I can optional, so that it's possible to get started with only PaGMO and PyKEP(keplerian_toolbox).

As this tool escalates further, I promise there'll be a nice fully developed example. This post however should be able to get the ,,playful ones'' started on the idea.
 
Last edited:

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Awsome! Thanks. I'll try it this week, I believe.

So far I can't clone:
Code:
git clone [email protected]:tuzcsaba/orbiter-kep.git
Cloning into 'orbiter-kep'...
The authenticity of host 'github.com (192.30.252.123)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.123' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
 

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
Cześć Enjo!

All I can think of, is that you might not have added your public key to GitHub for authentication.
HTML:
https://github.com/settings/keys

Try the HTTPS endpoint
Code:
git clone https://github.com/tuzcsaba/orbiter-kep.git
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Thanks. The HTTPS solution worked. Now I need to install the dependencies. If I continue failing, I'll let you know.

---------- Post added 03-06-16 at 08:08 AM ---------- Previous post was 02-06-16 at 05:50 PM ----------

OK, I'm stuck. Somehow the include <pagmo/pagmo.h> didn't get installed, although I had chosen to install headers. Do you know how to fix it?

[EDIT] I think I'll give up for now, but after you successfully package it as a binary, and then code it into an MFD, then we HAVE to make it communicate with TransX via [ame="http://www.orbithangar.com/searchid.php?ID=6889"]ModuleMessagingExt[/ame]. [ame="http://www.orbithangar.com/searchid.php?ID=3992"]This Open Source MFD[/ame] should teach you how to draw the resulting orbits. And if you need some more space to draw the orbits, here's [ame="http://www.orbithangar.com/searchid.php?ID=6023"]a bigger canvas for ya[/ame].
 
Last edited:

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
Enjo, thank you for taking interest in this.

I am sorry that it didn't work out well, a possible problem might be that PaGMO was installed with a different prefix (e.g. /usr), than the utility (e.g. /usr/local)

This can be the other way around as well.

You can do
Code:
find /usr | grep pagmo
to find where the PaGMO headers are installed, and if it's not /usr/local/include, then you need to edit the CMakeLists.txt file, but I'll do it for you.

If you want we can do some kind of 1-on-1 session to get you running, our timezones are in align. It would help me a lot in figuring out how to modify the build scripts, so that they are more flexible for different environments.

Thank you for the MFD resources, I don't know when I get to it. Now I am operating on a Mac, I'll need to move over to Windows, and make things work there, link the whole stuff statically, and then start an MFD project in which I try to use the static libraries.

I feel it'll be a long way ahead, but when I come to that, I'd definitely like to catch up with you, to integrate this thing with your MFDs.
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
I'm looking forward to it. It's very innovative stuff here.

Code:
enjo@ip2505504b:~$ find /usr | grep pagmo.h
/usr/include/pagmo/src/pagmo.h
Weird install location, isn't it? I chose the /usr prefix for both libraries instead of /usr/local

0) Edited CMakeLists.txt
1) I needed to modify your sources, by removing the prefix <pagmo/*>
2) You forgot to mention the gnuplot-iostreams dependency
3) Trying to compile and getting:

Code:
/home/enjo/Downloads/src/orbiter-kep/src/optimise.cpp: In member function ‘pagmo::decision_vector orbiterkep::optimiser::run_once(const decision_vector*, bool, double)’:
/home/enjo/Downloads/src/orbiter-kep/src/optimise.cpp:17:67: error: ‘pagmo::migration::rate_type’ is not a class or namespace
   pagmo::migration::best_s_policy sel_single(2, pagmo::migration::rate_type::absolute);


---------- Post added at 11:53 AM ---------- Previous post was at 11:42 AM ----------

Thank you for the MFD resources, I don't know when I get to it. Now I am operating on a Mac, I'll need to move over to Windows, and make things work there, link the whole stuff statically, and then start an MFD project in which I try to use the static libraries.
Have you considered simply cross-compiling with MinGW?

---------- Post added at 12:11 PM ---------- Previous post was at 11:53 AM ----------

If you want we can do some kind of 1-on-1 session to get you running, our timezones are in align. It would help me a lot in figuring out how to modify the build scripts, so that they are more flexible for different environments.
I prefer polluting the forum thread :) I can only work on projects other than mine in short bursts of time, when I have it.
 
Last edited:

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
Enjo, I am sorry, indeed I forgot about a few details here.

0. The pagmo installer installs all the headers in a 'src' subfolder, so they don't end up where they should be. I did a manual repair of that early on, and completely forgot about it. I simply moved all from under 'src' one folder up.

1. If you do that, you don't need to change the <> includes.

2. As a baseline, I am adding dependencies as submodules under third_party. Same is with gnuplot-iostreams. The reason I didn't mention it, because if you do
Code:
git submodule update
there should be no other task with it, it's just a .h, so no need to build it or anything, once it's in place.

3. As for the compiler error, pagmo::migration::rate_type is an enum defined in:
<pagmo/migration/base.h>
The master header import
#include <pagmo/pagmo.h> should pull it in, if you move the damn headers to their correct location.

Sorry for all this mess,

p.s Difficulties of getting this into an MFD, are more conceptual than technical. Of course, I'll probably end up cross-compiling this thing using MinGW, and then getting it in an MFD implementation, for which I have to read and learn a lot at this point.

The problem is more with how this thing will operate in an MFD:
  • Global optimization is a messy business. You run the algorithm, it'll come up with a result, which is with a good chance only a local optimum.
  • The second time you run it, you'll get a different local optimum.

With a good setup, which PaGMO is, statistically you'll end up very near to the global optimum, but you need several dozen rounds to get near enough.

So some kind of DB storage will be necessary, to act as a memory, so that the results of previous runs are saved.

The optimisation rounds themselves have to be made in a way, so that they don't disturb simulation.

So as a Phase 1, what I will shoot at, is not this.

I want to detach the optimisation itself from the MFD, make it output a binary format which can be fed into an MFD, and the MFD would merely act as a helper, which shows some info about the plan, and feeds it into TransX and IMFD, and Orbit MFD, and whatever.

Oh, I have so much plans, and so little time :) But I'll get to it I'm sure...

---------- Post added at 02:16 PM ---------- Previous post was at 10:28 AM ----------

As I am modifying the code at this phase quite aggressively, let's move the deeper technical discussion about the code to GitHub:
https://github.com/tuzcsaba/orbiter-kep/issues

Feel free to create issues of all kind there, installation, execution, the math behind it, anything, and let us discuss it there further, before we completely make this Thread a noise-pile.
 
Last edited:

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
Hard part over, now the tedious part comes. Ideas appreciated

Hi.

This is my last post on this thread, last piece of news. Further posting will be related to the so called GravityAssistModule, which provides:
- A DLL and headers, to integrate in any Orbiter Module, which solve the MGA and MGA-1DSM problems using PyKEP and PaGMO, within Orbiter.

THe linkage issues were hell. Most of the DLL is compiled in MinGW, it needs Boost, and PyKEP, and PaGMO, so lots of dlls, but it links nice in MSVC, and using an extern "C" interface it is possible to invoke the main optimisation routine, by sending over a serialized Protocol Buffer.

Phase 1:
- I am building a Module, which allows the entering, and solving of the problems talked about here, from within Orbiter, and outputs the familar format to fly the plan. THis feature is implemented in a dialog.

Phase 2:
- I am planning to build an MFD, which presents the plan on-screen. Right now I thing I'll try to utilize HUDDrawerSDK for this and print the plan on the screen somewhere.

Phase 3:
- I am adding ModuleMessaging hooks, to expose the plan for any interested MFDs.

------ When I reach this phase, I'll start documenting the existing stuff ------

Phase 4:
- Whatever.

Anyone interested in helping, or have ideas, or anything, please link up with the Github page:
https://github.com/tuzcsaba/orbiter-kep
 

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
I think that this is an excellent development. I fully appreciate that compressing PyKEP and PyGMO into a general purpose MFD is a real technical achievement. You have my full support. However, I am more of a theoretician than a programmer so there may be a limit to what I can do in practice to help you in the task that you have set yourself.
 
Last edited:

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
This sounds great! Let me know if you have any issues with my libraries (or MFD coding in general), or just need a quick tip without spending time on reading the implementation examples.
You might also want to take a look at the MultipleVesselsMFD library, that allows for MFD parameter persistence, as well as multiple vessels support (normally the vessels' variables are shared across different vessels)

---------- Post added at 07:10 AM ---------- Previous post was at 06:19 AM ----------

Phase 2:
- I am planning to build an MFD, which presents the plan on-screen. Right now I thing I'll try to utilize HUDDrawerSDK for this and print the plan on the screen somewhere.
It doesn't need to be an MFD, just an oapi::Module is enough, especially if you enter the values via dialog already, and plan to display data on the HUD. I think you can also use the MultipleVesselsMFD library for a pure plugin. It's just an abstraction, which suggests to be used for MFDs, but looking back at the sources, I don't see any actual MFD dependencies there.

Phase 3:
- I am adding ModuleMessaging hooks, to expose the plan for any interested MFDs.
So the pipeline would be to:
- plan the mission through your dialog and expose them
- obtain them through TransX and expose launch parameters for the parking orbit
- obtain the parameters through Launch MFD
- profit
 
Last edited:

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
Nice work f1re. I wish you good luck working on the code. The MFD and the ModuleMessagingExt interface code is easy - and Enjo or I can help you with that when you need us. You just need to figure out the API interfaces to your code .. what data or commands you need to get and what data you wish to produce. We can write any of these to interface to you:

1. The MFD and HUD Drawing routines to compile directly into your code, so you have a full MFD of your own.
2. MFD and HUD drawing routines that compile as a DLL, and dynamically call your DLL through your API.
3. If you don't need a MFD display, but you prefer to interact with humans through TransX or LaunchMFD, or BaseSync, or whichever MFD that supports ModuleMessagingExt, then we can create a bridge DLL that just interfaces your standalone app or DLL to ModuleMessagingExt (e.g. to talk on whatever local procedure call, message bus or other interface you prefer.)

TL;DR ... continue developing the code, then work on the API, then discuss how you want to plug it together.
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Phase 2:
- I am planning to build an MFD, which presents the plan on-screen. Right now I thing I'll try to utilize HUDDrawerSDK for this and print the plan on the screen somewhere.
Just one more thought here: if you learn how to draw on the HUD, you should have very little problem transferring the drawing routines to an MFD later. Just remember to be able to draw with an assumption of varying width and height of the drawing context.
In this context, you could treat HUDDrawerSDK drawing as a Pre-MFD step, so that you have any visual feedback before doing something larger. Maybe one day I could code the MFD interface myself and commit the code to your GIT project (think of outsourcing, or forking :) )

---------- Post added at 12:54 PM ---------- Previous post was at 12:51 PM ----------

We can write any of these to interface to you:

1. The MFD and HUD Drawing routines to compile directly into your code, so you have a full MFD of your own.
Not so fast. The HUD Drawing must be centralized to work correctly with other modules in the queue for the HUD drawing context. So only the DLL option is available here.
[EDIT] Or do you mean specifically drawing ellipses and other shapes?
 
Last edited:

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
Enjo, ADSWNJ, Keithth G, thanks for all so far.

I expect that I'll disappear with this thing for a while, and report back once I have something worthy of showing.

We can get back to the interfacing matters at that point. I will expose data from my DLL, but I don't want to get into possible patches to TransX using this data, until the thing is rock solid as a standalone tool within Orbiter, with manual feeding of the data into TransX.
I did very little Win32 programming in the past, and right now I am pacing like a snail.

So you'll hear from me, but as my schedule looks for next few weeks, not for a short while.

Until then, Cheers.
 

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
So you'll hear from me, but as my schedule looks for next few weeks, not for a short while.

Of course - that's the deal for all of us. Real life comes first!
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Of course - that's the deal for all of us. Real life comes first!
Something tells me, that the Orbiter addon development addiction might be stronger...

Just for reference, before I forget - Re: Phase 2 - MFD:
There's a MFD button page template, which simplifies coding of the buttons, and is especially helpful, when you plan on having a number of buttons greater than the default number.
 

f1re

Donator
Donator
Joined
Apr 26, 2016
Messages
24
Reaction score
0
Points
0
GravityAssistMFD-0.1

So, here's the basic idea, but it's a nothing yet, a simple prototype.

I did went to Jupiter on the Galileo track with it though, so it's definitely usable already to some degree.

Usage in a nutshell

So you copy the things in the ZIP in your Orbiter root folder as usual, and enable the module, as usual.

The start up simulator, and Ctr+F4, open the dialog "Find Optimal MGA solution"

You will get a bunch of things to set, and the default settings reflect a plan similar to Keithth G's original example, trip to Mercury, with GA around Venus.

Important note: The solutions are cached, and stored between sessions. A problem is defined by the Departure, ARrival altitudes, and the planets you wish to encounter. The other options affect the Optimization, but belong under the same cache key, no matter what they are set to.

You have a Reset Solutions button to clear the cache.

The PaGMO section is something for more advanced tweaks. The only thing you might want to decrease from 8, is the "Number of Islands" setting.
The others are fairly OK, and I'll gladly explain later what they are for if anyone interested. The other field of interest is "Generations", but 100000 is plenty for MGA. For MGA-1DSM you might want higher, and also if you do multi-objective, you might want to double it to increase convergence to the Pareto fronts.

So you have your plan set up, you press Find Optimum, and the found plan starts to pop into the textfield on the right.

That's Phase 1.

The thing has an MFD too, GravityAssistMFD. When you open it, it'll draw the basic timeline of the mission on the HUD, and the current stage in the MFD area. It's time based, so you might want to rewind to before the escape to see the details of the escape.

This way you have a plan, which goes for minimal deltaV, and fits into the specified bounds.

Great, but what if we can afford a bit larger deltaV, if the trip could take a bit less time.

That's where you go multi-objective. It'll take more time, but you'll get idea about the trade-off between time and deltaV.

For this, you just need to press Pareto fronts on the dialog.

And wait... If you have the time, you can up Generations to 200000, to get more convergence in the you'll see what...

So it will go on for a while, but when it's done, you'll have a nice graph under the stage details. What it shows, is the Time vs. DeltaV pareto fronts.

These are points, where you cannot improve one variable, without making the other variable worse. In a multi-objective optimization, you hunt for the pareto-points, because there is no clear definition of "Best".

For guidance, the graph also contains the values for T and deltaV. T is in days, deltaV is in m/s.

So if you went the default plan, you see that we have a 10187m/s plan which takes us to Mercury in 271.61 days.

And from the graph, you can read, that you can half the journey time, by dropping in another 2000m/s. It's all about what are your constraints.

So let's say, you want to get to Mercury in less than half a year. So put in 0.5 to the upper bound of "Time of Flight".

Of course, this will be a more expensive solution, so in order so that you can find it, you have to Reset Solutions, then Find Optimum again.

There we go, instead of 271 days, we can get to Mercury in 182.62 days, and the cost is 10743.21 m/s versus 10187m/s. THat's not bad.

But in Multi-objective it's totally up to you, what kind of plan you want. The tool only helps you find the best deltaV solution which fits the constraints.

This is 0.1, I don't call it a release, it's a preview demo, and I'd be delighted to hear back your experience.

Also, I can only hope that I packed all the dependencies, if I missed something, please ping.

Oh, also please note, this is learning code for me, and my first MFD. I was not quite pragmatic in the coding at this point, with regards to S.O.L.I.D, but I'll clean the code up as well eventually.
The module exposes variables using ModuleMessaging lib.
 

Attachments

  • GravityAssistMFD-0.1.zip
    4.7 MB · Views: 8
Last edited:

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
Thank you very much, 'f1re' for doing this. Personally, I think this is a bit of a milestone for Orbiter trajectory planning. Although this may be a bit technical for some (or even most) users, it represents a sizeable leap forward in the ability for Orbiter 'mission planners' to design some very realistic, and now optimised, trajectories.

I don't have time to download and explore at the moment, but I will when I have the opportunity to do so.

Well done.
 
Last edited:

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Great. I knew that you couldn't resist :)
I can't comment the operation itself yet, because your binary suffers from this known issue.

If I could already suggest something regarding packaging of your addon:
1) Could you please move the "MGAPlans" under "Config/MFD" directory? Less root tree pollution.
2) I know your project is open to public via Web, but would it be possible if you script automatic fetching of the source and store it under "OrbiterSDK/GravityAssistMFD" before zipping and distributing?

[EDIT] Could you point me to the source, where you expose the variables via ModuleMessagingExt?
 
Last edited:
Top