Skip to content

Commit

Permalink
adjust GA to recent changes for unit handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kdemmich committed Jan 31, 2024
1 parent 60b2b20 commit 936f22b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions WeatherRoutingTool/algorithms/genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import matplotlib
import xarray as xr
from astropy import units as u
from matplotlib import pyplot as plt
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.termination import get_termination
Expand Down Expand Up @@ -111,23 +112,23 @@ def terminate(self, **kwargs):
courses = waypoint_coors['courses']
start_times = waypoint_coors['start_times']
travel_times = waypoint_coors['travel_times']
arrival_time = start_times[-1] + timedelta(seconds=dists[-1]/speed)
arrival_time = start_times[-1] + timedelta(seconds=dists[-1].value/speed.value)

dists = np.append(dists, -99)
courses = np.append(courses, -99)
dists = np.append(dists, -99 * u.meter)
courses = np.append(courses, -99 * u.degree)
start_times = np.append(start_times, arrival_time)
travel_times = np.append(travel_times, -99)
travel_times = np.append(travel_times, -99 * u.second)

route = RouteParams(count=npoints,
route = RouteParams(count=npoints-1,
start=self.start,
finish=self.finish,
gcr=None,
route_type='min_fuel_route',
time=travel_times,
time=travel_times[-1],
lats_per_step=lats,
lons_per_step=lons,
course_per_step=courses,
dists_per_step=dists,
course_per_step=courses[-1],
dists_per_step=dists[-1],
starttime_per_step=start_times,
ship_params_per_step=self.ship_params)

Expand Down
2 changes: 1 addition & 1 deletion WeatherRoutingTool/algorithms/genetic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def get_power(self, route):

shipparams = self.boat.get_ship_parameters(route_dict['courses'], route_dict['start_lats'],
route_dict['start_lons'], route_dict['start_times'], [])
fuel = shipparams.get_fuel()
fuel = shipparams.get_fuel_rate()
fuel = (fuel / 3600) * route_dict['travel_times']
return np.sum(fuel), shipparams

Expand Down

0 comments on commit 936f22b

Please sign in to comment.