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

Updated phasing/_lambert to pygmo2 #142

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 15 additions & 18 deletions pykep/phasing/_lambert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pygmo.problem._base import base # pylint: disable=import-error
from pygmo import hypervolume
from pykep.planet import gtoc7
from pykep.orbit_plots import plot_planet, plot_lambert
Expand All @@ -7,7 +6,7 @@
from math import exp


class lambert_metric(base):
class lambert_metric:

"""
This class defines the Lambert phasing metric as published in the paper:
Expand All @@ -34,24 +33,22 @@ def __init__(self, epoch_bounds=[0, 1000], A1=gtoc7(1), A2=gtoc7(2), single_obje
lm = planet(epoch_bounds=[0, 1000], A1=gtoc7(1), A2=gtoc7(2), single_objective=False, Tmax = 0.3, Isp = 3000, ms = 1500)
"""

# First we call the constructor of the base class telling
# essentially to pygmo what kind of problem to expect (2 objective, 0
# contraints etc.)
super().__init__(
2, 0, 1 + (not single_objective), 0, 0, 0)

# then we set the problem bounds (in this case equal for all
# We set the problem bounds (in this case equal for all
# components)
self.set_bounds(epoch_bounds[0], epoch_bounds[1])
self._bounds = (epoch_bounds[0], epoch_bounds[1])
self.f_dimension = 1 if single_objective else 2
self._ast1 = A1
self._ast2 = A2
self._Tmax = Tmax
self._Isp = Isp
self._ms = ms
self._UNFEASIBLE = 1e+20

# We reimplement the virtual method that defines the objective function.
def _objfun_impl(self, x):
# We implement the get_bounds and fitness functions.
def get_bounds(self):
return self._bounds

def fitness(self, x):
from math import sqrt
# 1 - We check that the transfer time is positive
if x[0] >= x[1]:
Expand Down Expand Up @@ -111,8 +108,8 @@ def plot_orbits(self, pop, ax=None):
else:
axis = ax

plot_planet(A1, axes=axis, s=10, t0=epoch(self.lb[0]))
plot_planet(A2, axes=axis, s=10, t0=epoch(self.ub[0]))
plot_planet(A1, axes=axis, s=10, t0=epoch(self._bounds[0]))
plot_planet(A2, axes=axis, s=10, t0=epoch(self._bounds[1]))
for ind in pop:
if ind.cur_f[0] == self._UNFEASIBLE:
continue
Expand All @@ -139,7 +136,7 @@ def plot_pareto_front(self, pop):
rx, ry = self._compute_ref_point()
axis = pop.plot_pareto_fronts()
axis.set_xlim([0, rx])
axis.set_ylim([self.lb[0], ry])
axis.set_ylim([self._bounds[0], ry])
plt.xlabel("[m/s]")
plt.ylabel("[MJD2000]")
plt.draw()
Expand All @@ -154,11 +151,11 @@ def compute_hypervolume(self, pop):
return (hv.compute(self._compute_ref_point()) * DAY2SEC / AU)

def _compute_ref_point(self):
rx = self._Tmax / self._ms * DAY2SEC * (self.ub[0] - self.lb[0])
ry = self.ub[0]
rx = self._Tmax / self._ms * DAY2SEC * (self._bounds[1] - self._bounds[0])
ry = self._bounds[1]
return (rx, ry)

def human_readable_extra(self):
def get_extra_info(self):
retval = "\n\tAsteroid 1: " + self._ast1.name
retval = retval + "\n\tAsteroid 2: " + self._ast2.name
return retval