-
Notifications
You must be signed in to change notification settings - Fork 80
Add speed information to all chromosomes of the genetic algorithm #117
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5d30a2d
delete leftover of PMX crossover
kdemmich d3733ce
modify Chromosomes in RandomPlateauMutation to contain speed information
kdemmich d919826
add speed to chromosome in RouteBlendMutation
kdemmich fcdd3b0
draft addition of speed information to RandomWalkMutation
kdemmich c26bd40
draft addition of speed information to chromosomes in repair and patcher
kdemmich d9f1583
[unit tests] mark monitoring tests as manual & save figures via
kdemmich 5515eac
Merge branch 'main' into OptimiseSpeedGA
kdemmich 736310f
fix run-time errors and unit tests
kdemmich 376598d
[unit tests] add test for routeparams.get_waypoint_coords
kdemmich 93f71ab
fix linting
kdemmich 96a91c3
adapt docstrings
kdemmich 9a6bf31
adapt docstrings
kdemmich 5434e62
Merge branch 'main' into OptimiseSpeedGA
kdemmich a79248d
[gcrslider] add boat speed to initial population
kdemmich 90e7287
[genetic] add speed information to GridBasedPopulation
kdemmich c6e439a
[genetic] add speed information to FromGeojsonPopulation
kdemmich 48fc034
fix linting
kdemmich 9cd2ed0
fix unit test for routeparams
kdemmich faf742f
[genetic] add type hints for src and dst in patcher
kdemmich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -62,6 +62,8 @@ def __call__(cls, *args, **kwargs): | |
| class GreatCircleRoutePatcher(PatcherBase): | ||
| """Produce a set of waypoints along the Great Circle Route between src and dst. | ||
|
|
||
| The same speed as the speed at `src` is added to every waypoint. | ||
|
|
||
| :param dist: Dist between each waypoint in the Great Circle Route | ||
| :type dist: float | ||
| """ | ||
|
|
@@ -73,20 +75,26 @@ def __init__(self, dist: float = 10_000.0): | |
| # variables | ||
| self.dist = dist | ||
|
|
||
| def patch(self, src: tuple, dst: tuple, departure_time: datetime = None, npoints=None, ) -> np.ndarray: | ||
| def patch(self, | ||
| src: tuple[float, float, float], | ||
| dst: tuple[float, float, float], | ||
| departure_time: datetime = None, | ||
| npoints=None, | ||
| ) -> np.ndarray: | ||
| """Generate equi-distant waypoints across the Great Circle Route from src to | ||
| dst | ||
|
|
||
| :param src: Source waypoint as (lat, lon) pair | ||
| :type src: tuple[float, float] | ||
| :param dst: Destination waypoint as (lat, lon) pair | ||
| :type dst: tuple[float, float] | ||
| :return: List of waypoints along the great circle (lat, lon) | ||
| :rtype: np.array[tuple[float, float]] | ||
| :param src: Source waypoint as (lat, lon, v) triple | ||
| :type src: tuple[float, float, float] | ||
| :param dst: Destination waypoint as (lat, lon, v) triple | ||
| :type dst: tuple[float, float, float] | ||
| :return: List of waypoints along the great circle (lat, lon, v) | ||
| :rtype: np.array[tuple[float, float, float]] | ||
| """ | ||
|
|
||
| geod: Geodesic = Geodesic.WGS84 | ||
| line = geod.InverseLine(*src, *dst) | ||
| line = geod.InverseLine(*src[:-1], *dst[:-1]) | ||
| speed = src[2] | ||
|
|
||
| if not npoints == None: | ||
| self.dist = line.s13 / npoints | ||
|
|
@@ -97,7 +105,7 @@ def patch(self, src: tuple, dst: tuple, departure_time: datetime = None, npoints | |
| for i in range(npoints + 1): | ||
| s = min(self.dist * i, line.s13) | ||
| g = line.Position(s, Geodesic.STANDARD | Geodesic.LONG_UNROLL) | ||
| route.append((g['lat2'], g['lon2'])) | ||
| route.append((g['lat2'], g['lon2'], speed)) | ||
|
|
||
| return np.array([src, *route[1:-1], dst]) | ||
|
|
||
|
|
@@ -256,14 +264,20 @@ def _setup_components(self) -> tuple[WeatherCond, Boat, WaterDepth, ConstraintsL | |
|
|
||
| return wt, boat, water_depth, constraints_list | ||
|
|
||
| def patch(self, src, dst, departure_time: datetime = None): | ||
| def patch(self, | ||
| src: tuple[float, float, float], | ||
| dst: tuple[float, float, float], | ||
| departure_time: datetime = None | ||
| ): | ||
| """ | ||
| Produce a set of waypoints between src and dst using the IsoFuel algorithm. | ||
|
|
||
| :param src: Source waypoint as (lat, lon) pair | ||
| :type src: tuple[float, float] | ||
| :param dst: Destination waypoint as (lat, lon) pair | ||
| :type dst: tuple[float, float] | ||
| The same speed as the speed at `src` is added to every waypoint. | ||
|
|
||
| :param src: Source waypoint as (lat, lon, speed) triple | ||
| :type src: tuple[float, float, float] | ||
| :param dst: Destination waypoint as (lat, lon, speed) triple | ||
| :type dst: tuple[float, float, float] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also add type hints of the method arguments? |
||
| :param departure_time: departure time from src | ||
| :type departure_time: datetime | ||
| :return: List of waypoints or list of multiple routes connecting src and dst | ||
|
|
@@ -272,7 +286,7 @@ def patch(self, src, dst, departure_time: datetime = None): | |
| self.patch_count += 1 | ||
|
|
||
| cfg = self.config.model_copy(update={ | ||
| "DEFAULT_ROUTE": [*src, *dst], | ||
| "DEFAULT_ROUTE": [*src[:-1], *dst[:-1]], | ||
| "DEPARTURE_TIME": departure_time | ||
| }) | ||
|
|
||
|
|
@@ -303,9 +317,11 @@ def patch(self, src, dst, departure_time: datetime = None): | |
| logger.debug('Falling back to gcr patching!') | ||
| return self.patchfn_gcr.patch(src, dst, departure_time) | ||
|
|
||
| speed = np.full(min_fuel_route.lons_per_step.shape, src[2]) | ||
|
|
||
| # single route | ||
| if self.n_routes == "single": | ||
| return np.stack([min_fuel_route.lats_per_step, min_fuel_route.lons_per_step], axis=1) | ||
| return np.stack([min_fuel_route.lats_per_step, min_fuel_route.lons_per_step, speed], axis=1) | ||
|
|
||
| # list of routes | ||
| if not alg.route_list: | ||
|
|
@@ -314,7 +330,7 @@ def patch(self, src, dst, departure_time: datetime = None): | |
| routes = [] | ||
|
|
||
| for rt in alg.route_list: | ||
| routes.append(np.stack([rt.lats_per_step, rt.lons_per_step], axis=1)) | ||
| routes.append(np.stack([rt.lats_per_step, rt.lons_per_step, speed], axis=1)) | ||
| return routes | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also update the type hints of the method arguments?
Instead of
src: tuple, dst: tuplewritesrc: tuple[float, float, float], dst: tuple[float, float, float]