From 593865934d5d62af5600b42d19a443f5ba415158 Mon Sep 17 00:00:00 2001 From: Takara Baumbach Date: Wed, 5 Oct 2022 14:24:07 +0200 Subject: [PATCH] optional parameter force_turn_costs --- CHANGELOG.md | 7 ++++++- .../services/isochrones/fast/ResultTest.java | 4 ++-- .../ors/v2/services/routing/ResultTest.java | 4 ++-- openrouteservice/pom.xml | 2 +- .../org/heigit/ors/routing/RoutingProfile.java | 2 +- .../RouteProfileConfiguration.java | 18 ++++++++++++++++++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b22dec31b3..b2d5acadba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,10 @@ RELEASING: ## [Unreleased] +## [6.7.1] - 2022-10-05 +### Added +- optional `encoder_options` parameter `force_turn_costs` ([#1220](https://github.com/GIScience/openrouteservice/pull/1220)) + ## [6.7.0] - 2022-01-04 ### Added - add core matrix algorithm @@ -539,7 +543,8 @@ are attached to roads. ([Issue #162](https://github.com/GIScience/openrouteservi - Fix bug in RPHAST when location lies on a oneway road. - Consider turn restrictions if optimized=false is passed. -[unreleased]: https://github.com/GIScience/openrouteservice/compare/v6.7.0...HEAD +[unreleased]: https://github.com/GIScience/openrouteservice/compare/v6.7.1...HEAD +[6.7.1]: https://github.com/GIScience/openrouteservice/compare/v6.7.0...v6.7.1 [6.7.0]: https://github.com/GIScience/openrouteservice/compare/v6.6.4...v6.7.0 [6.6.4]: https://github.com/GIScience/openrouteservice/compare/v6.6.3...v6.6.4 [6.6.3]: https://github.com/GIScience/openrouteservice/compare/v6.6.2...v6.6.3 diff --git a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/isochrones/fast/ResultTest.java b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/isochrones/fast/ResultTest.java index 0c1694e70f..6bb3b266ca 100644 --- a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/isochrones/fast/ResultTest.java +++ b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/isochrones/fast/ResultTest.java @@ -379,7 +379,7 @@ public void testSmoothingFactor() { .then() .body("any { it.key == 'type' }", is(true)) .body("any { it.key == 'features' }", is(true)) - .body("features[0].geometry.coordinates[0].size", is(75)) + .body("features[0].geometry.coordinates[0].size()", is(75)) .statusCode(200); body.put("smoothing", "100"); @@ -393,7 +393,7 @@ public void testSmoothingFactor() { .then() .body("any { it.key == 'type' }", is(true)) .body("any { it.key == 'features' }", is(true)) - .body("features[0].geometry.coordinates[0].size", is(89)) + .body("features[0].geometry.coordinates[0].size()", is(89)) .statusCode(200); } diff --git a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ResultTest.java b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ResultTest.java index b962210795..fc2081148d 100644 --- a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ResultTest.java +++ b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ResultTest.java @@ -2681,8 +2681,8 @@ public void testSkipSegments() { .body("routes[0].containsKey('warnings')", is(true)) .body("routes[0].warnings[0].containsKey('code')", is(true)) .body("routes[0].warnings[0].code", is(3)) - .body("routes[0].segments.size", is(4)) - .body("routes[0].way_points.size", is(5)) + .body("routes[0].segments.size()", is(4)) + .body("routes[0].way_points.size()", is(5)) .body("routes[0].bbox[0]", is(0.0f)) .body("routes[0].bbox[1]", is(0.0f)) .statusCode(200); diff --git a/openrouteservice/pom.xml b/openrouteservice/pom.xml index 1b15ba3f44..9740536c53 100644 --- a/openrouteservice/pom.xml +++ b/openrouteservice/pom.xml @@ -34,7 +34,7 @@ 4.0.0 org.heigit.ors openrouteservice - 6.7.0 + 6.7.1 war openrouteservice openrouteservice.org diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java index 5901f9dc0b..b1f2d20aa9 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -875,7 +875,7 @@ public GHResponse computeRoute(double lat0, double lon0, double lat1, double lon int weightingMethod = searchParams.getWeightingMethod(); RouteSearchContext searchCntx = createSearchContext(searchParams); - int flexibleMode = searchParams.getFlexibleMode() ? KEY_FLEX_PREPROCESSED : KEY_FLEX_STATIC; + int flexibleMode = searchParams.getFlexibleMode() || config.isEnforceTurnCosts() ? KEY_FLEX_PREPROCESSED : KEY_FLEX_STATIC; boolean optimized = searchParams.getOptimized(); GHRequest req; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/configuration/RouteProfileConfiguration.java b/openrouteservice/src/main/java/org/heigit/ors/routing/configuration/RouteProfileConfiguration.java index 1502aa754c..1006dd532b 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/configuration/RouteProfileConfiguration.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/configuration/RouteProfileConfiguration.java @@ -63,6 +63,8 @@ public class RouteProfileConfiguration { private int trafficExpirationMin = 15; + private boolean enforceTurnCosts = false; + public RouteProfileConfiguration() { extStorages = new HashMap<>(); graphBuilders = new HashMap<>(); @@ -83,6 +85,8 @@ public RouteProfileConfiguration(RouteProfileConfiguration rpc) { encoderFlagsSize = rpc.encoderFlagsSize; encoderOptions = rpc.encoderOptions; + enforceTurnCosts = hasEnforceTurnCosts(rpc.encoderOptions); + isochronePreparationOpts = rpc.isochronePreparationOpts; preparationOpts = rpc.preparationOpts; executionOpts = rpc.executionOpts; @@ -212,6 +216,15 @@ public Double getMaximumDistanceDynamicWeights() { return maximumDistanceDynamicWeights; } + private static boolean hasEnforceTurnCosts(String encoderOptions) { + for (String option : encoderOptions.split("\\|")) { + String[] keyValuePair = option.split("="); + if (keyValuePair.length > 0 && keyValuePair[0].equals("force_turn_costs")) { + return keyValuePair[1].equals("true"); + } + } + return false; + } public void setMaximumDistanceAvoidAreas(Double value) { @@ -261,6 +274,7 @@ public Integer getEncoderFlagsSize() public void setEncoderOptions(String value) { encoderOptions = value; + enforceTurnCosts = hasEnforceTurnCosts(value); } public String getEncoderOptions() @@ -403,6 +417,10 @@ public double getMaximumSpeedLowerBound(){ return maximumSpeedLowerBound; } + public boolean isEnforceTurnCosts() { + return enforceTurnCosts; + } + public void setTrafficExpirationMin(int trafficExpirationMin) { this.trafficExpirationMin = trafficExpirationMin; }