Skip to content

Commit

Permalink
fix: failing queries that combine departure/arrival parameters with a…
Browse files Browse the repository at this point in the history
…void areas (#1871)
  • Loading branch information
aoles authored Oct 28, 2024
2 parents 8e58bfb + feb401f commit ad35cb3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ RELEASING:

### 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 polygons ([#1871](https://github.com/GIScience/openrouteservice/pull/1871))

## [8.2.0] - 2024-10-09
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>

<!-- switch graphhopper versions to enable debugging -->
<graphhopper.version>v4.9.3</graphhopper.version>
<!--graphhopper.version>v4.9-SNAPSHOT</graphhopper.version-->
<graphhopper.version>v4.9.4</graphhopper.version>
<!--graphhopper.version>4.9-SNAPSHOT</graphhopper.version-->
<springdoc-openapi-starter.version>2.6.0</springdoc-openapi-starter.version>
<swagger-parser.version>2.1.22</swagger-parser.version>
<snakeyaml.version>2.2</snakeyaml.version>
Expand Down

0 comments on commit ad35cb3

Please sign in to comment.