From 8fb636a7fef2046fe7be85c60c7a204bc1e7b007 Mon Sep 17 00:00:00 2001 From: aoles Date: Wed, 23 Oct 2024 22:08:54 +0200 Subject: [PATCH 1/5] fix: logic to pass time to td routing algorithms --- .../org/heigit/ors/routing/RoutingProfile.java | 11 ++++++++--- .../org/heigit/ors/routing/RoutingRequest.java | 18 +++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfile.java b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfile.java index 9aaf53dbf3..3ef2018c98 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -643,14 +643,19 @@ public void setSpeedups(GHRequest req, boolean useCH, boolean useCore, boolean u } } - boolean requiresTimeDependentWeighting(RouteSearchParameters searchParams, RouteSearchContext searchCntx) { + boolean requiresTimeDependentAlgorithm(RouteSearchParameters searchParams, RouteSearchContext searchCntx) { if (!searchParams.isTimeDependent()) return false; FlagEncoder flagEncoder = searchCntx.getEncoder(); - return flagEncoder.hasEncodedValue(EncodingManager.getKey(flagEncoder, ConditionalEdges.ACCESS)) - || flagEncoder.hasEncodedValue(EncodingManager.getKey(flagEncoder, ConditionalEdges.SPEED)) + if (flagEncoder.hasEncodedValue(EncodingManager.getKey(flagEncoder, ConditionalEdges.ACCESS))) + return true; + + if (WeightingMethod.SHORTEST==searchParams.getWeightingMethod()) + return false; + + return flagEncoder.hasEncodedValue(EncodingManager.getKey(flagEncoder, ConditionalEdges.SPEED)) || mGraphHopper.isTrafficEnabled(); } diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingRequest.java b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingRequest.java index d2fb840131..11d02f8670 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingRequest.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingRequest.java @@ -390,10 +390,8 @@ else if (bearings[1] == null) if (TemporaryUtilShelter.supportWeightingMethod(profileType)) { ProfileTools.setWeightingMethod(req.getHints(), weightingMethod, profileType, TemporaryUtilShelter.hasTimeDependentSpeed(searchParams, searchCntx)); - if (routingProfile.requiresTimeDependentWeighting(searchParams, searchCntx)) { - req.setAlgorithm(Parameters.Algorithms.TD_ASTAR); + if (routingProfile.requiresTimeDependentAlgorithm(searchParams, searchCntx)) flexibleMode = ProfileTools.KEY_FLEX_PREPROCESSED; - } flexibleMode = TemporaryUtilShelter.getFlexibilityMode(flexibleMode, searchParams, profileType); } else throw new IllegalArgumentException("Unsupported weighting " + weightingMethod + " for profile + " + profileType); @@ -413,16 +411,22 @@ else if (bearings[1] == null) if (searchParams.isTimeDependent()) { String key; - LocalDateTime time; + LocalDateTime dateTime; if (searchParams.hasDeparture()) { key = RouteRequestParameterNames.PARAM_DEPARTURE; - time = searchParams.getDeparture(); + dateTime = searchParams.getDeparture(); } else { key = RouteRequestParameterNames.PARAM_ARRIVAL; - time = searchParams.getArrival(); + dateTime = searchParams.getArrival(); } - req.getHints().putObject(key, time.atZone(ZoneId.of("Europe/Berlin")).toInstant()); + Instant time = dateTime.atZone(ZoneId.of("Europe/Berlin")).toInstant(); + req.getHints().putObject(key, time); + + if (routingProfile.requiresTimeDependentAlgorithm(searchParams, searchCntx)) { + req.getHints().putObject("time", time.toEpochMilli()); + req.setAlgorithm(Parameters.Algorithms.TD_ASTAR); + } } if (routingProfile.getAstarEpsilon() != null) From c3822cc6278516d9bc0c79f0544eb1a3cc22a2a8 Mon Sep 17 00:00:00 2001 From: aoles Date: Wed, 23 Oct 2024 22:31:01 +0200 Subject: [PATCH 2/5] docs: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e22a32d78..3400f677c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ RELEASING: ## [unreleased] ### Fixed - do not enforce a time-dependent routing algorithm unless the weighting requires it ([#1865](https://github.com/GIScience/openrouteservice/pull/1865)) +- failing queries that combined departure/arrival parameters with avoid areas ([#1870](https://github.com/GIScience/openrouteservice/pull/1870)) ## [8.2.0] - 2024-10-09 ### Added From 712cf71df499bcf752db2135dc040de3d6cb45a3 Mon Sep 17 00:00:00 2001 From: aoles Date: Thu, 24 Oct 2024 23:19:17 +0200 Subject: [PATCH 3/5] test: compatibility of time parameters with avoid polygons --- .../ors/apitests/routing/ParamsTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ors-api/src/test/java/org/heigit/ors/apitests/routing/ParamsTest.java b/ors-api/src/test/java/org/heigit/ors/apitests/routing/ParamsTest.java index fbeea66d65..a5aa37601e 100644 --- a/ors-api/src/test/java/org/heigit/ors/apitests/routing/ParamsTest.java +++ b/ors-api/src/test/java/org/heigit/ors/apitests/routing/ParamsTest.java @@ -112,6 +112,7 @@ public ParamsTest() { addParameter("preference", "recommended"); addParameter("profile", "cycling-regular"); addParameter("carProfile", "driving-car"); + addParameter("hgvProfile", "driving-hgv"); addParameter("footProfile", "foot-walking"); } @@ -1725,6 +1726,42 @@ void expectDepartureAndArrivalToBeMutuallyExclusive() { .statusCode(400); } + @Test + void testCompatibilityOfAvoidAreasWithTimeDependentRouting() { + JSONObject body = new JSONObject(); + body.put("coordinates", getParameter("coordinatesShort")); + body.put("preference", getParameter("preference")); + body.put("departure", "2021-01-31T12:00"); + + JSONObject avoidGeom = new JSONObject("{\"type\":\"Polygon\",\"coordinates\":[[[8.680,49.421],[8.687,49.421],[8.687,49.418],[8.680,49.418],[8.680,49.421]]]}}"); + JSONObject options = new JSONObject(); + options.put("avoid_polygons", avoidGeom); + body.put("options", options); + + given() + .headers(jsonContent) + .pathParam("profile", getParameter("footProfile")) + .body(body.toString()) + .when() + .post(getEndPointPath() + "/{profile}") + .then() + .assertThat() + .body("any { it.key == 'routes' }", is(true)) + .statusCode(200); + + body.put("preference", "shortest"); + given() + .headers(jsonContent) + .pathParam("profile", getParameter("hgvProfile")) + .body(body.toString()) + .when() + .post(getEndPointPath() + "/{profile}") + .then() + .assertThat() + .body("any { it.key == 'routes' }", is(true)) + .statusCode(200); + } + @Test void expectNoErrorOnSingleRadiusForMultipleCoordinates() { JSONObject body = new JSONObject(); From 36a90f820ff5114e5a69269521aa580b8381bfef Mon Sep 17 00:00:00 2001 From: aoles Date: Thu, 24 Oct 2024 23:21:20 +0200 Subject: [PATCH 4/5] chore: update GH version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a0a6914b7e..e5831c83f1 100644 --- a/pom.xml +++ b/pom.xml @@ -48,8 +48,8 @@ yyyy-MM-dd'T'HH:mm:ss'Z' - v4.9.3 - + v4.9.4 + 2.6.0 2.1.22 2.2 From 801c9b9b9a28f0d81806cf2419f197264c1345b8 Mon Sep 17 00:00:00 2001 From: aoles Date: Thu, 24 Oct 2024 23:23:57 +0200 Subject: [PATCH 5/5] docs: correct PR number in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3400f677c2..05ffb2b441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ RELEASING: ## [unreleased] ### Fixed - do not enforce a time-dependent routing algorithm unless the weighting requires it ([#1865](https://github.com/GIScience/openrouteservice/pull/1865)) -- failing queries that combined departure/arrival parameters with avoid areas ([#1870](https://github.com/GIScience/openrouteservice/pull/1870)) +- failing queries that combined departure/arrival parameters with avoid polygons ([#1871](https://github.com/GIScience/openrouteservice/pull/1871)) ## [8.2.0] - 2024-10-09 ### Added