From 1b035b2f6785687a975352e21543362f1dd35fb1 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Tue, 24 Dec 2019 14:03:51 +0100 Subject: [PATCH 01/38] Integrating maximum_speed-weighting in development branch. --- .../ors/api/requests/common/APIEnums.java | 3 +- .../api/requests/routing/RouteRequest.java | 18 +++++++ .../requests/routing/RouteRequestHandler.java | 16 ++++++ .../ors/routing/RouteSearchParameters.java | 7 +++ .../heigit/ors/routing/RoutingProfile.java | 8 +++ .../heigit/ors/routing/RoutingRequest.java | 6 +++ .../heigit/ors/routing/WeightingMethod.java | 6 +++ .../core/MaximumSpeedCoreEdgeFilter.java | 51 +++++++++++++++++++ 8 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/common/APIEnums.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/common/APIEnums.java index 053b5e52d0..343641aa15 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/common/APIEnums.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/common/APIEnums.java @@ -209,7 +209,8 @@ public String toString() { public enum RoutePreference { FASTEST("fastest"), SHORTEST("shortest"), - RECOMMENDED("recommended"); + RECOMMENDED("recommended"), + MAXIMUM_SPEED("maximum_speed"); private final String value; diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java index a8a8d889bd..b8e06ea912 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java @@ -57,6 +57,8 @@ public class RouteRequest { public static final String PARAM_SIMPLIFY_GEOMETRY = "geometry_simplify"; public static final String PARAM_SKIP_SEGMENTS = "skip_segments"; public static final String PARAM_ALTERNATIVE_ROUTES = "alternative_routes"; + public static final String PARAM_USER_SPEED = "user_speed"; + @ApiModelProperty(name = PARAM_ID, value = "Arbitrary identification string of the request reflected in the meta information.", example = "routing_request") @@ -245,6 +247,11 @@ public class RouteRequest { @JsonIgnore private boolean hasAlternativeRoutes = false; + @ApiModelProperty(name = PARAM_USER_SPEED, value = "The maximum speed specified by user.", example = "90") + @JsonProperty(PARAM_USER_SPEED) + private double userSpeed; + @JsonIgnore + private boolean hasUserSpeed = false; @JsonCreator public RouteRequest(@JsonProperty(value = PARAM_COORDINATES, required = true) List> coordinates) { @@ -504,6 +511,15 @@ public void setAlternativeRoutes(RouteRequestAlternativeRoutes alternativeRoutes hasAlternativeRoutes = true; } + public void setUserSpeed(Double userSpeed) { + this.userSpeed = userSpeed; + hasUserSpeed = true; + } + + public double getUserSpeed() { + return userSpeed; + } + public boolean hasIncludeRoundaboutExitInfo() { return hasIncludeRoundaboutExitInfo; } @@ -575,4 +591,6 @@ public boolean hasSimplifyGeometry() { public boolean hasSkipSegments() { return hasSkipSegments;} public boolean hasAlternativeRoutes() { return hasAlternativeRoutes; } + + public boolean hasUserSpeed() { return hasUserSpeed; } } diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java index 49292183d8..d92d2212c6 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java @@ -175,6 +175,10 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo params.setAlternativeRoutesShareFactor(alternativeRoutes.getShareFactor()); } + if(request.hasUserSpeed()){ + routingRequest.setUserSpeed(convertUserSpeed(request.getUserSpeed())); + } + params.setConsiderTurnRestrictions(false); routingRequest.setSearchParameters(params); @@ -239,6 +243,10 @@ public RouteSearchParameters processRequestOptions(RouteRequestOptions options, if (roundTripOptions.hasSeed()) { params.setRoundTripSeed(roundTripOptions.getSeed()); } + + if(params.hasUserSpeed()){ + params.setUserSpeed(convertUserSpeed(request.getUserSpeed())); + } } return params; @@ -483,4 +491,12 @@ private int[] convertAvoidCountries(String[] avoidCountries) throws ParameterVal return avoidCountryIds; } + + private double convertUserSpeed(Double userSpeed) throws ParameterValueException{ + if(userSpeed < 80){ + throw new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequest.PARAM_USER_SPEED); + } + return userSpeed; + } + } \ No newline at end of file diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java index 7815675eeb..99a1cc2a9a 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java @@ -71,6 +71,8 @@ public class RouteSearchParameters { private int roundTripPoints = 2; private long roundTripSeed = -1; + private double userSpeed; + private String options; public int getProfileType() { @@ -489,6 +491,10 @@ public long getRoundTripSeed() { return roundTripSeed; } + public double getUserSpeed() {return userSpeed;} + + public void setUserSpeed(double userSpeed) { this.userSpeed = userSpeed;} + public boolean isProfileTypeDriving() { return RoutingProfileType.isDriving(this.getProfileType()); } @@ -507,6 +513,7 @@ public boolean requiresDynamicWeights() { || getWeightingMethod() == WeightingMethod.RECOMMENDED || isProfileTypeHeavyVehicle() && getVehicleType() > 0 || isProfileTypeDriving() && hasParameters(VehicleParameters.class) + || getWeightingMethod() == WeightingMethod.MAXIMUM_SPEED ; } 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 c2c7e3dba3..29cd9becaa 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -798,6 +798,14 @@ public GHResponse computeRoundTripRoute(double lat0, double lon0, WayPointBearin flexibleMode = true; } + if (supportWeightingMethod(profileType)) { + if (weightingMethod == WeightingMethod.MAXIMUM_SPEED) { + req.setWeighting("fastest"); + req.getHints().put("weighting_method", "maximum_speed"); + req.getHints().put("user_speed",searchParams.getUserSpeed()); + } + } + if (searchParams.requiresDynamicWeights() || flexibleMode) { if (mGraphHopper.isCHEnabled()) req.getHints().put(KEY_CH_DISABLE, true); diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java index a0156e719c..38d939cfa7 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java @@ -42,6 +42,7 @@ public class RoutingRequest extends ServiceRequest { private boolean continueStraight = false; private List skipSegments = new ArrayList<>(); private boolean includeCountryInfo = false; + private double userSpeed; public RoutingRequest() { @@ -207,4 +208,9 @@ public boolean getIncludeCountryInfo() { public void setIncludeCountryInfo(boolean includeCountryInfo) { this.includeCountryInfo = includeCountryInfo; } + + public void setUserSpeed(double userSpeed){this.userSpeed = userSpeed;} + + public double getUserSpeed(){return userSpeed;} + } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/WeightingMethod.java b/openrouteservice/src/main/java/org/heigit/ors/routing/WeightingMethod.java index a52081a377..1f5a877d96 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/WeightingMethod.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/WeightingMethod.java @@ -18,6 +18,7 @@ public class WeightingMethod { public static final int FASTEST = 1; public static final int SHORTEST = 2; public static final int RECOMMENDED = 3; + public static final int MAXIMUM_SPEED = 4; private WeightingMethod() {} @@ -29,6 +30,9 @@ public static int getFromString(String method) { } else if ("recommended".equalsIgnoreCase(method)) { return WeightingMethod.RECOMMENDED; } + else if ("maximum_speed".equalsIgnoreCase(method)){ + return WeightingMethod.MAXIMUM_SPEED; + } return WeightingMethod.UNKNOWN; } @@ -40,6 +44,8 @@ public static String getName(int profileType) { return "shortest"; case RECOMMENDED: return "recommended"; + case MAXIMUM_SPEED: + return "maximum_speed"; default: return ""; } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java new file mode 100644 index 0000000000..21e21fe932 --- /dev/null +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -0,0 +1,51 @@ +/* This file is part of Openrouteservice. + * + * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public License along with this library; + * if not, see . + */ +package heigit.ors.routing.graphhopper.extensions.edgefilters.core; + +import com.graphhopper.routing.util.EdgeFilter; +import com.graphhopper.storage.GraphStorage; +import com.graphhopper.util.EdgeIteratorState; +import com.graphhopper.routing.util.FlagEncoder; +import org.heigit.ors.config.AppConfig; +import org.heigit.ors.routing.graphhopper.extensions.storages.GraphStorageUtils; +import org.heigit.ors.routing.graphhopper.extensions.storages.HeavyVehicleAttributesGraphStorage; + +/** + * This class includes in the core all edges with speed more than the one set in the app.config file max_speed. + * + * @author Athanasios Kogios + */ + +public class MaximumSpeedCoreEdgeFilter implements EdgeFilter { + private HeavyVehicleAttributesGraphStorage storage; + private double maxSpeed = Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","max_speed")); //Minimum speed of the core. + public final FlagEncoder flagEncoder; + + public MaximumSpeedCoreEdgeFilter(FlagEncoder encoder, GraphStorage graphStorage) { + this.flagEncoder = encoder; + if (!flagEncoder.isRegistered()) + throw new IllegalStateException("Make sure you add the FlagEncoder " + flagEncoder + " to an EncodingManager before using it elsewhere"); + storage = GraphStorageUtils.getGraphExtension(graphStorage, HeavyVehicleAttributesGraphStorage.class); + } + + @Override + public boolean accept(EdgeIteratorState edge) { + if ( flagEncoder.getReverseSpeed(edge.getFlags()) > maxSpeed || flagEncoder.getSpeed(edge.getFlags()) > maxSpeed ) { //If the max speed of the road is greater than that of the limit include it in the core. + return false; + } else { + return true; + } + } +} + From c57f0b961de11457867324c43bc13051d765a791 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Tue, 24 Dec 2019 17:52:02 +0100 Subject: [PATCH 02/38] Continuing integration. --- .../extensions/ORSGraphHopper.java | 16 ++++ .../extensions/ORSWeightingFactory.java | 3 + .../extensions/core/PrepareCore.java | 13 ++- .../weighting/MaximumSpeedWeighting.java | 91 +++++++++++++++++++ 4 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index 84590722b7..8483516267 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -47,6 +47,7 @@ import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.AvoidFeaturesCoreEdgeFilter; import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.HeavyVehicleCoreEdgeFilter; import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.WheelchairCoreEdgeFilter; +import heigit.ors.routing.graphhopper.extensions.edgefilters.core.MaximumSpeedCoreEdgeFilter; import org.heigit.ors.routing.graphhopper.extensions.util.ORSParameters; import org.heigit.ors.util.CoordTools; import org.slf4j.Logger; @@ -322,6 +323,11 @@ else if (ALT_ROUTE.equalsIgnoreCase(algoStr)) throw new IllegalArgumentException( "The max_visited_nodes parameter has to be below or equal to:" + getMaxVisitedNodes()); + + if(hints.get("weighting_method", "").toLowerCase() =="maximum_speed") { + weighting = new MaximumSpeedWeighting(encoder, hints); + } + weighting = createTurnWeighting(queryGraph, weighting, tMode); AlgorithmOptions algoOpts = AlgorithmOptions.start().algorithm(algoStr).traversalMode(tMode) @@ -516,6 +522,16 @@ public void postProcessing() { coreEdgeFilter.add(new WheelchairCoreEdgeFilter(gs)); } + /* Maximum Speed Filter */ + if (routingProfileCategory !=0 & encodingManager.hasEncoder("heavyvehicle")) { + FlagEncoder flagEncoder=getEncodingManager().getEncoder("heavyvehicle"); // Set encoder only for heavy vehicles. + coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, gs)); + } + if (routingProfileCategory !=0 & encodingManager.hasEncoder("car-ors")) { + FlagEncoder flagEncoder=getEncodingManager().getEncoder("car-ors"); // Set encoder only for cars. + coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, gs)); + } + /* End filter sequence initialization */ //Create the core diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java index 0fc15f0807..3fefbeed38 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java @@ -62,6 +62,9 @@ else if ("fastest".equalsIgnoreCase(strWeighting)) else result = new FastestWeighting(encoder, hintsMap); } + else if ("maximum_speed".equalsIgnoreCase(strWeighting)){ + result = new MaximumSpeedWeighting(encoder, hintsMap); + } else if ("priority".equalsIgnoreCase(strWeighting)) { result = new PreferencePriorityWeighting(encoder, hintsMap); diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java index c61da6124f..a3a1da5077 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java @@ -506,9 +506,16 @@ public RoutingAlgorithm createAlgo(Graph graph, AlgorithmOptions opts) { String algoStr = ASTAR_BI; if (ASTAR_BI.equals(algoStr)) { - CoreALT tmpAlgo = new CoreALT(graph, prepareWeighting, traversalMode); - tmpAlgo.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); - algo = tmpAlgo; + if(opts.getHints().get("weighting_method","fastest") == "maximum_speed") { + CoreALT tmpAlgo = new CoreALT(graph, opts.getWeighting(), traversalMode); + tmpAlgo.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); + algo = tmpAlgo; + } + else{ + CoreALT tmpAlgo = new CoreALT(graph, prepareWeighting, traversalMode); + tmpAlgo.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); + algo = tmpAlgo; + } } else if (DIJKSTRA_BI.equals(algoStr)) { algo = new CoreDijkstra(graph, prepareWeighting, traversalMode); } else { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java new file mode 100644 index 0000000000..6765815e92 --- /dev/null +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -0,0 +1,91 @@ +package heigit.ors.routing.graphhopper.extensions.weighting; + +import com.graphhopper.routing.util.FlagEncoder; +import com.graphhopper.routing.util.HintsMap; +import com.graphhopper.routing.weighting.FastestWeighting; +import com.graphhopper.util.CHEdgeIteratorState; +import com.graphhopper.util.EdgeIteratorState; +import com.graphhopper.util.Parameters.Routing; + +/** + * This class creates the weighting for the routing according to the maximum speed set by user. + * + * @author Athanasios Kogios + */ + +public class MaximumSpeedWeighting extends FastestWeighting { + protected final static double SPEED_CONV = 3.6; //From km/h to m/s. + private final double headingPenalty; + private final double userMaxSpeed; + private final String weighting; + + public MaximumSpeedWeighting(FlagEncoder encoder, HintsMap map) { + super(encoder, map); + userMaxSpeed = map.getDouble("user_speed",80); + headingPenalty = map.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); + weighting = map.get("weighting","fastest"); + } + + private double speedToTime_km_h(double speed, EdgeIteratorState edge){ + //Conversion of the speeds (km/h) to times taken from the edges into time adding the penalties + double time = edge.getDistance() / speed * SPEED_CONV; + + // add direction penalties at start/stop/via points + boolean unfavoredEdge = edge.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, false); + if (unfavoredEdge) + time += headingPenalty; + + return time; + } + + private double speedToTime_m_s(double speed, EdgeIteratorState edge){ + //Conversion of the speeds (m/s) to times taken from the edges into time adding the penalties + double time = edge.getDistance() / speed; + + // add direction penalties at start/stop/via points + boolean unfavoredEdge = edge.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, false); + if (unfavoredEdge) + time += headingPenalty; + + return time; + } + + @Override + public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId) { + CHEdgeIteratorState tmp = (CHEdgeIteratorState) edge; + if (tmp.isShortcut()) { + //If a shortcut is in both directions the weight is identical => no need for 'reverse' + //tmp.getWeight() is in time (seconds) so we first change it to speed + double time = tmp.getWeight(); + double distance = edge.getDistance(); + double speed = edge.getDistance()/ tmp.getWeight(); + //Check for zero to avoid infinities + if (speed == 0) { + return Double.POSITIVE_INFINITY; + } + //Find the minimum of the two values. if (speed > userMaxSpeed) -> userMaxSpeed, else -> speed + speed = java.lang.Math.min(userMaxSpeed, speed); + //Convert speed to time + return speedToTime_m_s(speed, edge); + } + else{ + //If it is not a shortcut we need to test both directions + double speed = reverse ? flagEncoder.getReverseSpeed(edge.getFlags()) : flagEncoder.getSpeed(edge.getFlags()); + if (speed == 0) { + return Double.POSITIVE_INFINITY; + } + if(speed > userMaxSpeed) { + speed = userMaxSpeed; + return speedToTime_km_h(speed, edge); + }else{ + return super.calcWeight(edge, reverse, prevOrNextEdgeId); + } + } + } + + @Override + public String getName() { + return "maximum_speed"; + } + +} From 84d6857e63662e0f73b87f139a8cd1a32ac67916 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Tue, 24 Dec 2019 20:41:07 +0100 Subject: [PATCH 03/38] Added TODO list in files. --- .../ors/routing/graphhopper/extensions/ORSGraphHopper.java | 1 + .../edgefilters/core/MaximumSpeedCoreEdgeFilter.java | 3 ++- .../extensions/weighting/MaximumSpeedWeighting.java | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index 8483516267..a40a52c30b 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -48,6 +48,7 @@ import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.HeavyVehicleCoreEdgeFilter; import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.WheelchairCoreEdgeFilter; import heigit.ors.routing.graphhopper.extensions.edgefilters.core.MaximumSpeedCoreEdgeFilter; +import heigit.ors.routing.graphhopper.extensions.weighting.MaximumSpeedWeighting; import org.heigit.ors.routing.graphhopper.extensions.util.ORSParameters; import org.heigit.ors.util.CoordTools; import org.slf4j.Logger; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index 21e21fe932..c078343ae0 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -39,9 +39,10 @@ public MaximumSpeedCoreEdgeFilter(FlagEncoder encoder, GraphStorage graphStorage storage = GraphStorageUtils.getGraphExtension(graphStorage, HeavyVehicleAttributesGraphStorage.class); } + //TODO Find correct way to parse maxspeed of the edge. @Override public boolean accept(EdgeIteratorState edge) { - if ( flagEncoder.getReverseSpeed(edge.getFlags()) > maxSpeed || flagEncoder.getSpeed(edge.getFlags()) > maxSpeed ) { //If the max speed of the road is greater than that of the limit include it in the core. + if ( edge.get(flagEncoder.getMaxSpeed()) > maxSpeed || flagEncoder.getSpeed(edge.getFlags()) > maxSpeed ) { //If the max speed of the road is greater than that of the limit include it in the core. return false; } else { return true; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 6765815e92..5114b94a01 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -26,6 +26,8 @@ public MaximumSpeedWeighting(FlagEncoder encoder, HintsMap map) { weighting = map.get("weighting","fastest"); } + //TODO Find correct way to parse data. + private double speedToTime_km_h(double speed, EdgeIteratorState edge){ //Conversion of the speeds (km/h) to times taken from the edges into time adding the penalties double time = edge.getDistance() / speed * SPEED_CONV; From 97586f8795a870633b7028130306a0f27197b626 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Tue, 7 Jan 2020 14:11:31 +0100 Subject: [PATCH 04/38] Working implementation of the MaximumSpeddCoreEdgeFilter and the MaximumSpeedWeighting in the development branch. --- .../ors/api/requests/routing/RouteRequestHandler.java | 4 ---- .../routing/graphhopper/extensions/ORSWeightingFactory.java | 1 + .../edgefilters/core/MaximumSpeedCoreEdgeFilter.java | 4 ++-- .../extensions/weighting/MaximumSpeedWeighting.java | 6 +++--- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java index d92d2212c6..8df64db637 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java @@ -243,10 +243,6 @@ public RouteSearchParameters processRequestOptions(RouteRequestOptions options, if (roundTripOptions.hasSeed()) { params.setRoundTripSeed(roundTripOptions.getSeed()); } - - if(params.hasUserSpeed()){ - params.setUserSpeed(convertUserSpeed(request.getUserSpeed())); - } } return params; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java index 3fefbeed38..0a72e9b92d 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java @@ -24,6 +24,7 @@ import com.graphhopper.storage.index.LocationIndex; import com.graphhopper.util.Helper; import com.graphhopper.util.PMap; +import heigit.ors.routing.graphhopper.extensions.weighting.MaximumSpeedWeighting; import org.heigit.ors.routing.ProfileWeighting; import org.heigit.ors.routing.graphhopper.extensions.flagencoders.FlagEncoderNames; import org.heigit.ors.routing.graphhopper.extensions.weighting.*; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index c078343ae0..5f553a37c1 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -39,10 +39,10 @@ public MaximumSpeedCoreEdgeFilter(FlagEncoder encoder, GraphStorage graphStorage storage = GraphStorageUtils.getGraphExtension(graphStorage, HeavyVehicleAttributesGraphStorage.class); } - //TODO Find correct way to parse maxspeed of the edge. + //TODO FInd difference between methods getMaxSpeed and getAverageSpeedEnc @Override public boolean accept(EdgeIteratorState edge) { - if ( edge.get(flagEncoder.getMaxSpeed()) > maxSpeed || flagEncoder.getSpeed(edge.getFlags()) > maxSpeed ) { //If the max speed of the road is greater than that of the limit include it in the core. + if ( (edge.get(flagEncoder.getAverageSpeedEnc()) > maxSpeed) || (edge.getReverse(flagEncoder.getAverageSpeedEnc())) > maxSpeed ) { //If the max speed of the road is greater than that of the limit include it in the core. return false; } else { return true; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 5114b94a01..b40ced73c1 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -33,7 +33,7 @@ private double speedToTime_km_h(double speed, EdgeIteratorState edge){ double time = edge.getDistance() / speed * SPEED_CONV; // add direction penalties at start/stop/via points - boolean unfavoredEdge = edge.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, false); + boolean unfavoredEdge = edge.get(EdgeIteratorState.UNFAVORED_EDGE); if (unfavoredEdge) time += headingPenalty; @@ -45,7 +45,7 @@ private double speedToTime_m_s(double speed, EdgeIteratorState edge){ double time = edge.getDistance() / speed; // add direction penalties at start/stop/via points - boolean unfavoredEdge = edge.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, false); + boolean unfavoredEdge = edge.get(EdgeIteratorState.UNFAVORED_EDGE); if (unfavoredEdge) time += headingPenalty; @@ -72,7 +72,7 @@ public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNext } else{ //If it is not a shortcut we need to test both directions - double speed = reverse ? flagEncoder.getReverseSpeed(edge.getFlags()) : flagEncoder.getSpeed(edge.getFlags()); + double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); if (speed == 0) { return Double.POSITIVE_INFINITY; } From 0ed73c58a93aa4f00fbb812757b91ccd8b1d061e Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Tue, 7 Jan 2020 14:23:30 +0100 Subject: [PATCH 05/38] Changes in RoutingProfile. --- openrouteservice/pom.xml | 5 +++-- .../src/main/java/org/heigit/ors/routing/RoutingProfile.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openrouteservice/pom.xml b/openrouteservice/pom.xml index e54663ec1f..ac7608eb5f 100644 --- a/openrouteservice/pom.xml +++ b/openrouteservice/pom.xml @@ -272,6 +272,7 @@ 3.0.3 + - com.graphhopper graphhopper-core @@ -307,7 +309,6 @@ graphhopper-reader-osm 0.12-SNAPSHOT - --> com.typesafe 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 29cd9becaa..f35d6eb1a6 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -800,8 +800,8 @@ public GHResponse computeRoundTripRoute(double lat0, double lon0, WayPointBearin if (supportWeightingMethod(profileType)) { if (weightingMethod == WeightingMethod.MAXIMUM_SPEED) { - req.setWeighting("fastest"); - req.getHints().put("weighting_method", "maximum_speed"); + req.setWeighting(VAL_FASTEST); + req.getHints().put(KEY_WEIGHTING_METHOD, "maximum_speed"); req.getHints().put("user_speed",searchParams.getUserSpeed()); } } From 9a9460ff15f3fb6966e92cada71977553d16d9de Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Tue, 7 Jan 2020 15:25:12 +0100 Subject: [PATCH 06/38] Add max_speed in the app.config file under routing.profiles.default_params. Everything seems to work now. --- .../src/main/resources/app.config | 346 ++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100644 openrouteservice/src/main/resources/app.config diff --git a/openrouteservice/src/main/resources/app.config b/openrouteservice/src/main/resources/app.config new file mode 100644 index 0000000000..bfb17bffc1 --- /dev/null +++ b/openrouteservice/src/main/resources/app.config @@ -0,0 +1,346 @@ +{ + ors { + info: { + base_url: "https://openrouteservice.org/", + support_mail: "support@openrouteservice.org", + author_tag: "openrouteservice", + content_licence: "LGPL 3.0" + }, + services: { + matrix: { + enabled: true, + maximum_routes: 200, + maximum_visited_nodes: 100000, + allow_resolve_locations: true, + attribution: "openrouteservice.org, OpenStreetMap contributors" + } + isochrones: { + enabled: true, + # possible values for maximum_range_distance and maximum_range_time are an integer or a list of values specifically defined for each profile + maximum_range_distance: + [ + {profiles: "any", value: 50000} + {profiles: "driving-car, driving-hgv", value: 100000} + ], + maximum_range_time: + [ + {profiles: "any", value: 18000} + {profiles: "driving-car, driving-hgv", value: 3600} + ], + maximum_intervals: 10, + maximum_locations: 2, + allow_compute_area: true + } + routing: { + enabled: true, + mode: "normal", + sources: ["/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/heidelberg.osm.gz"], + init_threads: 1, + attribution: "openrouteservice.org, OpenStreetMap contributors, tmc - BASt", + distance_approximation: true, + routing_name: "ORSRouting", + profiles: { + active: ["vehicles-car"], + default_params: { + encoder_flags_size: 4, + graphs_root_path: "graphs", + elevation_provider: multi, + elevation_cache_clear: false, + elevation_cache_path: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/elevation", + instructions: true, + maximum_distance: 100000, + maximum_segment_distance_with_dynamic_weights: 50000, + maximum_waypoints: 50, + maximum_snapping_radius: 350, + max_speed: 80 + preparation: + { + min_network_size: 200, + min_one_way_network_size: 200, + + methods: + { + lm: + { + enabled: true, + threads: 1, + weightings: "fastest,shortest", + landmarks: 16 + } + } + } + execution: + { + methods: + { + lm: + { + disabling_allowed: true, + active_landmarks: 8 + } + } + } + }, + + profile-vehicles-car: { + profiles: "driving-car", + parameters: { + encoder_options: "turn_costs=true|block_fords=false|maximum_grade_level=1|use_acceleration=true", + maximum_distance: 100000, + elevation: true, + preparation: + { + min_network_size: 200, + min_one_way_network_size: 200, + + methods: + { + ch: + { + enabled: true, + threads: 1, + weightings: "fastest" + }, + lm: + { + enabled: true, + threads: 1, + weightings: "fastest", + landmarks: 16 + }, + core: + { + enabled: true, + threads: 1, + weightings: "fastest,shortest", + landmarks: 32 + } + } + } + execution: + { + methods: + { + ch: + { + disabling_allowed: true + }, + lm: + { + disabling_allowed: true, + active_landmarks: 8 + }, + core: + { + disabling_allowed: true, + active_landmarks: 6 + } + } + } + ext_storages: { + WayCategory: {}, + HeavyVehicle: {restrictions: true}, + WaySurfaceType: {}, + Tollways: {}, + Borders: { + boundaries: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/borders.geojson", + ids: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/ids.csv", + openborders: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/openborders.csv" + }, + RoadAccessRestrictions: { + use_for_warnings: true + } + } + traffic: false + } + } + profile-vehicles-hgv: { + profiles: "driving-hgv", + parameters: { + encoder_options: "turn_costs=true|block_fords=false|use_acceleration=true", + maximum_distance: 100000, + elevation: true, + preparation: + { + min_network_size: 200, + min_one_way_network_size: 200, + + methods: + { + ch: + { + enabled: true, + threads: 1, + weightings: "fastest" + }, + lm: + { + enabled: true, + threads: 1, + weightings: "fastest", + landmarks: 16 + }, + core: + { + enabled: true, + threads: 1, + weightings: "fastest,shortest", + landmarks: 32 + } + } + } + execution: + { + methods: + { + ch: + { + disabling_allowed: true + }, + lm: + { + disabling_allowed: true, + active_landmarks: 8 + }, + core: + { + disabling_allowed: true, + active_landmarks: 6 + } + } + } + ext_storages: { + WayCategory: {}, + HeavyVehicle: {restrictions: true}, + WaySurfaceType: {}, + Tollways: {}, + Borders: { + boundaries: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/borders.geojson", + ids: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/ids.csv", + openborders: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/openborders.csv" + } + } + traffic: false + } + } + + profile-bike: { + profiles: "cycling-regular", + parameters: { + encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", + elevation: true, + ext_storages: { + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + profile-bike-mtb: { + profiles: "cycling-mountain", + parameters: { + encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", + elevation: true, + maximum_snapping_radius: 10, + ext_storages: { + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + profile-bike-road: { + profiles: "cycling-road", + parameters: { + encoder_options: "consider_elevation=false|turn_costs=false|block_fords=false", + elevation: true, + ext_storages: { + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + profile-bike-e: { + profiles: "cycling-electric", + parameters: { + encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", + elevation: true, + ext_storages: { + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + + profile-pedestrian-walk: { + profiles: "foot-walking", + parameters: { + encoder_options: "block_fords=false", + elevation: true, + ext_storages: { + GreenIndex: { + filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/green_streets_hd.csv" + }, + NoiseIndex: { + filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/noise_data_hd.csv" + }, + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + }, + profile-pedestrian-hike: { + profiles: "foot-hiking", + parameters: { + encoder_options: "block_fords=false", + elevation: true, + ext_storages: { + GreenIndex: { + filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/green_streets_hd.csv" + }, + NoiseIndex: { + filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/noise_data_hd.csv" + }, + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + + profile-wheelchair: { + profiles: "wheelchair", + parameters: { + encoder_options: "block_fords=true", + elevation: true, + maximum_snapping_radius: 50, + ext_storages: { + Wheelchair: { + KerbsOnCrossings: "true" + }, + WaySurfaceType: {}, + WayCategory: {}, + OsmId: {} + } + } + } + } + } + } + logging: { + enabled: true, + level_file: "DEBUG_LOGGING.json", + location: "./logs", + stdout: true + } + } +} From 7750fde43553c74a3759a14b7a948bf123642ab7 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Mon, 27 Jan 2020 15:06:13 +0100 Subject: [PATCH 07/38] Changes in package names and comment additions. --- .../core/MaximumSpeedCoreEdgeFilter.java | 2 +- .../weighting/MaximumSpeedWeighting.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index 5f553a37c1..647446afa8 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -11,7 +11,7 @@ * You should have received a copy of the GNU Lesser General Public License along with this library; * if not, see . */ -package heigit.ors.routing.graphhopper.extensions.edgefilters.core; +package org.heigit.ors.routing.graphhopper.extensions.edgefilters.core; import com.graphhopper.routing.util.EdgeFilter; import com.graphhopper.storage.GraphStorage; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index b40ced73c1..d3ba362bfc 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -1,4 +1,17 @@ -package heigit.ors.routing.graphhopper.extensions.weighting; +/* This file is part of Openrouteservice. + * + * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public License along with this library; + * if not, see . + */ +package org.heigit.ors.routing.graphhopper.extensions.weighting; import com.graphhopper.routing.util.FlagEncoder; import com.graphhopper.routing.util.HintsMap; From 8d5b35653f13fa56c4d1bbd7dc67272329000638 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Mon, 27 Jan 2020 15:10:10 +0100 Subject: [PATCH 08/38] Added correct paths for MaximumSpeedCoreEdgeFilter and MaximumSpeedWeighting in ORSGraphhopper and ORSWeightingFactory. --- .../ors/routing/graphhopper/extensions/ORSGraphHopper.java | 4 ++-- .../routing/graphhopper/extensions/ORSWeightingFactory.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index a40a52c30b..fae1e7f729 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -47,8 +47,8 @@ import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.AvoidFeaturesCoreEdgeFilter; import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.HeavyVehicleCoreEdgeFilter; import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.WheelchairCoreEdgeFilter; -import heigit.ors.routing.graphhopper.extensions.edgefilters.core.MaximumSpeedCoreEdgeFilter; -import heigit.ors.routing.graphhopper.extensions.weighting.MaximumSpeedWeighting; +import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.MaximumSpeedCoreEdgeFilter; +import org.heigit.ors.routing.graphhopper.extensions.weighting.MaximumSpeedWeighting; import org.heigit.ors.routing.graphhopper.extensions.util.ORSParameters; import org.heigit.ors.util.CoordTools; import org.slf4j.Logger; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java index 0a72e9b92d..c03b811eee 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java @@ -24,7 +24,7 @@ import com.graphhopper.storage.index.LocationIndex; import com.graphhopper.util.Helper; import com.graphhopper.util.PMap; -import heigit.ors.routing.graphhopper.extensions.weighting.MaximumSpeedWeighting; +import org.heigit.ors.routing.graphhopper.extensions.weighting.MaximumSpeedWeighting; import org.heigit.ors.routing.ProfileWeighting; import org.heigit.ors.routing.graphhopper.extensions.flagencoders.FlagEncoderNames; import org.heigit.ors.routing.graphhopper.extensions.weighting.*; From e8661fc862fc04841d670355ee4f66a025f58a26 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 12 Feb 2020 21:15:29 +0100 Subject: [PATCH 09/38] Changes in .gitignore --- openrouteservice/.gitignore | 41 ++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/openrouteservice/.gitignore b/openrouteservice/.gitignore index 9c6d0ab7e3..cab81d97f6 100644 --- a/openrouteservice/.gitignore +++ b/openrouteservice/.gitignore @@ -1,13 +1,30 @@ -target/ -*~ -TODO.txt -.settings/ -.classpath + +.metadata/ + +.recommenders/ +.recommenders/caches/identified-project-coordinates.json +openrouteservice/Program FilesApache Software FoundationTomcat 7.0webappsopenrouteservice-0.0.1-SNAPSHOTWEB-INFlogsCounter_RS.csv +.recommenders/caches/manual-mappings.json +.recommenders/index/http___download_eclipse_org_recommenders_models_neon_/segments.gen +.idea/ +*.iml +.DS_Store +nohup.out +.python-version + .project -#/WebContent/WEB-INF/app.config -*.iws -*.ipr -cgiar-cache -srtm_38_03.zip -logs/ -.attach_* \ No newline at end of file + +# Ignore all app.config files except for the .sample one +openrouteservice/WebContent/WEB-INF/app.config* +!openrouteservice/WebContent/WEB-INF/app.config.sample +openrouteservice/src/main/resources/app.config* +!openrouteservice/src/main/resources/app.config.sample + +app.config.local +cgiar_provider/ +graphs/ +target/ +.python-version +nohup.out +build/ +cgiar_cache/ \ No newline at end of file From 089062242c8d09289ca55eac99e95b81f94f5c35 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Thu, 2 Apr 2020 10:33:03 +0200 Subject: [PATCH 10/38] Commit for merge. --- .../ors/api/requests/routing/RouteRequestHandler.java | 6 +++++- .../java/org/heigit/ors/routing/RoutingProfile.java | 10 ++++++++++ .../edgefilters/core/MaximumSpeedCoreEdgeFilter.java | 1 - 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java index 8df64db637..1105a4c6f9 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java @@ -123,6 +123,10 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo if(request.hasId()) routingRequest.setId(request.getId()); + if(request.hasUserSpeed()){ + routingRequest.setUserSpeed(convertUserSpeed(request.getUserSpeed())); + } + int profileType = -1; int coordinatesLength = request.getCoordinates().size(); @@ -176,7 +180,7 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo } if(request.hasUserSpeed()){ - routingRequest.setUserSpeed(convertUserSpeed(request.getUserSpeed())); + params.setUserSpeed(convertUserSpeed(request.getUserSpeed())); } params.setConsiderTurnRestrictions(false); 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 f35d6eb1a6..61df63609a 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -80,6 +80,7 @@ public class RoutingProfile { private static final String KEY_CUSTOM_WEIGHTINGS = "custom_weightings"; private static final String VAL_SHORTEST = "shortest"; private static final String VAL_FASTEST = "fastest"; + private static final String VAL_MAXIMUM_SPEED = "maximum_speed"; private static final String KEY_WEIGHTING_METHOD = "weighting_method"; private static final String KEY_CH_DISABLE = "ch.disable"; private static final String KEY_LM_DISABLE = "lm.disable"; @@ -920,10 +921,19 @@ else if (bearings[1] == null) flexibleMode = true; } + if (supportWeightingMethod(profileType)) { + if (weightingMethod == WeightingMethod.MAXIMUM_SPEED) { + req.setWeighting("fastest"); + req.getHints().put("weighting_method", "maximum_speed"); + req.getHints().put("user_speed",searchParams.getUserSpeed()); + } + } + if(profileType == RoutingProfileType.WHEELCHAIR) { flexibleMode = true; } + if (searchParams.requiresDynamicWeights() || flexibleMode) { if (mGraphHopper.isCHEnabled()) req.getHints().put(KEY_CH_DISABLE, true); diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index 647446afa8..c855c49e60 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -39,7 +39,6 @@ public MaximumSpeedCoreEdgeFilter(FlagEncoder encoder, GraphStorage graphStorage storage = GraphStorageUtils.getGraphExtension(graphStorage, HeavyVehicleAttributesGraphStorage.class); } - //TODO FInd difference between methods getMaxSpeed and getAverageSpeedEnc @Override public boolean accept(EdgeIteratorState edge) { if ( (edge.get(flagEncoder.getAverageSpeedEnc()) > maxSpeed) || (edge.getReverse(flagEncoder.getAverageSpeedEnc())) > maxSpeed ) { //If the max speed of the road is greater than that of the limit include it in the core. From 2a242e3b38e19b8d03fe6b03e1e0c889876526f3 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Thu, 2 Apr 2020 12:47:16 +0200 Subject: [PATCH 11/38] Commit for testing purposes. --- .../main/java/org/heigit/ors/routing/RoutingProfile.java | 7 ++++--- .../main/java/org/heigit/ors/routing/RoutingRequest.java | 2 +- .../ors/routing/graphhopper/extensions/ORSGraphHopper.java | 6 ------ .../extensions/flagencoders/VehicleFlagEncoder.java | 2 ++ 4 files changed, 7 insertions(+), 10 deletions(-) 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 6090cd2474..4381025ec7 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -808,8 +808,9 @@ public GHResponse computeRoundTripRoute(double lat0, double lon0, WayPointBearin if (supportWeightingMethod(profileType)) { if (weightingMethod == WeightingMethod.MAXIMUM_SPEED) { req.setWeighting(VAL_FASTEST); - req.getHints().put(KEY_WEIGHTING_METHOD, "maximum_speed"); + req.getHints().put(KEY_WEIGHTING_METHOD, VAL_MAXIMUM_SPEED); req.getHints().put("user_speed",searchParams.getUserSpeed()); + flexibleMode = true; } } @@ -937,8 +938,8 @@ else if (bearings[1] == null) if (supportWeightingMethod(profileType)) { if (weightingMethod == WeightingMethod.MAXIMUM_SPEED) { - req.setWeighting("fastest"); - req.getHints().put("weighting_method", "maximum_speed"); + req.setWeighting(VAL_FASTEST); + req.getHints().put(KEY_WEIGHTING_METHOD, "maximum_speed"); req.getHints().put("user_speed",searchParams.getUserSpeed()); } } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java index 1532ed5013..642cf352eb 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java @@ -224,5 +224,5 @@ public void setResponseFormat(String responseFormat) { public String getResponseFormat() { return this.responseFormat; - }\ + } } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index 77aa16260d..ec12ecebf8 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -318,12 +318,6 @@ else if (ALT_ROUTE.equalsIgnoreCase(algoStr)) throw new IllegalArgumentException( "The max_visited_nodes parameter has to be below or equal to:" + getMaxVisitedNodes()); - if(hints.get("weighting_method", "").toLowerCase() =="maximum_speed") { - weighting = new MaximumSpeedWeighting(encoder, hints); - } - - weighting = createTurnWeighting(queryGraph, weighting, tMode); - int uTurnCosts = hints.getInt(Parameters.Routing.U_TURN_COSTS, INFINITE_U_TURN_COSTS); weighting = createTurnWeighting(queryGraph, weighting, tMode, uTurnCosts); if (weighting instanceof TurnWeighting) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java index b355333b23..bed520cafb 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java @@ -234,6 +234,8 @@ public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, EncodingManager.A } } + if (speed > 80) System.out.println(way.getId() + " " + speed); + setSpeed(false, edgeFlags, speed); setSpeed(true, edgeFlags, speed); From d97e2614679b5ce17a434d94a1795d4c0390e7a0 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Tue, 7 Apr 2020 17:40:19 +0200 Subject: [PATCH 12/38] Changes in MaximumSpeedWeighting. --- .../ors/api/requests/common/APIEnums.java | 3 +- .../ors/routing/RouteSearchParameters.java | 12 +- .../heigit/ors/routing/RoutingProfile.java | 24 +--- .../heigit/ors/routing/WeightingMethod.java | 6 - .../extensions/ORSGraphHopper.java | 6 + .../extensions/ORSWeightingFactory.java | 3 - .../extensions/core/PrepareCore.java | 13 +- .../weighting/MaximumSpeedWeighting.java | 117 +++++++++++------- 8 files changed, 94 insertions(+), 90 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/common/APIEnums.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/common/APIEnums.java index 627441512f..609e5804b5 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/common/APIEnums.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/common/APIEnums.java @@ -209,8 +209,7 @@ public String toString() { public enum RoutePreference { FASTEST("fastest"), SHORTEST("shortest"), - RECOMMENDED("recommended"), - MAXIMUM_SPEED("maximum_speed"); + RECOMMENDED("recommended"); private final String value; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java index 1dc8daceac..3f0107a7b5 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java @@ -82,6 +82,7 @@ public class RouteSearchParameters { private long roundTripSeed = -1; private double userSpeed; + private boolean hasUserSpeed = false; private String options; @@ -531,7 +532,12 @@ public long getRoundTripSeed() { public double getUserSpeed() {return userSpeed;} - public void setUserSpeed(double userSpeed) { this.userSpeed = userSpeed;} + public void setUserSpeed(double userSpeed) { + this.userSpeed = userSpeed; + hasUserSpeed = true; + } + + public boolean hasUserSpeed() {return hasUserSpeed;} public boolean isProfileTypeDriving() { return RoutingProfileType.isDriving(this.getProfileType()); @@ -550,9 +556,7 @@ public boolean requiresDynamicWeights() { || getWeightingMethod() == WeightingMethod.SHORTEST || getWeightingMethod() == WeightingMethod.RECOMMENDED || isProfileTypeHeavyVehicle() && getVehicleType() > 0 - || isProfileTypeDriving() && hasParameters(VehicleParameters.class) - || getWeightingMethod() == WeightingMethod.MAXIMUM_SPEED - ; + || isProfileTypeDriving() && hasParameters(VehicleParameters.class); } /** 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 4381025ec7..1afc12112e 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -83,7 +83,6 @@ public class RoutingProfile { private static final String KEY_CUSTOM_WEIGHTINGS = "custom_weightings"; private static final String VAL_SHORTEST = "shortest"; private static final String VAL_FASTEST = "fastest"; - private static final String VAL_MAXIMUM_SPEED = "maximum_speed"; private static final String KEY_WEIGHTING_METHOD = "weighting_method"; private static final String KEY_CH_DISABLE = "ch.disable"; private static final String KEY_LM_DISABLE = "lm.disable"; @@ -805,15 +804,6 @@ public GHResponse computeRoundTripRoute(double lat0, double lon0, WayPointBearin flexibleMode = true; } - if (supportWeightingMethod(profileType)) { - if (weightingMethod == WeightingMethod.MAXIMUM_SPEED) { - req.setWeighting(VAL_FASTEST); - req.getHints().put(KEY_WEIGHTING_METHOD, VAL_MAXIMUM_SPEED); - req.getHints().put("user_speed",searchParams.getUserSpeed()); - flexibleMode = true; - } - } - if (searchParams.requiresDynamicWeights() || flexibleMode) { if (mGraphHopper.isCHEnabled()) req.getHints().put(KEY_CH_DISABLE, true); @@ -936,18 +926,16 @@ else if (bearings[1] == null) flexibleMode = true; } - if (supportWeightingMethod(profileType)) { - if (weightingMethod == WeightingMethod.MAXIMUM_SPEED) { - req.setWeighting(VAL_FASTEST); - req.getHints().put(KEY_WEIGHTING_METHOD, "maximum_speed"); - req.getHints().put("user_speed",searchParams.getUserSpeed()); - } - } - if(profileType == RoutingProfileType.WHEELCHAIR) { flexibleMode = true; } + if (supportWeightingMethod(profileType)) { + if (searchParams.hasUserSpeed()) { + req.getHints().put("user_speed",searchParams.getUserSpeed()); + flexibleMode = true; + } + } if (searchParams.requiresDynamicWeights() || flexibleMode) { if (mGraphHopper.isCHEnabled()) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/WeightingMethod.java b/openrouteservice/src/main/java/org/heigit/ors/routing/WeightingMethod.java index 1f5a877d96..a52081a377 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/WeightingMethod.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/WeightingMethod.java @@ -18,7 +18,6 @@ public class WeightingMethod { public static final int FASTEST = 1; public static final int SHORTEST = 2; public static final int RECOMMENDED = 3; - public static final int MAXIMUM_SPEED = 4; private WeightingMethod() {} @@ -30,9 +29,6 @@ public static int getFromString(String method) { } else if ("recommended".equalsIgnoreCase(method)) { return WeightingMethod.RECOMMENDED; } - else if ("maximum_speed".equalsIgnoreCase(method)){ - return WeightingMethod.MAXIMUM_SPEED; - } return WeightingMethod.UNKNOWN; } @@ -44,8 +40,6 @@ public static String getName(int profileType) { return "shortest"; case RECOMMENDED: return "recommended"; - case MAXIMUM_SPEED: - return "maximum_speed"; default: return ""; } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index ec12ecebf8..77343e0c44 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -318,6 +318,12 @@ else if (ALT_ROUTE.equalsIgnoreCase(algoStr)) throw new IllegalArgumentException( "The max_visited_nodes parameter has to be below or equal to:" + getMaxVisitedNodes()); + + if(hints.has("user_speed")) { + weighting = new MaximumSpeedWeighting(encoder, hints, weighting); + } + + int uTurnCosts = hints.getInt(Parameters.Routing.U_TURN_COSTS, INFINITE_U_TURN_COSTS); weighting = createTurnWeighting(queryGraph, weighting, tMode, uTurnCosts); if (weighting instanceof TurnWeighting) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java index f7fd457c06..191cefe08b 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java @@ -72,9 +72,6 @@ else if ("fastest".equalsIgnoreCase(strWeighting)) else result = new FastestWeighting(encoder, hintsMap); } - else if ("maximum_speed".equalsIgnoreCase(strWeighting)){ - result = new MaximumSpeedWeighting(encoder, hintsMap); - } else if ("priority".equalsIgnoreCase(strWeighting)) { result = new PreferencePriorityWeighting(encoder, hintsMap); diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java index 6f9f54f468..4955335258 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java @@ -509,16 +509,9 @@ public RoutingAlgorithm createAlgo(Graph graph, AlgorithmOptions opts) { String algoStr = ASTAR_BI; if (ASTAR_BI.equals(algoStr)) { - if(opts.getHints().get("weighting_method","fastest") == "maximum_speed") { - CoreALT tmpAlgo = new CoreALT(graph, opts.getWeighting(), traversalMode); - tmpAlgo.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); - algo = tmpAlgo; - } - else{ - CoreALT tmpAlgo = new CoreALT(graph, prepareWeighting, traversalMode); - tmpAlgo.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); - algo = tmpAlgo; - } + CoreALT tmpAlgo = new CoreALT(graph, prepareWeighting, traversalMode); + tmpAlgo.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); + algo = tmpAlgo; } else if (DIJKSTRA_BI.equals(algoStr)) { algo = new CoreDijkstra(graph, prepareWeighting, traversalMode); } else { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index d3ba362bfc..0615470e5d 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -15,7 +15,7 @@ import com.graphhopper.routing.util.FlagEncoder; import com.graphhopper.routing.util.HintsMap; -import com.graphhopper.routing.weighting.FastestWeighting; +import com.graphhopper.routing.weighting.Weighting; import com.graphhopper.util.CHEdgeIteratorState; import com.graphhopper.util.EdgeIteratorState; import com.graphhopper.util.Parameters.Routing; @@ -26,21 +26,22 @@ * @author Athanasios Kogios */ -public class MaximumSpeedWeighting extends FastestWeighting { +public class MaximumSpeedWeighting implements Weighting { protected final static double SPEED_CONV = 3.6; //From km/h to m/s. private final double headingPenalty; private final double userMaxSpeed; - private final String weighting; - - public MaximumSpeedWeighting(FlagEncoder encoder, HintsMap map) { - super(encoder, map); - userMaxSpeed = map.getDouble("user_speed",80); - headingPenalty = map.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); - weighting = map.get("weighting","fastest"); + private final Weighting superWeighting; + private final FlagEncoder flagEncoder; + private HintsMap hintsMap; + + public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighting weighting) { + this.flagEncoder = flagEncoder; + this.hintsMap = hintsMap; + this.superWeighting = weighting; + userMaxSpeed = hintsMap.getDouble("user_speed",80); + headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); } - //TODO Find correct way to parse data. - private double speedToTime_km_h(double speed, EdgeIteratorState edge){ //Conversion of the speeds (km/h) to times taken from the edges into time adding the penalties double time = edge.getDistance() / speed * SPEED_CONV; @@ -53,54 +54,76 @@ private double speedToTime_km_h(double speed, EdgeIteratorState edge){ return time; } - private double speedToTime_m_s(double speed, EdgeIteratorState edge){ - //Conversion of the speeds (m/s) to times taken from the edges into time adding the penalties - double time = edge.getDistance() / speed; + @Override + public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId) { + CHEdgeIteratorState tmp = (CHEdgeIteratorState) edge; - // add direction penalties at start/stop/via points - boolean unfavoredEdge = edge.get(EdgeIteratorState.UNFAVORED_EDGE); - if (unfavoredEdge) - time += headingPenalty; + if(hintsMap.getWeighting() == "fastest") { + if (tmp.isShortcut()) { + return tmp.getWeight(); // If the edge is a shortcut we have a different way to get the weight. + } else { + //If it is not a shortcut we need to test both directions + double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); + if (speed > userMaxSpeed) { + speed = userMaxSpeed;// Change the speed to the maximum one defined by the user. + return speedToTime_km_h(speed, edge); + } else { + return superWeighting.calcWeight(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. + } + } + } + + return superWeighting.calcWeight(edge, reverse, prevOrNextEdgeId); - return time; } @Override - public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId) { + public long calcMillis(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId){ CHEdgeIteratorState tmp = (CHEdgeIteratorState) edge; - if (tmp.isShortcut()) { - //If a shortcut is in both directions the weight is identical => no need for 'reverse' - //tmp.getWeight() is in time (seconds) so we first change it to speed - double time = tmp.getWeight(); - double distance = edge.getDistance(); - double speed = edge.getDistance()/ tmp.getWeight(); - //Check for zero to avoid infinities - if (speed == 0) { - return Double.POSITIVE_INFINITY; - } - //Find the minimum of the two values. if (speed > userMaxSpeed) -> userMaxSpeed, else -> speed - speed = java.lang.Math.min(userMaxSpeed, speed); - //Convert speed to time - return speedToTime_m_s(speed, edge); - } - else{ - //If it is not a shortcut we need to test both directions - double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); - if (speed == 0) { - return Double.POSITIVE_INFINITY; - } - if(speed > userMaxSpeed) { - speed = userMaxSpeed; - return speedToTime_km_h(speed, edge); - }else{ - return super.calcWeight(edge, reverse, prevOrNextEdgeId); + + if(hintsMap.getWeighting() == "fastest") { + if (tmp.isShortcut()) { + return (long) tmp.getWeight(); // If the edge is a shortcut we have a different way to get the weight. + } else { + //If it is not a shortcut we need to test both directions + double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); + if (speed > userMaxSpeed) { + speed = userMaxSpeed;// Change the speed to the maximum one defined by the user. + return (long) speedToTime_km_h(speed, edge); + } else { + return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. + } } } + + return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId); + } + + + @Override + public double getMinWeight(double distance) { + return superWeighting.getMinWeight(distance); + } + + @Override + public FlagEncoder getFlagEncoder() { + return superWeighting.getFlagEncoder(); + } + + @Override + public boolean matches(HintsMap weightingMap) { + return superWeighting.matches(weightingMap); + } + + @Override + public String toString() { + return "maximum_speed|" + superWeighting.toString(); } @Override public String getName() { - return "maximum_speed"; + return "maximum_speed|" + superWeighting.getName(); } } + From 276b4f3752fca36d0e55ecde841cbe160d059a02 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Mon, 13 Apr 2020 12:12:08 +0200 Subject: [PATCH 13/38] Minor changes. --- .../main/java/org/heigit/ors/routing/RoutingProfile.java | 6 +++++- .../extensions/weighting/MaximumSpeedWeighting.java | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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 a3ea4e577b..2afc59c5d7 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -884,7 +884,7 @@ else if (bearings[1] == null) else setSpeedups(req, false, false, true); } - + //cannot use CH or CoreALT with requests where the weighting of non-predefined edges might change if(flexibleMode == KEY_FLEX_FULLY) setSpeedups(req, false, false, true); @@ -903,6 +903,10 @@ else if (bearings[1] == null) req.getHints().put("alternative_route.max_share_factor", searchParams.getAlternativeRoutesShareFactor()); } + if(searchParams.hasUserSpeed()){ + req.getHints().put("user_speed", searchParams.getUserSpeed()); + } + if (directedSegment) { resp = mGraphHopper.constructFreeHandRoute(req); } else { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 0615470e5d..90b6936079 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -38,8 +38,11 @@ public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighti this.flagEncoder = flagEncoder; this.hintsMap = hintsMap; this.superWeighting = weighting; - userMaxSpeed = hintsMap.getDouble("user_speed",80); - headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); + if(hintsMap.getDouble("user_speed",80) < 80 ){ + throw new RuntimeException("User speed should be <= 80."); + } + userMaxSpeed = hintsMap.getDouble("user_speed",80); + headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); } private double speedToTime_km_h(double speed, EdgeIteratorState edge){ From 21874688b8856f8a7e9409dc83625248dd7cecd7 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Mon, 13 Apr 2020 13:52:10 +0200 Subject: [PATCH 14/38] Fixed minor problems. --- .../core/MaximumSpeedCoreEdgeFilter.java | 5 +- .../src/main/resources/app.config | 346 ------------------ 2 files changed, 3 insertions(+), 348 deletions(-) delete mode 100644 openrouteservice/src/main/resources/app.config diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index c855c49e60..5f0ed17d26 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -29,10 +29,11 @@ public class MaximumSpeedCoreEdgeFilter implements EdgeFilter { private HeavyVehicleAttributesGraphStorage storage; - private double maxSpeed = Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","max_speed")); //Minimum speed of the core. + private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","max_speed")) != null) ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","max_speed")) : 80; //Minimum speed of the core. public final FlagEncoder flagEncoder; - public MaximumSpeedCoreEdgeFilter(FlagEncoder encoder, GraphStorage graphStorage) { + public + MaximumSpeedCoreEdgeFilter(FlagEncoder encoder, GraphStorage graphStorage) { this.flagEncoder = encoder; if (!flagEncoder.isRegistered()) throw new IllegalStateException("Make sure you add the FlagEncoder " + flagEncoder + " to an EncodingManager before using it elsewhere"); diff --git a/openrouteservice/src/main/resources/app.config b/openrouteservice/src/main/resources/app.config deleted file mode 100644 index bfb17bffc1..0000000000 --- a/openrouteservice/src/main/resources/app.config +++ /dev/null @@ -1,346 +0,0 @@ -{ - ors { - info: { - base_url: "https://openrouteservice.org/", - support_mail: "support@openrouteservice.org", - author_tag: "openrouteservice", - content_licence: "LGPL 3.0" - }, - services: { - matrix: { - enabled: true, - maximum_routes: 200, - maximum_visited_nodes: 100000, - allow_resolve_locations: true, - attribution: "openrouteservice.org, OpenStreetMap contributors" - } - isochrones: { - enabled: true, - # possible values for maximum_range_distance and maximum_range_time are an integer or a list of values specifically defined for each profile - maximum_range_distance: - [ - {profiles: "any", value: 50000} - {profiles: "driving-car, driving-hgv", value: 100000} - ], - maximum_range_time: - [ - {profiles: "any", value: 18000} - {profiles: "driving-car, driving-hgv", value: 3600} - ], - maximum_intervals: 10, - maximum_locations: 2, - allow_compute_area: true - } - routing: { - enabled: true, - mode: "normal", - sources: ["/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/heidelberg.osm.gz"], - init_threads: 1, - attribution: "openrouteservice.org, OpenStreetMap contributors, tmc - BASt", - distance_approximation: true, - routing_name: "ORSRouting", - profiles: { - active: ["vehicles-car"], - default_params: { - encoder_flags_size: 4, - graphs_root_path: "graphs", - elevation_provider: multi, - elevation_cache_clear: false, - elevation_cache_path: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/elevation", - instructions: true, - maximum_distance: 100000, - maximum_segment_distance_with_dynamic_weights: 50000, - maximum_waypoints: 50, - maximum_snapping_radius: 350, - max_speed: 80 - preparation: - { - min_network_size: 200, - min_one_way_network_size: 200, - - methods: - { - lm: - { - enabled: true, - threads: 1, - weightings: "fastest,shortest", - landmarks: 16 - } - } - } - execution: - { - methods: - { - lm: - { - disabling_allowed: true, - active_landmarks: 8 - } - } - } - }, - - profile-vehicles-car: { - profiles: "driving-car", - parameters: { - encoder_options: "turn_costs=true|block_fords=false|maximum_grade_level=1|use_acceleration=true", - maximum_distance: 100000, - elevation: true, - preparation: - { - min_network_size: 200, - min_one_way_network_size: 200, - - methods: - { - ch: - { - enabled: true, - threads: 1, - weightings: "fastest" - }, - lm: - { - enabled: true, - threads: 1, - weightings: "fastest", - landmarks: 16 - }, - core: - { - enabled: true, - threads: 1, - weightings: "fastest,shortest", - landmarks: 32 - } - } - } - execution: - { - methods: - { - ch: - { - disabling_allowed: true - }, - lm: - { - disabling_allowed: true, - active_landmarks: 8 - }, - core: - { - disabling_allowed: true, - active_landmarks: 6 - } - } - } - ext_storages: { - WayCategory: {}, - HeavyVehicle: {restrictions: true}, - WaySurfaceType: {}, - Tollways: {}, - Borders: { - boundaries: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/borders.geojson", - ids: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/ids.csv", - openborders: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/openborders.csv" - }, - RoadAccessRestrictions: { - use_for_warnings: true - } - } - traffic: false - } - } - profile-vehicles-hgv: { - profiles: "driving-hgv", - parameters: { - encoder_options: "turn_costs=true|block_fords=false|use_acceleration=true", - maximum_distance: 100000, - elevation: true, - preparation: - { - min_network_size: 200, - min_one_way_network_size: 200, - - methods: - { - ch: - { - enabled: true, - threads: 1, - weightings: "fastest" - }, - lm: - { - enabled: true, - threads: 1, - weightings: "fastest", - landmarks: 16 - }, - core: - { - enabled: true, - threads: 1, - weightings: "fastest,shortest", - landmarks: 32 - } - } - } - execution: - { - methods: - { - ch: - { - disabling_allowed: true - }, - lm: - { - disabling_allowed: true, - active_landmarks: 8 - }, - core: - { - disabling_allowed: true, - active_landmarks: 6 - } - } - } - ext_storages: { - WayCategory: {}, - HeavyVehicle: {restrictions: true}, - WaySurfaceType: {}, - Tollways: {}, - Borders: { - boundaries: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/borders.geojson", - ids: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/ids.csv", - openborders: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/openborders.csv" - } - } - traffic: false - } - } - - profile-bike: { - profiles: "cycling-regular", - parameters: { - encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", - elevation: true, - ext_storages: { - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - profile-bike-mtb: { - profiles: "cycling-mountain", - parameters: { - encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", - elevation: true, - maximum_snapping_radius: 10, - ext_storages: { - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - profile-bike-road: { - profiles: "cycling-road", - parameters: { - encoder_options: "consider_elevation=false|turn_costs=false|block_fords=false", - elevation: true, - ext_storages: { - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - profile-bike-e: { - profiles: "cycling-electric", - parameters: { - encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", - elevation: true, - ext_storages: { - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - - profile-pedestrian-walk: { - profiles: "foot-walking", - parameters: { - encoder_options: "block_fords=false", - elevation: true, - ext_storages: { - GreenIndex: { - filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/green_streets_hd.csv" - }, - NoiseIndex: { - filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/noise_data_hd.csv" - }, - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - }, - profile-pedestrian-hike: { - profiles: "foot-hiking", - parameters: { - encoder_options: "block_fords=false", - elevation: true, - ext_storages: { - GreenIndex: { - filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/green_streets_hd.csv" - }, - NoiseIndex: { - filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/noise_data_hd.csv" - }, - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - - profile-wheelchair: { - profiles: "wheelchair", - parameters: { - encoder_options: "block_fords=true", - elevation: true, - maximum_snapping_radius: 50, - ext_storages: { - Wheelchair: { - KerbsOnCrossings: "true" - }, - WaySurfaceType: {}, - WayCategory: {}, - OsmId: {} - } - } - } - } - } - } - logging: { - enabled: true, - level_file: "DEBUG_LOGGING.json", - location: "./logs", - stdout: true - } - } -} From b7d4608d144ae874ba005940d817280931ffdafd Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Fri, 17 Apr 2020 15:49:47 +0200 Subject: [PATCH 15/38] Fully working MaximumSpeedWeighting. --- .../extensions/core/PrepareCore.java | 4 ++-- .../weighting/MaximumSpeedWeighting.java | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java index 4955335258..fee1a76aed 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/core/PrepareCore.java @@ -509,11 +509,11 @@ public RoutingAlgorithm createAlgo(Graph graph, AlgorithmOptions opts) { String algoStr = ASTAR_BI; if (ASTAR_BI.equals(algoStr)) { - CoreALT tmpAlgo = new CoreALT(graph, prepareWeighting, traversalMode); + CoreALT tmpAlgo = new CoreALT(graph,new PreparationWeighting(opts.getWeighting()), traversalMode); tmpAlgo.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); algo = tmpAlgo; } else if (DIJKSTRA_BI.equals(algoStr)) { - algo = new CoreDijkstra(graph, prepareWeighting, traversalMode); + algo = new CoreDijkstra(graph, new PreparationWeighting(opts.getWeighting()), traversalMode); } else { throw new IllegalArgumentException("Algorithm " + opts.getAlgorithm() + " not supported for Contraction Hierarchies. Try with ch.disable=true"); diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 90b6936079..654cdc7133 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -82,20 +82,18 @@ public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNext @Override public long calcMillis(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId){ - CHEdgeIteratorState tmp = (CHEdgeIteratorState) edge; + if (edge instanceof CHEdgeIteratorState && ((CHEdgeIteratorState) edge).isShortcut()) { + throw new IllegalStateException("calcMillis should only be called on original edges"); + } if(hintsMap.getWeighting() == "fastest") { - if (tmp.isShortcut()) { - return (long) tmp.getWeight(); // If the edge is a shortcut we have a different way to get the weight. + //If it is not a shortcut we need to test both directions + double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); + if (speed > userMaxSpeed) { + speed = userMaxSpeed;// Change the speed to the maximum one defined by the user. + return (long) speedToTime_km_h(speed, edge); } else { - //If it is not a shortcut we need to test both directions - double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); - if (speed > userMaxSpeed) { - speed = userMaxSpeed;// Change the speed to the maximum one defined by the user. - return (long) speedToTime_km_h(speed, edge); - } else { - return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. - } + return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. } } From 7d45c4f7a1e70d53944d5411a1842b8c297ad615 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Mon, 20 Apr 2020 13:00:48 +0200 Subject: [PATCH 16/38] Working MaximumSpeedWeighting plus a corresponding filter. --- .../ors/v2/services/routing/ResultTest.java | 23 +++++++++++++++ .../weighting/MaximumSpeedWeighting.java | 29 +++++++++++++------ 2 files changed, 43 insertions(+), 9 deletions(-) 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 3a91f2ac4b..8912deac0a 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 @@ -1221,6 +1221,29 @@ public void testOptimizedAndTurnRestrictions() { .statusCode(200); } + @Test + public void testMaximumSpeedWeighting() { + JSONObject body = new JSONObject(); + body.put("coordinates", constructCoords("8.63348,49.41766|8.6441,49.4672")); + body.put("preference", getParameter("preference")); + body.put("instructions", true); + body.put("user_speed",80); + + // Test that the "right turn only" restriction at the junction is taken into account + given() + .header("Accept", "application/json") + .header("Content-Type", "application/json") + .pathParam("profile", "driving-car") + .body(body.toString()) + .when() + .post(getEndPointPath() + "/{profile}") + .then() + .assertThat() + .body("any { it.key == 'routes' }", is(true)) + .body("routes[0].summary.duration", is(1694.8f)) + .statusCode(200); + } + @Test public void testNoBearings() { JSONObject body = new JSONObject(); diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 654cdc7133..68dc9234b0 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -29,6 +29,7 @@ public class MaximumSpeedWeighting implements Weighting { protected final static double SPEED_CONV = 3.6; //From km/h to m/s. private final double headingPenalty; + private final long headingPenaltyMillis; private final double userMaxSpeed; private final Weighting superWeighting; private final FlagEncoder flagEncoder; @@ -41,12 +42,14 @@ public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighti if(hintsMap.getDouble("user_speed",80) < 80 ){ throw new RuntimeException("User speed should be <= 80."); } - userMaxSpeed = hintsMap.getDouble("user_speed",80); headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); + headingPenaltyMillis = Math.round(headingPenalty * 1000); + userMaxSpeed = hintsMap.getDouble("user_speed",80); } - private double speedToTime_km_h(double speed, EdgeIteratorState edge){ - //Conversion of the speeds (km/h) to times taken from the edges into time adding the penalties + /** This function computes the weight when the speed of the edge is greater than the user speed */ + private double calcMaximumSpeedWeight(double speed, EdgeIteratorState edge){ + //Conversion of the speeds to times including the factor for changing from km/h -> m/s. double time = edge.getDistance() / speed * SPEED_CONV; // add direction penalties at start/stop/via points @@ -57,6 +60,15 @@ private double speedToTime_km_h(double speed, EdgeIteratorState edge){ return time; } + /** This function is going to add the difference of: (edge speed - maximum_speed) in the calcMillis. */ + private double calcMaximumSpeedMillis(double userMaxSpeed, double speed, EdgeIteratorState edge){ + // TODO move this to AbstractWeighting? see #485 + //Conversion of the speeds to times including the factor for changing from km/h -> m/ms. + double time = Math.abs((edge.getDistance() * ( 1 / speed - 1 / userMaxSpeed ))) * SPEED_CONV * 1000; + + return time; + } + @Override public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId) { CHEdgeIteratorState tmp = (CHEdgeIteratorState) edge; @@ -69,7 +81,7 @@ public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNext double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); if (speed > userMaxSpeed) { speed = userMaxSpeed;// Change the speed to the maximum one defined by the user. - return speedToTime_km_h(speed, edge); + return calcMaximumSpeedWeight(speed, edge); } else { return superWeighting.calcWeight(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. } @@ -82,16 +94,15 @@ public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNext @Override public long calcMillis(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId){ - if (edge instanceof CHEdgeIteratorState && ((CHEdgeIteratorState) edge).isShortcut()) { - throw new IllegalStateException("calcMillis should only be called on original edges"); - } if(hintsMap.getWeighting() == "fastest") { //If it is not a shortcut we need to test both directions double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); if (speed > userMaxSpeed) { - speed = userMaxSpeed;// Change the speed to the maximum one defined by the user. - return (long) speedToTime_km_h(speed, edge); + long testTest= superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId); + long testTestTest = (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); + long test = superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId) + (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); + return test; } else { return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. } From 398b467499fcc28b2ce01b7777c01c02f9ce39c8 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 29 Apr 2020 11:57:24 +0200 Subject: [PATCH 17/38] Passed the tests performed using R. --- .../weighting/MaximumSpeedWeighting.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 68dc9234b0..04f27a171d 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -95,20 +95,16 @@ public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNext @Override public long calcMillis(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId){ - if(hintsMap.getWeighting() == "fastest") { - //If it is not a shortcut we need to test both directions - double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); - if (speed > userMaxSpeed) { - long testTest= superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId); - long testTestTest = (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); - long test = superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId) + (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); - return test; - } else { - return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. - } + //If it is not a shortcut we need to test both directions + double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); + if (speed > userMaxSpeed) { + long testTest= superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId); + long testTestTest = (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); + long test = superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId) + (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); + return test; + } else { + return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. } - - return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId); } From bbba0a01b13c11ea84a091a68df7e2a30d138d3d Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 6 May 2020 14:12:09 +0200 Subject: [PATCH 18/38] Change app.config max_speed to maximum_speed. --- .../core/MaximumSpeedCoreEdgeFilter.java | 2 +- .../src/main/resources/app.config | 346 ++++++++++++++++++ 2 files changed, 347 insertions(+), 1 deletion(-) create mode 100644 openrouteservice/src/main/resources/app.config diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index 5f0ed17d26..dfcf761c37 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -29,7 +29,7 @@ public class MaximumSpeedCoreEdgeFilter implements EdgeFilter { private HeavyVehicleAttributesGraphStorage storage; - private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","max_speed")) != null) ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","max_speed")) : 80; //Minimum speed of the core. + private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) != null) ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","max_speed")) : 80; //Minimum speed of the core. public final FlagEncoder flagEncoder; public diff --git a/openrouteservice/src/main/resources/app.config b/openrouteservice/src/main/resources/app.config new file mode 100644 index 0000000000..f714d0a333 --- /dev/null +++ b/openrouteservice/src/main/resources/app.config @@ -0,0 +1,346 @@ +{ + ors { + info: { + base_url: "https://openrouteservice.org/", + support_mail: "support@openrouteservice.org", + author_tag: "openrouteservice", + content_licence: "LGPL 3.0" + }, + services: { + matrix: { + enabled: true, + maximum_routes: 200, + maximum_visited_nodes: 100000, + allow_resolve_locations: true, + attribution: "openrouteservice.org, OpenStreetMap contributors" + } + isochrones: { + enabled: true, + # possible values for maximum_range_distance and maximum_range_time are an integer or a list of values specifically defined for each profile + maximum_range_distance: + [ + {profiles: "any", value: 50000} + {profiles: "driving-car, driving-hgv", value: 100000} + ], + maximum_range_time: + [ + {profiles: "any", value: 18000} + {profiles: "driving-car, driving-hgv", value: 3600} + ], + maximum_intervals: 10, + maximum_locations: 2, + allow_compute_area: true + } + routing: { + enabled: true, + mode: "normal", + sources: ["/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/heidelberg.osm.gz"], + init_threads: 1, + attribution: "openrouteservice.org, OpenStreetMap contributors, tmc - BASt", + distance_approximation: true, + routing_name: "ORSRouting", + profiles: { + active: ["vehicles-car"], + default_params: { + encoder_flags_size: 4, + graphs_root_path: "graphs", + elevation_provider: multi, + elevation_cache_clear: false, + elevation_cache_path: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/elevation", + instructions: true, + maximum_distance: 100000, + maximum_segment_distance_with_dynamic_weights: 50000, + maximum_waypoints: 50, + maximum_snapping_radius: 350, + maximum_speed: 80, + preparation: + { + min_network_size: 200, + min_one_way_network_size: 200, + + methods: + { + lm: + { + enabled: true, + threads: 1, + weightings: "fastest,shortest", + landmarks: 16 + } + } + } + execution: + { + methods: + { + lm: + { + disabling_allowed: true, + active_landmarks: 8 + } + } + } + }, + + profile-vehicles-car: { + profiles: "driving-car", + parameters: { + encoder_options: "turn_costs=true|block_fords=false|maximum_grade_level=1|use_acceleration=true", + maximum_distance: 100000, + elevation: true, + preparation: + { + min_network_size: 200, + min_one_way_network_size: 200, + + methods: + { + ch: + { + enabled: false, + threads: 1, + weightings: "fastest" + }, + lm: + { + enabled: true, + threads: 1, + weightings: "fastest", + landmarks: 16 + }, + core: + { + enabled: true, + threads: 1, + weightings: "fastest,shortest", + landmarks: 32 + } + } + } + execution: + { + methods: + { + ch: + { + disabling_allowed: true + }, + lm: + { + disabling_allowed: true, + active_landmarks: 8 + }, + core: + { + disabling_allowed: true, + active_landmarks: 6 + } + } + } + ext_storages: { + WayCategory: {}, + HeavyVehicle: {restrictions: true}, + WaySurfaceType: {}, + Tollways: {}, + Borders: { + boundaries: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/borders.geojson", + ids: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/ids.csv", + openborders: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/openborders.csv" + }, + RoadAccessRestrictions: { + use_for_warnings: true + } + } + traffic: false + } + } + profile-vehicles-hgv: { + profiles: "driving-hgv", + parameters: { + encoder_options: "turn_costs=true|block_fords=false|use_acceleration=true", + maximum_distance: 100000, + elevation: true, + preparation: + { + min_network_size: 200, + min_one_way_network_size: 200, + + methods: + { + ch: + { + enabled: true, + threads: 1, + weightings: "fastest" + }, + lm: + { + enabled: true, + threads: 1, + weightings: "fastest", + landmarks: 16 + }, + core: + { + enabled: true, + threads: 1, + weightings: "fastest,shortest", + landmarks: 32 + } + } + } + execution: + { + methods: + { + ch: + { + disabling_allowed: true + }, + lm: + { + disabling_allowed: true, + active_landmarks: 8 + }, + core: + { + disabling_allowed: true, + active_landmarks: 6 + } + } + } + ext_storages: { + WayCategory: {}, + HeavyVehicle: {restrictions: true}, + WaySurfaceType: {}, + Tollways: {}, + Borders: { + boundaries: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/borders.geojson", + ids: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/ids.csv", + openborders: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/openborders.csv" + } + } + traffic: false + } + } + + profile-bike: { + profiles: "cycling-regular", + parameters: { + encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", + elevation: true, + ext_storages: { + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + profile-bike-mtb: { + profiles: "cycling-mountain", + parameters: { + encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", + elevation: true, + maximum_snapping_radius: 10, + ext_storages: { + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + profile-bike-road: { + profiles: "cycling-road", + parameters: { + encoder_options: "consider_elevation=false|turn_costs=false|block_fords=false", + elevation: true, + ext_storages: { + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + profile-bike-e: { + profiles: "cycling-electric", + parameters: { + encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", + elevation: true, + ext_storages: { + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + + profile-pedestrian-walk: { + profiles: "foot-walking", + parameters: { + encoder_options: "block_fords=false", + elevation: true, + ext_storages: { + GreenIndex: { + filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/green_streets_hd.csv" + }, + NoiseIndex: { + filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/noise_data_hd.csv" + }, + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + }, + profile-pedestrian-hike: { + profiles: "foot-hiking", + parameters: { + encoder_options: "block_fords=false", + elevation: true, + ext_storages: { + GreenIndex: { + filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/green_streets_hd.csv" + }, + NoiseIndex: { + filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/noise_data_hd.csv" + }, + WayCategory: {}, + WaySurfaceType: {}, + HillIndex: {}, + TrailDifficulty: {} + } + } + } + + profile-wheelchair: { + profiles: "wheelchair", + parameters: { + encoder_options: "block_fords=true", + elevation: true, + maximum_snapping_radius: 50, + ext_storages: { + Wheelchair: { + KerbsOnCrossings: "true" + }, + WaySurfaceType: {}, + WayCategory: {}, + OsmId: {} + } + } + } + } + } + } + logging: { + enabled: true, + level_file: "DEBUG_LOGGING.json", + location: "./logs", + stdout: true + } + } +} From 483caac9cca3b2f74fefee0282f502880d4862a4 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 6 May 2020 14:56:40 +0200 Subject: [PATCH 19/38] Minor fixes. --- .../extensions/flagencoders/VehicleFlagEncoder.java | 2 -- openrouteservice/src/main/resources/app.config | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java index bed520cafb..b355333b23 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java @@ -234,8 +234,6 @@ public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, EncodingManager.A } } - if (speed > 80) System.out.println(way.getId() + " " + speed); - setSpeed(false, edgeFlags, speed); setSpeed(true, edgeFlags, speed); diff --git a/openrouteservice/src/main/resources/app.config b/openrouteservice/src/main/resources/app.config index f714d0a333..cc2b3ea2ce 100644 --- a/openrouteservice/src/main/resources/app.config +++ b/openrouteservice/src/main/resources/app.config @@ -34,7 +34,7 @@ routing: { enabled: true, mode: "normal", - sources: ["/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/heidelberg.osm.gz"], + sources: ["/home/star_pirate/GIScience/openrouteservice/openrouteservice/src/main/files/bayern-latest.osm.bz2"], init_threads: 1, attribution: "openrouteservice.org, OpenStreetMap contributors, tmc - BASt", distance_approximation: true, @@ -48,7 +48,7 @@ elevation_cache_clear: false, elevation_cache_path: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/elevation", instructions: true, - maximum_distance: 100000, + maximum_distance: 1000000, maximum_segment_distance_with_dynamic_weights: 50000, maximum_waypoints: 50, maximum_snapping_radius: 350, @@ -86,7 +86,7 @@ profiles: "driving-car", parameters: { encoder_options: "turn_costs=true|block_fords=false|maximum_grade_level=1|use_acceleration=true", - maximum_distance: 100000, + maximum_distance: 1000000, elevation: true, preparation: { @@ -158,7 +158,7 @@ profiles: "driving-hgv", parameters: { encoder_options: "turn_costs=true|block_fords=false|use_acceleration=true", - maximum_distance: 100000, + maximum_distance: 1000000, elevation: true, preparation: { From 1a1635b81ecddcb7b037bd7db9d94bf13f21f907 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Mon, 11 May 2020 12:21:08 +0200 Subject: [PATCH 20/38] Fixed some errors. --- .../routing/graphhopper/extensions/ORSGraphHopper.java | 7 ++++--- .../edgefilters/core/MaximumSpeedCoreEdgeFilter.java | 10 ++++------ openrouteservice/src/main/resources/app.config | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index 77343e0c44..158055282f 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -528,11 +528,12 @@ public void postProcessing() { /* Maximum Speed Filter */ if (routingProfileCategory !=0 & encodingManager.hasEncoder("heavyvehicle")) { FlagEncoder flagEncoder=getEncodingManager().getEncoder("heavyvehicle"); // Set encoder only for heavy vehicles. - coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, gs)); + coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder)); } - if (routingProfileCategory !=0 & encodingManager.hasEncoder("car-ors")) { + + if (routingProfileCategory !=0 & encodingManager.hasEncoder("car-ors") ){ FlagEncoder flagEncoder=getEncodingManager().getEncoder("car-ors"); // Set encoder only for cars. - coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, gs)); + coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder)); } /* End filter sequence initialization */ diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index dfcf761c37..a48d787211 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -14,6 +14,7 @@ package org.heigit.ors.routing.graphhopper.extensions.edgefilters.core; import com.graphhopper.routing.util.EdgeFilter; +import com.graphhopper.storage.GraphHopperStorage; import com.graphhopper.storage.GraphStorage; import com.graphhopper.util.EdgeIteratorState; import com.graphhopper.routing.util.FlagEncoder; @@ -28,16 +29,13 @@ */ public class MaximumSpeedCoreEdgeFilter implements EdgeFilter { - private HeavyVehicleAttributesGraphStorage storage; - private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) != null) ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","max_speed")) : 80; //Minimum speed of the core. + private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) != null) ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) : 80; //Minimum speed of the core. public final FlagEncoder flagEncoder; - public - MaximumSpeedCoreEdgeFilter(FlagEncoder encoder, GraphStorage graphStorage) { - this.flagEncoder = encoder; + public MaximumSpeedCoreEdgeFilter(FlagEncoder flagEncoder) { + this.flagEncoder = flagEncoder; if (!flagEncoder.isRegistered()) throw new IllegalStateException("Make sure you add the FlagEncoder " + flagEncoder + " to an EncodingManager before using it elsewhere"); - storage = GraphStorageUtils.getGraphExtension(graphStorage, HeavyVehicleAttributesGraphStorage.class); } @Override diff --git a/openrouteservice/src/main/resources/app.config b/openrouteservice/src/main/resources/app.config index cc2b3ea2ce..e121a59101 100644 --- a/openrouteservice/src/main/resources/app.config +++ b/openrouteservice/src/main/resources/app.config @@ -34,7 +34,7 @@ routing: { enabled: true, mode: "normal", - sources: ["/home/star_pirate/GIScience/openrouteservice/openrouteservice/src/main/files/bayern-latest.osm.bz2"], + sources: ["/home/star_pirate/GIScience/openrouteservice/openrouteservice/src/main/files/heidelberg.osm.gz"], init_threads: 1, attribution: "openrouteservice.org, OpenStreetMap contributors, tmc - BASt", distance_approximation: true, From 683992b9d5b7a40f77a1d8ca06fd480d05659b2c Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 20 May 2020 15:06:26 +0200 Subject: [PATCH 21/38] Removed test variables. --- openrouteservice/pom.xml | 6 ++---- .../extensions/weighting/MaximumSpeedWeighting.java | 8 +------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/openrouteservice/pom.xml b/openrouteservice/pom.xml index cac7449df4..7ebfa04d86 100644 --- a/openrouteservice/pom.xml +++ b/openrouteservice/pom.xml @@ -281,7 +281,6 @@ 3.0.3 - - + com.typesafe config diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 04f27a171d..afb2602380 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -62,7 +62,6 @@ private double calcMaximumSpeedWeight(double speed, EdgeIteratorState edge){ /** This function is going to add the difference of: (edge speed - maximum_speed) in the calcMillis. */ private double calcMaximumSpeedMillis(double userMaxSpeed, double speed, EdgeIteratorState edge){ - // TODO move this to AbstractWeighting? see #485 //Conversion of the speeds to times including the factor for changing from km/h -> m/ms. double time = Math.abs((edge.getDistance() * ( 1 / speed - 1 / userMaxSpeed ))) * SPEED_CONV * 1000; @@ -94,14 +93,9 @@ public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNext @Override public long calcMillis(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId){ - - //If it is not a shortcut we need to test both directions double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); if (speed > userMaxSpeed) { - long testTest= superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId); - long testTestTest = (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); - long test = superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId) + (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); - return test; + return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId) + (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); } else { return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. } From 50a8ca3d9f5bb2315116b9b68ece7e43aa62cb91 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 20 May 2020 15:09:50 +0200 Subject: [PATCH 22/38] Revert changes in pom.xml. --- openrouteservice/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openrouteservice/pom.xml b/openrouteservice/pom.xml index 7ebfa04d86..df0be2e7d9 100644 --- a/openrouteservice/pom.xml +++ b/openrouteservice/pom.xml @@ -316,7 +316,8 @@ graphhopper-reader-osm 0.13-SNAPSHOT ---> + --> + com.typesafe config From d24f98d91df52f9dce6cf31c83bec429f40367f2 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 20 May 2020 16:17:19 +0200 Subject: [PATCH 23/38] Remove app.config. --- .../src/main/resources/app.config | 346 ------------------ .../src/main/resources/app.config.sample | 1 + 2 files changed, 1 insertion(+), 346 deletions(-) delete mode 100644 openrouteservice/src/main/resources/app.config diff --git a/openrouteservice/src/main/resources/app.config b/openrouteservice/src/main/resources/app.config deleted file mode 100644 index e121a59101..0000000000 --- a/openrouteservice/src/main/resources/app.config +++ /dev/null @@ -1,346 +0,0 @@ -{ - ors { - info: { - base_url: "https://openrouteservice.org/", - support_mail: "support@openrouteservice.org", - author_tag: "openrouteservice", - content_licence: "LGPL 3.0" - }, - services: { - matrix: { - enabled: true, - maximum_routes: 200, - maximum_visited_nodes: 100000, - allow_resolve_locations: true, - attribution: "openrouteservice.org, OpenStreetMap contributors" - } - isochrones: { - enabled: true, - # possible values for maximum_range_distance and maximum_range_time are an integer or a list of values specifically defined for each profile - maximum_range_distance: - [ - {profiles: "any", value: 50000} - {profiles: "driving-car, driving-hgv", value: 100000} - ], - maximum_range_time: - [ - {profiles: "any", value: 18000} - {profiles: "driving-car, driving-hgv", value: 3600} - ], - maximum_intervals: 10, - maximum_locations: 2, - allow_compute_area: true - } - routing: { - enabled: true, - mode: "normal", - sources: ["/home/star_pirate/GIScience/openrouteservice/openrouteservice/src/main/files/heidelberg.osm.gz"], - init_threads: 1, - attribution: "openrouteservice.org, OpenStreetMap contributors, tmc - BASt", - distance_approximation: true, - routing_name: "ORSRouting", - profiles: { - active: ["vehicles-car"], - default_params: { - encoder_flags_size: 4, - graphs_root_path: "graphs", - elevation_provider: multi, - elevation_cache_clear: false, - elevation_cache_path: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/elevation", - instructions: true, - maximum_distance: 1000000, - maximum_segment_distance_with_dynamic_weights: 50000, - maximum_waypoints: 50, - maximum_snapping_radius: 350, - maximum_speed: 80, - preparation: - { - min_network_size: 200, - min_one_way_network_size: 200, - - methods: - { - lm: - { - enabled: true, - threads: 1, - weightings: "fastest,shortest", - landmarks: 16 - } - } - } - execution: - { - methods: - { - lm: - { - disabling_allowed: true, - active_landmarks: 8 - } - } - } - }, - - profile-vehicles-car: { - profiles: "driving-car", - parameters: { - encoder_options: "turn_costs=true|block_fords=false|maximum_grade_level=1|use_acceleration=true", - maximum_distance: 1000000, - elevation: true, - preparation: - { - min_network_size: 200, - min_one_way_network_size: 200, - - methods: - { - ch: - { - enabled: false, - threads: 1, - weightings: "fastest" - }, - lm: - { - enabled: true, - threads: 1, - weightings: "fastest", - landmarks: 16 - }, - core: - { - enabled: true, - threads: 1, - weightings: "fastest,shortest", - landmarks: 32 - } - } - } - execution: - { - methods: - { - ch: - { - disabling_allowed: true - }, - lm: - { - disabling_allowed: true, - active_landmarks: 8 - }, - core: - { - disabling_allowed: true, - active_landmarks: 6 - } - } - } - ext_storages: { - WayCategory: {}, - HeavyVehicle: {restrictions: true}, - WaySurfaceType: {}, - Tollways: {}, - Borders: { - boundaries: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/borders.geojson", - ids: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/ids.csv", - openborders: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/openborders.csv" - }, - RoadAccessRestrictions: { - use_for_warnings: true - } - } - traffic: false - } - } - profile-vehicles-hgv: { - profiles: "driving-hgv", - parameters: { - encoder_options: "turn_costs=true|block_fords=false|use_acceleration=true", - maximum_distance: 1000000, - elevation: true, - preparation: - { - min_network_size: 200, - min_one_way_network_size: 200, - - methods: - { - ch: - { - enabled: true, - threads: 1, - weightings: "fastest" - }, - lm: - { - enabled: true, - threads: 1, - weightings: "fastest", - landmarks: 16 - }, - core: - { - enabled: true, - threads: 1, - weightings: "fastest,shortest", - landmarks: 32 - } - } - } - execution: - { - methods: - { - ch: - { - disabling_allowed: true - }, - lm: - { - disabling_allowed: true, - active_landmarks: 8 - }, - core: - { - disabling_allowed: true, - active_landmarks: 6 - } - } - } - ext_storages: { - WayCategory: {}, - HeavyVehicle: {restrictions: true}, - WaySurfaceType: {}, - Tollways: {}, - Borders: { - boundaries: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/borders.geojson", - ids: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/ids.csv", - openborders: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/borders/openborders.csv" - } - } - traffic: false - } - } - - profile-bike: { - profiles: "cycling-regular", - parameters: { - encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", - elevation: true, - ext_storages: { - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - profile-bike-mtb: { - profiles: "cycling-mountain", - parameters: { - encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", - elevation: true, - maximum_snapping_radius: 10, - ext_storages: { - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - profile-bike-road: { - profiles: "cycling-road", - parameters: { - encoder_options: "consider_elevation=false|turn_costs=false|block_fords=false", - elevation: true, - ext_storages: { - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - profile-bike-e: { - profiles: "cycling-electric", - parameters: { - encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false", - elevation: true, - ext_storages: { - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - - profile-pedestrian-walk: { - profiles: "foot-walking", - parameters: { - encoder_options: "block_fords=false", - elevation: true, - ext_storages: { - GreenIndex: { - filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/green_streets_hd.csv" - }, - NoiseIndex: { - filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/noise_data_hd.csv" - }, - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - }, - profile-pedestrian-hike: { - profiles: "foot-hiking", - parameters: { - encoder_options: "block_fords=false", - elevation: true, - ext_storages: { - GreenIndex: { - filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/green_streets_hd.csv" - }, - NoiseIndex: { - filepath: "/home/star_pirate/GIScience/openrouteservice/openrouteservice-api-tests/data/noise_data_hd.csv" - }, - WayCategory: {}, - WaySurfaceType: {}, - HillIndex: {}, - TrailDifficulty: {} - } - } - } - - profile-wheelchair: { - profiles: "wheelchair", - parameters: { - encoder_options: "block_fords=true", - elevation: true, - maximum_snapping_radius: 50, - ext_storages: { - Wheelchair: { - KerbsOnCrossings: "true" - }, - WaySurfaceType: {}, - WayCategory: {}, - OsmId: {} - } - } - } - } - } - } - logging: { - enabled: true, - level_file: "DEBUG_LOGGING.json", - location: "./logs", - stdout: true - } - } -} diff --git a/openrouteservice/src/main/resources/app.config.sample b/openrouteservice/src/main/resources/app.config.sample index dcdae02599..0381d10ca6 100644 --- a/openrouteservice/src/main/resources/app.config.sample +++ b/openrouteservice/src/main/resources/app.config.sample @@ -68,6 +68,7 @@ "maximum_distance_alternative_routes": 100000, "maximum_alternative_routes": 3, "maximum_distance_round_trip_routes": 100000, + "maximum_speed": 80, "preparation": { "min_network_size": 200, "min_one_way_network_size": 200, From bb6fb48cb79e3c3d99c0f565c40ba14d56e72ce5 Mon Sep 17 00:00:00 2001 From: aoles Date: Thu, 21 May 2020 15:34:10 +0200 Subject: [PATCH 24/38] Require dynamic preprocessed algorithm when speed limit is provided --- .../org/heigit/ors/routing/RouteSearchParameters.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java index 24e0970ec6..d53847f5ca 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java @@ -530,14 +530,18 @@ public long getRoundTripSeed() { return roundTripSeed; } - public double getUserSpeed() {return userSpeed;} + public double getUserSpeed() { + return userSpeed; + } public void setUserSpeed(double userSpeed) { this.userSpeed = userSpeed; hasUserSpeed = true; } - public boolean hasUserSpeed() {return hasUserSpeed;} + public boolean hasUserSpeed() { + return hasUserSpeed; + } public boolean isProfileTypeDriving() { return RoutingProfileType.isDriving(this.getProfileType()); @@ -554,7 +558,8 @@ public boolean requiresDynamicPreprocessedWeights() { || hasAvoidCountries() || getConsiderTurnRestrictions() || isProfileTypeHeavyVehicle() && getVehicleType() > 0 - || isProfileTypeDriving() && hasParameters(VehicleParameters.class); + || isProfileTypeDriving() && hasParameters(VehicleParameters.class) + || hasUserSpeed(); } /** From eecd1e0018b6d0d40584d951fc6744d975635cb5 Mon Sep 17 00:00:00 2001 From: aoles Date: Fri, 29 May 2020 13:17:55 +0200 Subject: [PATCH 25/38] Cleanup and refactoring --- .../weighting/MaximumSpeedWeighting.java | 49 +++++++------------ 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index afb2602380..1a6c04db69 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -13,10 +13,10 @@ */ package org.heigit.ors.routing.graphhopper.extensions.weighting; +import com.graphhopper.routing.profiles.DecimalEncodedValue; import com.graphhopper.routing.util.FlagEncoder; import com.graphhopper.routing.util.HintsMap; import com.graphhopper.routing.weighting.Weighting; -import com.graphhopper.util.CHEdgeIteratorState; import com.graphhopper.util.EdgeIteratorState; import com.graphhopper.util.Parameters.Routing; @@ -29,22 +29,20 @@ public class MaximumSpeedWeighting implements Weighting { protected final static double SPEED_CONV = 3.6; //From km/h to m/s. private final double headingPenalty; - private final long headingPenaltyMillis; private final double userMaxSpeed; private final Weighting superWeighting; - private final FlagEncoder flagEncoder; - private HintsMap hintsMap; + private final DecimalEncodedValue avSpeedEnc; + private boolean calculateWeight; public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighting weighting) { - this.flagEncoder = flagEncoder; - this.hintsMap = hintsMap; - this.superWeighting = weighting; - if(hintsMap.getDouble("user_speed",80) < 80 ){ - throw new RuntimeException("User speed should be <= 80."); - } - headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); - headingPenaltyMillis = Math.round(headingPenalty * 1000); - userMaxSpeed = hintsMap.getDouble("user_speed",80); + this.avSpeedEnc = flagEncoder.getAverageSpeedEnc(); + this.superWeighting = weighting; + if(hintsMap.getDouble("user_speed",80) < 80 ){ + throw new RuntimeException("User speed should be <= 80."); + } + this.headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); + this.userMaxSpeed = hintsMap.getDouble("user_speed",80); + this.calculateWeight = (hintsMap.getWeighting() == "fastest"); } /** This function computes the weight when the speed of the edge is greater than the user speed */ @@ -70,30 +68,18 @@ private double calcMaximumSpeedMillis(double userMaxSpeed, double speed, EdgeIte @Override public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId) { - CHEdgeIteratorState tmp = (CHEdgeIteratorState) edge; - - if(hintsMap.getWeighting() == "fastest") { - if (tmp.isShortcut()) { - return tmp.getWeight(); // If the edge is a shortcut we have a different way to get the weight. - } else { - //If it is not a shortcut we need to test both directions - double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); - if (speed > userMaxSpeed) { - speed = userMaxSpeed;// Change the speed to the maximum one defined by the user. - return calcMaximumSpeedWeight(speed, edge); - } else { - return superWeighting.calcWeight(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. - } - } + if (calculateWeight) { + double speed = reverse ? edge.get(avSpeedEnc) : edge.getReverse(avSpeedEnc); + if (speed > userMaxSpeed) + return calcMaximumSpeedWeight(userMaxSpeed, edge);// Use the maximum speed defined } } return superWeighting.calcWeight(edge, reverse, prevOrNextEdgeId); - } @Override public long calcMillis(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId){ - double speed = reverse ? edge.get(flagEncoder.getAverageSpeedEnc()) : edge.getReverse(flagEncoder.getAverageSpeedEnc()); + double speed = reverse ? edge.get(avSpeedEnc) : edge.getReverse(avSpeedEnc); if (speed > userMaxSpeed) { return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId) + (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); } else { @@ -117,7 +103,7 @@ public boolean matches(HintsMap weightingMap) { return superWeighting.matches(weightingMap); } - @Override + @Override public String toString() { return "maximum_speed|" + superWeighting.toString(); } @@ -128,4 +114,3 @@ public String getName() { } } - From 0f198da0bdbc9b10a42c69aef50c7de75fe5542e Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 3 Jun 2020 16:36:12 +0200 Subject: [PATCH 26/38] Reviews. --- CHANGELOG.md | 3 + PULL_REQUEST_TEMPLATE.md | 2 +- .../ors/v2/services/routing/ResultTest.java | 2 +- .../requests/routing/RouteRequestHandler.java | 97 ++++++++++--------- .../core/MaximumSpeedCoreEdgeFilter.java | 9 +- .../weighting/MaximumSpeedWeighting.java | 20 ++-- 6 files changed, 71 insertions(+), 62 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 927a954993..658d86c789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added +* Added a Maximum Speed Core Edge Filter to include in the core edges with speed more than a value parsed from app.config. +* Added a Maximum Speed Weighting to perform routing using a user defined maximum speed as a parameter. + ### Fixed ### Changed ### Deprecated diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 3d2b61a738..b4c9966c42 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -17,7 +17,7 @@ Fixes # . ### Information about the changes - Key functionality added: -- Reason for change: +- Reason for change: C ### Examples and reasons for differences between live ORS routes and those generated from this pull request - 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 6998882e26..de9cd508b9 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 @@ -1230,7 +1230,7 @@ public void testMaximumSpeedWeighting() { body.put("instructions", true); body.put("user_speed",80); - // Test that the "right turn only" restriction at the junction is taken into account + //Test that the distance of the computed route. given() .header("Accept", "application/json") .header("Content-Type", "application/json") diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java index d8dcc86cca..e4753cd2c0 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java @@ -46,7 +46,7 @@ public RouteRequestHandler() { this.errorCodes.put("UNKNOWN_PARAMETER", RoutingErrorCodes.UNKNOWN_PARAMETER); } - public RouteResult[] generateRouteFromRequest(RouteRequest request) throws StatusCodeException{ + public RouteResult[] generateRouteFromRequest(RouteRequest request) throws StatusCodeException { RoutingRequest routingRequest = convertRouteRequest(request); try { @@ -58,7 +58,7 @@ public RouteResult[] generateRouteFromRequest(RouteRequest request) throws Statu } } - public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCodeException { + public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCodeException { RoutingRequest routingRequest = new RoutingRequest(); boolean isRoundTrip = request.hasRouteOptions() && request.getRouteOptions().hasRoundTripOptions(); routingRequest.setCoordinates(convertCoordinates(request.getCoordinates(), isRoundTrip)); @@ -85,9 +85,9 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo if (request.hasAttributes()) routingRequest.setAttributes(convertAttributes(request.getAttributes())); - if (request.hasExtraInfo()){ + if (request.hasExtraInfo()) { routingRequest.setExtraInfo(convertExtraInfo(request.getExtraInfo())); - for (APIEnums.ExtraInfo extra: request.getExtraInfo()) { + for (APIEnums.ExtraInfo extra : request.getExtraInfo()) { if (extra.compareTo(APIEnums.ExtraInfo.COUNTRY_INFO) == 0) { routingRequest.setIncludeCountryInfo(true); } @@ -113,10 +113,10 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo routingRequest.setSkipSegments(processSkipSegments(request)); } - if(request.hasId()) + if (request.hasId()) routingRequest.setId(request.getId()); - if(request.hasUserSpeed()){ + if (request.hasUserSpeed()) { routingRequest.setUserSpeed(convertUserSpeed(request.getUserSpeed())); } @@ -144,18 +144,18 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo if (request.hasRoutePreference()) params.setWeightingMethod(convertWeightingMethod(request.getRoutePreference())); - if(request.hasBearings()) + if (request.hasBearings()) params.setBearings(convertBearings(request.getBearings(), coordinatesLength)); - if(request.hasMaximumSearchRadii()) + if (request.hasMaximumSearchRadii()) params.setMaximumRadiuses(convertMaxRadii(request.getMaximumSearchRadii(), coordinatesLength, profileType)); - if(request.hasUseContractionHierarchies()) { + if (request.hasUseContractionHierarchies()) { params.setFlexibleMode(convertSetFlexibleMode(request.getUseContractionHierarchies())); params.setOptimized(request.getUseContractionHierarchies()); } - if(request.hasRouteOptions()) { + if (request.hasRouteOptions()) { params = processRouteRequestOptions(request, params); } @@ -178,7 +178,7 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo params.setAlternativeRoutesShareFactor(alternativeRoutes.getShareFactor()); } - if(request.hasUserSpeed()){ + if (request.hasUserSpeed()) { params.setUserSpeed(convertUserSpeed(request.getUserSpeed())); } @@ -191,7 +191,7 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo private List processSkipSegments(RouteRequest request) throws ParameterOutOfRangeException, ParameterValueException, EmptyElementException { List skipSegments = request.getSkipSegments(); - for (Integer skipSegment: skipSegments){ + for (Integer skipSegment : skipSegments) { if (skipSegment >= request.getCoordinates().size()) { throw new ParameterOutOfRangeException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequest.PARAM_SKIP_SEGMENTS, skipSegment.toString(), String.valueOf(request.getCoordinates().size() - 1)); } @@ -211,7 +211,7 @@ private List processSkipSegments(RouteRequest request) throws Parameter private RouteSearchParameters processRouteRequestOptions(RouteRequest request, RouteSearchParameters params) throws StatusCodeException { RouteRequestOptions routeOptions = request.getRouteOptions(); - params = processRequestOptions(routeOptions,params); + params = processRequestOptions(routeOptions, params); if (routeOptions.hasProfileParams()) params.setProfileParams(convertParameters(routeOptions, params.getProfileType())); return params; @@ -251,9 +251,9 @@ public RouteSearchParameters processRequestOptions(RouteRequestOptions options, return params; } - private boolean convertIncludeGeometry(RouteRequest request) throws IncompatibleParameterException { + private boolean convertIncludeGeometry(RouteRequest request) throws IncompatibleParameterException { boolean includeGeometry = request.getIncludeGeometry(); - if(!includeGeometry && request.getResponseType() != APIEnums.RouteResponseType.JSON) { + if (!includeGeometry && request.getResponseType() != APIEnums.RouteResponseType.JSON) { throw new IncompatibleParameterException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequest.PARAM_GEOMETRY, "false", RouteRequest.PARAM_FORMAT, APIEnums.RouteResponseType.GEOJSON + "/" + APIEnums.RouteResponseType.GPX); @@ -261,8 +261,8 @@ private boolean convertIncludeGeometry(RouteRequest request) throws Incompatibl return includeGeometry; } - private String convertGeometryFormat(APIEnums.RouteResponseType responseType) throws ParameterValueException { - switch(responseType) { + private String convertGeometryFormat(APIEnums.RouteResponseType responseType) throws ParameterValueException { + switch (responseType) { case GEOJSON: return "geojson"; case JSON: @@ -274,8 +274,8 @@ private String convertGeometryFormat(APIEnums.RouteResponseType responseType) t } } - private Coordinate[] convertCoordinates(List> coordinates, boolean allowSingleCoordinate) throws ParameterValueException { - if(!allowSingleCoordinate && coordinates.size() < 2) + private Coordinate[] convertCoordinates(List> coordinates, boolean allowSingleCoordinate) throws ParameterValueException { + if (!allowSingleCoordinate && coordinates.size() < 2) throw new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequest.PARAM_COORDINATES); if (allowSingleCoordinate && coordinates.size() > 1) @@ -287,15 +287,15 @@ private Coordinate[] convertCoordinates(List> coordinates, boolean ArrayList coords = new ArrayList<>(); - for(List coord : coordinates) { + for (List coord : coordinates) { coords.add(convertSingleCoordinate(coord)); } return coords.toArray(new Coordinate[coords.size()]); } - private Coordinate convertSingleCoordinate(List coordinate) throws ParameterValueException { - if(coordinate.size() != 2) + private Coordinate convertSingleCoordinate(List coordinate) throws ParameterValueException { + if (coordinate.size() != 2) throw new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequest.PARAM_COORDINATES); return new Coordinate(coordinate.get(0), coordinate.get(1)); @@ -304,10 +304,10 @@ private Coordinate convertSingleCoordinate(List coordinate) throws Para @Override protected int convertFeatureTypes(APIEnums.AvoidFeatures[] avoidFeatures, int profileType) throws UnknownParameterValueException, IncompatibleParameterException { int flags = 0; - for(APIEnums.AvoidFeatures avoid : avoidFeatures) { + for (APIEnums.AvoidFeatures avoid : avoidFeatures) { String avoidFeatureName = avoid.toString(); int flag = AvoidFeatureFlags.getFromString(avoidFeatureName); - if(flag == 0) + if (flag == 0) throw new UnknownParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequestOptions.PARAM_AVOID_FEATURES, avoidFeatureName); if (!AvoidFeatureFlags.isValid(profileType, flag)) @@ -320,13 +320,13 @@ protected int convertFeatureTypes(APIEnums.AvoidFeatures[] avoidFeatures, int pr } @Override - public int convertRouteProfileType(APIEnums.Profile profile) { + public int convertRouteProfileType(APIEnums.Profile profile) { return RoutingProfileType.getFromString(profile.toString()); } @Override protected BordersExtractor.Avoid convertAvoidBorders(APIEnums.AvoidBorders avoidBorders) { - if(avoidBorders != null) { + if (avoidBorders != null) { switch (avoidBorders) { case ALL: return BordersExtractor.Avoid.ALL; @@ -392,20 +392,20 @@ protected Polygon[] convertAvoidAreas(JSONObject geoJson, int profileType) throw return avoidAreas; } - private WayPointBearing[] convertBearings(Double[][] bearingsIn, int coordinatesLength) throws ParameterValueException { - if(bearingsIn == null || bearingsIn.length == 0) + private WayPointBearing[] convertBearings(Double[][] bearingsIn, int coordinatesLength) throws ParameterValueException { + if (bearingsIn == null || bearingsIn.length == 0) return new WayPointBearing[0]; - if(bearingsIn.length != coordinatesLength && bearingsIn.length != coordinatesLength-1) + if (bearingsIn.length != coordinatesLength && bearingsIn.length != coordinatesLength - 1) throw new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequest.PARAM_BEARINGS, Arrays.toString(bearingsIn), "The number of bearings must be equal to the number of waypoints on the route."); WayPointBearing[] bearings = new WayPointBearing[coordinatesLength]; - for(int i=0; i maxSpeed) || (edge.getReverse(flagEncoder.getAverageSpeedEnc())) > maxSpeed ) { //If the max speed of the road is greater than that of the limit include it in the core. + if ( (edge.get(flagEncoder.getAverageSpeedEnc()) > maxSpeed) || (edge.getReverse(flagEncoder.getAverageSpeedEnc())) > maxSpeed ) { + //If the max speed of the road is greater than that of the limit include it in the core. return false; } else { return true; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 1a6c04db69..5b0e34900c 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -19,6 +19,7 @@ import com.graphhopper.routing.weighting.Weighting; import com.graphhopper.util.EdgeIteratorState; import com.graphhopper.util.Parameters.Routing; +import org.heigit.ors.config.AppConfig; /** * This class creates the weighting for the routing according to the maximum speed set by user. @@ -27,28 +28,31 @@ */ public class MaximumSpeedWeighting implements Weighting { - protected final static double SPEED_CONV = 3.6; //From km/h to m/s. + protected final static double SPEED_UNIT_CONVERTER = 3.6; //From km/h to m/s. private final double headingPenalty; private final double userMaxSpeed; private final Weighting superWeighting; private final DecimalEncodedValue avSpeedEnc; private boolean calculateWeight; + private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) != null) + ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) + : 80; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighting weighting) { this.avSpeedEnc = flagEncoder.getAverageSpeedEnc(); this.superWeighting = weighting; - if(hintsMap.getDouble("user_speed",80) < 80 ){ - throw new RuntimeException("User speed should be <= 80."); + if(hintsMap.getDouble("user_speed",maxSpeed) < maxSpeed ){ + throw new RuntimeException("User speed should be <=" + maxSpeed); } this.headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); - this.userMaxSpeed = hintsMap.getDouble("user_speed",80); + this.userMaxSpeed = hintsMap.getDouble("user_speed",maxSpeed); this.calculateWeight = (hintsMap.getWeighting() == "fastest"); } /** This function computes the weight when the speed of the edge is greater than the user speed */ private double calcMaximumSpeedWeight(double speed, EdgeIteratorState edge){ //Conversion of the speeds to times including the factor for changing from km/h -> m/s. - double time = edge.getDistance() / speed * SPEED_CONV; + double time = edge.getDistance() / speed * SPEED_UNIT_CONVERTER; // add direction penalties at start/stop/via points boolean unfavoredEdge = edge.get(EdgeIteratorState.UNFAVORED_EDGE); @@ -61,7 +65,7 @@ private double calcMaximumSpeedWeight(double speed, EdgeIteratorState edge){ /** This function is going to add the difference of: (edge speed - maximum_speed) in the calcMillis. */ private double calcMaximumSpeedMillis(double userMaxSpeed, double speed, EdgeIteratorState edge){ //Conversion of the speeds to times including the factor for changing from km/h -> m/ms. - double time = Math.abs((edge.getDistance() * ( 1 / speed - 1 / userMaxSpeed ))) * SPEED_CONV * 1000; + double time = Math.abs((edge.getDistance() * ( 1 / speed - 1 / userMaxSpeed ))) * SPEED_UNIT_CONVERTER * 1000; return time; } @@ -71,7 +75,7 @@ public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNext if (calculateWeight) { double speed = reverse ? edge.get(avSpeedEnc) : edge.getReverse(avSpeedEnc); if (speed > userMaxSpeed) - return calcMaximumSpeedWeight(userMaxSpeed, edge);// Use the maximum speed defined } + return calcMaximumSpeedWeight(userMaxSpeed, edge); } return superWeighting.calcWeight(edge, reverse, prevOrNextEdgeId); @@ -83,7 +87,7 @@ public long calcMillis(EdgeIteratorState edge, boolean reverse, int prevOrNextEd if (speed > userMaxSpeed) { return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId) + (long) calcMaximumSpeedMillis(userMaxSpeed, speed, edge); } else { - return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId);// If the speed of the edge is zero or lower than the one defined by user we call the superWeighting calcWEight method. + return superWeighting.calcMillis(edge, reverse, prevOrNextEdgeId); } } From 4308af57eddb8697172e964617016065073b3f7a Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Thu, 4 Jun 2020 13:18:33 +0200 Subject: [PATCH 27/38] More reviews. --- CHANGELOG.md | 3 +- PULL_REQUEST_TEMPLATE.md | 2 +- .../ors/v2/services/routing/ResultTest.java | 3 +- openrouteservice/.gitignore | 41 ++++++------------- .../api/requests/routing/RouteRequest.java | 22 +++++----- .../requests/routing/RouteRequestHandler.java | 18 ++++---- .../ors/routing/RouteSearchParameters.java | 20 ++++----- .../heigit/ors/routing/RoutingProfile.java | 4 +- .../heigit/ors/routing/RoutingRequest.java | 6 +-- .../extensions/ORSGraphHopper.java | 12 +++--- .../extensions/ORSWeightingFactory.java | 3 -- .../core/MaximumSpeedCoreEdgeFilter.java | 16 ++++---- .../weighting/MaximumSpeedWeighting.java | 6 +-- .../src/main/resources/app.config.sample | 2 +- 14 files changed, 68 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 658d86c789..652b714163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added -* Added a Maximum Speed Core Edge Filter to include in the core edges with speed more than a value parsed from app.config. -* Added a Maximum Speed Weighting to perform routing using a user defined maximum speed as a parameter. +* New `maximum_speed` parameter to the driving profiles of the directions API to specify speed limit above a certain threshold set in the config file. ### Fixed ### Changed diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index b4c9966c42..3d2b61a738 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -17,7 +17,7 @@ Fixes # . ### Information about the changes - Key functionality added: -- Reason for change: C +- Reason for change: ### Examples and reasons for differences between live ORS routes and those generated from this pull request - 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 de9cd508b9..e5e2c6bcf9 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 @@ -1223,11 +1223,10 @@ public void testOptimizedAndTurnRestrictions() { } @Test - public void testMaximumSpeedWeighting() { + public void testMaximumSpeed() { JSONObject body = new JSONObject(); body.put("coordinates", constructCoords("8.63348,49.41766|8.6441,49.4672")); body.put("preference", getParameter("preference")); - body.put("instructions", true); body.put("user_speed",80); //Test that the distance of the computed route. diff --git a/openrouteservice/.gitignore b/openrouteservice/.gitignore index cab81d97f6..9c6d0ab7e3 100644 --- a/openrouteservice/.gitignore +++ b/openrouteservice/.gitignore @@ -1,30 +1,13 @@ - -.metadata/ - -.recommenders/ -.recommenders/caches/identified-project-coordinates.json -openrouteservice/Program FilesApache Software FoundationTomcat 7.0webappsopenrouteservice-0.0.1-SNAPSHOTWEB-INFlogsCounter_RS.csv -.recommenders/caches/manual-mappings.json -.recommenders/index/http___download_eclipse_org_recommenders_models_neon_/segments.gen -.idea/ -*.iml -.DS_Store -nohup.out -.python-version - -.project - -# Ignore all app.config files except for the .sample one -openrouteservice/WebContent/WEB-INF/app.config* -!openrouteservice/WebContent/WEB-INF/app.config.sample -openrouteservice/src/main/resources/app.config* -!openrouteservice/src/main/resources/app.config.sample - -app.config.local -cgiar_provider/ -graphs/ target/ -.python-version -nohup.out -build/ -cgiar_cache/ \ No newline at end of file +*~ +TODO.txt +.settings/ +.classpath +.project +#/WebContent/WEB-INF/app.config +*.iws +*.ipr +cgiar-cache +srtm_38_03.zip +logs/ +.attach_* \ No newline at end of file diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java index b8e06ea912..383e602ca0 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java @@ -57,7 +57,7 @@ public class RouteRequest { public static final String PARAM_SIMPLIFY_GEOMETRY = "geometry_simplify"; public static final String PARAM_SKIP_SEGMENTS = "skip_segments"; public static final String PARAM_ALTERNATIVE_ROUTES = "alternative_routes"; - public static final String PARAM_USER_SPEED = "user_speed"; + public static final String PARAM_MAXIMUM_SPEED = "maximum_speed"; @ApiModelProperty(name = PARAM_ID, value = "Arbitrary identification string of the request reflected in the meta information.", @@ -247,11 +247,11 @@ public class RouteRequest { @JsonIgnore private boolean hasAlternativeRoutes = false; - @ApiModelProperty(name = PARAM_USER_SPEED, value = "The maximum speed specified by user.", example = "90") - @JsonProperty(PARAM_USER_SPEED) - private double userSpeed; + @ApiModelProperty(name = PARAM_MAXIMUM_SPEED, value = "The maximum speed specified by user.", example = "90") + @JsonProperty(PARAM_MAXIMUM_SPEED) + private double maximumSpeed; @JsonIgnore - private boolean hasUserSpeed = false; + private boolean hasMaximumSpeed = false; @JsonCreator public RouteRequest(@JsonProperty(value = PARAM_COORDINATES, required = true) List> coordinates) { @@ -511,13 +511,13 @@ public void setAlternativeRoutes(RouteRequestAlternativeRoutes alternativeRoutes hasAlternativeRoutes = true; } - public void setUserSpeed(Double userSpeed) { - this.userSpeed = userSpeed; - hasUserSpeed = true; + public void setMaximumSpeed(Double maximumSpeed) { + this.maximumSpeed = maximumSpeed; + hasMaximumSpeed = true; } - public double getUserSpeed() { - return userSpeed; + public double getMaximumSpeed() { + return maximumSpeed; } public boolean hasIncludeRoundaboutExitInfo() { @@ -592,5 +592,5 @@ public boolean hasSimplifyGeometry() { public boolean hasAlternativeRoutes() { return hasAlternativeRoutes; } - public boolean hasUserSpeed() { return hasUserSpeed; } + public boolean hasMaximumSpeed() { return hasMaximumSpeed; } } diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java index e4753cd2c0..36b41372f3 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java @@ -116,8 +116,8 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCod if (request.hasId()) routingRequest.setId(request.getId()); - if (request.hasUserSpeed()) { - routingRequest.setUserSpeed(convertUserSpeed(request.getUserSpeed())); + if (request.hasMaximumSpeed()) { + routingRequest.setMaximumSpeed(validateMaximumSpeed(request.getMaximumSpeed())); } int profileType = -1; @@ -178,8 +178,8 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCod params.setAlternativeRoutesShareFactor(alternativeRoutes.getShareFactor()); } - if (request.hasUserSpeed()) { - params.setUserSpeed(convertUserSpeed(request.getUserSpeed())); + if (request.hasMaximumSpeed()) { + params.setMaximumSpeed(validateMaximumSpeed(request.getMaximumSpeed())); } params.setConsiderTurnRestrictions(false); @@ -513,10 +513,12 @@ private int[] convertAvoidCountries(String[] avoidCountries) throws ParameterVal return avoidCountryIds; } - private double convertUserSpeed(Double userSpeed) throws ParameterValueException { - double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params", "maximum_speed")) != null) ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params", "maximum_speed")) : 80; //Minimum speed of the core. - if (userSpeed < maxSpeed) { - throw new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequest.PARAM_USER_SPEED); + private double validateMaximumSpeed(Double userSpeed) throws ParameterValueException { + double maximumSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params", "maximum_speed_lower_bound")) != null) + ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params", "maximum_speed_lower_bound")) + : 80; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. + if (userSpeed < maximumSpeed) { + throw new RuntimeException("The maximum speed must not be lower than" + maximumSpeed + "km/h."); } return userSpeed; } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java index d53847f5ca..2f0c549ca2 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RouteSearchParameters.java @@ -81,8 +81,8 @@ public class RouteSearchParameters { private int roundTripPoints = 2; private long roundTripSeed = -1; - private double userSpeed; - private boolean hasUserSpeed = false; + private double maximumSpeed; + private boolean hasMaximumSpeed = false; private String options; @@ -530,17 +530,17 @@ public long getRoundTripSeed() { return roundTripSeed; } - public double getUserSpeed() { - return userSpeed; + public double getMaximumSpeed() { + return maximumSpeed; } - public void setUserSpeed(double userSpeed) { - this.userSpeed = userSpeed; - hasUserSpeed = true; + public void setMaximumSpeed(double maximumSpeed) { + this.maximumSpeed = maximumSpeed; + hasMaximumSpeed = true; } - public boolean hasUserSpeed() { - return hasUserSpeed; + public boolean hasMaximumSpeed() { + return hasMaximumSpeed; } public boolean isProfileTypeDriving() { @@ -559,7 +559,7 @@ public boolean requiresDynamicPreprocessedWeights() { || getConsiderTurnRestrictions() || isProfileTypeHeavyVehicle() && getVehicleType() > 0 || isProfileTypeDriving() && hasParameters(VehicleParameters.class) - || hasUserSpeed(); + || hasMaximumSpeed(); } /** 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 ae0c9d4e79..05ee4aaa0b 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -887,8 +887,8 @@ else if (bearings[1] == null) req.getHints().put("alternative_route.max_share_factor", searchParams.getAlternativeRoutesShareFactor()); } - if(searchParams.hasUserSpeed()){ - req.getHints().put("user_speed", searchParams.getUserSpeed()); + if(searchParams.hasMaximumSpeed()){ + req.getHints().put("user_speed", searchParams.getMaximumSpeed()); } if (directedSegment) { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java index efcd135418..58b6e979ec 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java @@ -43,7 +43,7 @@ public class RoutingRequest extends ServiceRequest { private boolean continueStraight = false; private List skipSegments = new ArrayList<>(); private boolean includeCountryInfo = false; - private double userSpeed; + private double maximumSpeed; private String responseFormat = "json"; @@ -212,9 +212,9 @@ public void setIncludeCountryInfo(boolean includeCountryInfo) { this.includeCountryInfo = includeCountryInfo; } - public void setUserSpeed(double userSpeed){this.userSpeed = userSpeed;} + public void setMaximumSpeed(double maximumSpeed){this.maximumSpeed = maximumSpeed;} - public double getUserSpeed(){return userSpeed;} + public double getMaximumSpeed(){return maximumSpeed;} public void setResponseFormat(String responseFormat) { if (!Helper.isEmpty(responseFormat)) { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index 569fcd17f3..49bdd693f7 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -533,13 +533,13 @@ public void postProcessing() { } /* Maximum Speed Filter */ - if (routingProfileCategory !=0 & encodingManager.hasEncoder("heavyvehicle")) { - FlagEncoder flagEncoder=getEncodingManager().getEncoder("heavyvehicle"); // Set encoder only for heavy vehicles. - coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder)); - } + if (routingProfileCategory !=0 & (encodingManager.hasEncoder("heavyvehicle") || encodingManager.hasEncoder("car-ors")) ) { + FlagEncoder flagEncoder = null; + if(encodingManager.hasEncoder("heavyvehicle")) + flagEncoder = getEncodingManager().getEncoder("heavyvehicle"); + else if(encodingManager.hasEncoder("car-ors")) + flagEncoder = getEncodingManager().getEncoder("car-ors"); - if (routingProfileCategory !=0 & encodingManager.hasEncoder("car-ors") ){ - FlagEncoder flagEncoder=getEncodingManager().getEncoder("car-ors"); // Set encoder only for cars. coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder)); } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java index 191cefe08b..bc39d464a9 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSWeightingFactory.java @@ -18,13 +18,10 @@ import com.graphhopper.routing.util.HintsMap; import com.graphhopper.routing.util.TraversalMode; import com.graphhopper.routing.weighting.*; -import com.graphhopper.storage.Graph; import com.graphhopper.storage.GraphHopperStorage; import com.graphhopper.storage.TurnCostExtension; -import com.graphhopper.storage.index.LocationIndex; import com.graphhopper.util.Helper; import com.graphhopper.util.PMap; -import org.heigit.ors.routing.graphhopper.extensions.weighting.MaximumSpeedWeighting; import com.graphhopper.util.Parameters; import org.heigit.ors.routing.ProfileWeighting; import org.heigit.ors.routing.graphhopper.extensions.flagencoders.FlagEncoderNames; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index 57537f32ce..088296993d 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -13,14 +13,11 @@ */ package org.heigit.ors.routing.graphhopper.extensions.edgefilters.core; +import com.graphhopper.routing.profiles.DecimalEncodedValue; import com.graphhopper.routing.util.EdgeFilter; -import com.graphhopper.storage.GraphHopperStorage; -import com.graphhopper.storage.GraphStorage; import com.graphhopper.util.EdgeIteratorState; import com.graphhopper.routing.util.FlagEncoder; import org.heigit.ors.config.AppConfig; -import org.heigit.ors.routing.graphhopper.extensions.storages.GraphStorageUtils; -import org.heigit.ors.routing.graphhopper.extensions.storages.HeavyVehicleAttributesGraphStorage; /** * This class includes in the core all edges with speed more than the one set in the app.config file max_speed. @@ -29,18 +26,19 @@ */ public class MaximumSpeedCoreEdgeFilter implements EdgeFilter { - private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) != null) - ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) + private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) != null) + ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) : 80; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. - public final FlagEncoder flagEncoder; + + private final DecimalEncodedValue avSpeedEnc; public MaximumSpeedCoreEdgeFilter(FlagEncoder flagEncoder) { - this.flagEncoder = flagEncoder; + this.avSpeedEnc = flagEncoder.getAverageSpeedEnc(); } @Override public boolean accept(EdgeIteratorState edge) { - if ( (edge.get(flagEncoder.getAverageSpeedEnc()) > maxSpeed) || (edge.getReverse(flagEncoder.getAverageSpeedEnc())) > maxSpeed ) { + if ( (edge.get(avSpeedEnc) > maxSpeed) || (edge.getReverse(avSpeedEnc)) > maxSpeed ) { //If the max speed of the road is greater than that of the limit include it in the core. return false; } else { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 5b0e34900c..5eca02e767 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -34,8 +34,8 @@ public class MaximumSpeedWeighting implements Weighting { private final Weighting superWeighting; private final DecimalEncodedValue avSpeedEnc; private boolean calculateWeight; - private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) != null) - ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed")) + private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) != null) + ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) : 80; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighting weighting) { @@ -49,7 +49,7 @@ public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighti this.calculateWeight = (hintsMap.getWeighting() == "fastest"); } - /** This function computes the weight when the speed of the edge is greater than the user speed */ + /** This function returns the time needed for a route only if the speed of the edge is bigger than the speed set by the user */ private double calcMaximumSpeedWeight(double speed, EdgeIteratorState edge){ //Conversion of the speeds to times including the factor for changing from km/h -> m/s. double time = edge.getDistance() / speed * SPEED_UNIT_CONVERTER; diff --git a/openrouteservice/src/main/resources/app.config.sample b/openrouteservice/src/main/resources/app.config.sample index 0381d10ca6..74fb193875 100644 --- a/openrouteservice/src/main/resources/app.config.sample +++ b/openrouteservice/src/main/resources/app.config.sample @@ -68,7 +68,7 @@ "maximum_distance_alternative_routes": 100000, "maximum_alternative_routes": 3, "maximum_distance_round_trip_routes": 100000, - "maximum_speed": 80, + "maximum_speed_lower_bound": 80, "preparation": { "min_network_size": 200, "min_one_way_network_size": 200, From 5d559723fcc5c9dbe58af5e4a9eb6803ad2d438f Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:03:23 +0200 Subject: [PATCH 28/38] More reviews. --- CHANGELOG.md | 2 +- .../src/main/java/org/heigit/ors/routing/RoutingProfile.java | 2 +- .../src/main/java/org/heigit/ors/routing/RoutingRequest.java | 4 +++- .../extensions/weighting/MaximumSpeedWeighting.java | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 652b714163..333d840cf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added -* New `maximum_speed` parameter to the driving profiles of the directions API to specify speed limit above a certain threshold set in the config file. +* New `maximum_speed` parameter to the driving profiles of the directions API, for specifying a speed limit, above a certain threshold set in the config file. ### Fixed ### Changed 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 05ee4aaa0b..38b681cb0b 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -888,7 +888,7 @@ else if (bearings[1] == null) } if(searchParams.hasMaximumSpeed()){ - req.getHints().put("user_speed", searchParams.getMaximumSpeed()); + req.getHints().put("maximum_speed", searchParams.getMaximumSpeed()); } if (directedSegment) { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java index 58b6e979ec..3cfa4c06d8 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java @@ -212,7 +212,9 @@ public void setIncludeCountryInfo(boolean includeCountryInfo) { this.includeCountryInfo = includeCountryInfo; } - public void setMaximumSpeed(double maximumSpeed){this.maximumSpeed = maximumSpeed;} + public void setMaximumSpeed(double maximumSpeed){ + this.maximumSpeed = maximumSpeed; + } public double getMaximumSpeed(){return maximumSpeed;} diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 5eca02e767..3e5f8975db 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -46,7 +46,7 @@ public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighti } this.headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); this.userMaxSpeed = hintsMap.getDouble("user_speed",maxSpeed); - this.calculateWeight = (hintsMap.getWeighting() == "fastest"); + this.calculateWeight = (superWeighting.getName() == "fastest"); } /** This function returns the time needed for a route only if the speed of the edge is bigger than the speed set by the user */ From 2923f360f37e2332948b06d178bd7533e081be15 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Fri, 5 Jun 2020 18:12:38 +0200 Subject: [PATCH 29/38] Even more reviews. --- openrouteservice/pom.xml | 4 ++-- .../ors/api/requests/routing/RouteRequest.java | 4 +++- .../api/requests/routing/RouteRequestHandler.java | 15 ++------------- .../heigit/ors/routing/RoutingProfileManager.java | 4 ++++ .../org/heigit/ors/routing/RoutingRequest.java | 6 ++++-- .../configuration/RouteProfileConfiguration.java | 10 ++++++++++ .../extensions/GraphProcessContext.java | 7 +++++++ .../graphhopper/extensions/ORSGraphHopper.java | 11 ++++++++--- .../core/MaximumSpeedCoreEdgeFilter.java | 6 ++++-- .../weighting/MaximumSpeedWeighting.java | 6 ++++-- 10 files changed, 48 insertions(+), 25 deletions(-) diff --git a/openrouteservice/pom.xml b/openrouteservice/pom.xml index 17fdc84d07..a4bb9ea246 100644 --- a/openrouteservice/pom.xml +++ b/openrouteservice/pom.xml @@ -281,6 +281,7 @@ 3.0.3 + com.graphhopper graphhopper-core @@ -317,7 +318,6 @@ graphhopper-reader-osm 0.13-SNAPSHOT - --> com.typesafe diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java index 383e602ca0..f0ff257dcb 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java @@ -592,5 +592,7 @@ public boolean hasSimplifyGeometry() { public boolean hasAlternativeRoutes() { return hasAlternativeRoutes; } - public boolean hasMaximumSpeed() { return hasMaximumSpeed; } + public boolean hasMaximumSpeed() { + return hasMaximumSpeed; + } } diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java index 36b41372f3..f4b6aa557a 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequestHandler.java @@ -117,7 +117,7 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCod routingRequest.setId(request.getId()); if (request.hasMaximumSpeed()) { - routingRequest.setMaximumSpeed(validateMaximumSpeed(request.getMaximumSpeed())); + routingRequest.setMaximumSpeed(request.getMaximumSpeed()); } int profileType = -1; @@ -179,7 +179,7 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCod } if (request.hasMaximumSpeed()) { - params.setMaximumSpeed(validateMaximumSpeed(request.getMaximumSpeed())); + params.setMaximumSpeed(request.getMaximumSpeed()); } params.setConsiderTurnRestrictions(false); @@ -512,15 +512,4 @@ private int[] convertAvoidCountries(String[] avoidCountries) throws ParameterVal return avoidCountryIds; } - - private double validateMaximumSpeed(Double userSpeed) throws ParameterValueException { - double maximumSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params", "maximum_speed_lower_bound")) != null) - ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params", "maximum_speed_lower_bound")) - : 80; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. - if (userSpeed < maximumSpeed) { - throw new RuntimeException("The maximum speed must not be lower than" + maximumSpeed + "km/h."); - } - return userSpeed; - } - } \ No newline at end of file diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java index 4087c497ab..c9d211a19f 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java @@ -576,6 +576,10 @@ public RoutingProfile getRouteProfile(RoutingRequest req, boolean oneToMany) thr } } + if(searchParams.getMaximumSpeed() !=0 & searchParams.getMaximumSpeed() < config.getMaximumSpeedLowerBound()){ + throw new RuntimeException("The maximum speed must not be lower than " + config.getMaximumSpeedLowerBound() + " km/h."); + } + return rp; } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java index 3cfa4c06d8..ae7a85aa05 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java @@ -208,7 +208,7 @@ public boolean getIncludeCountryInfo() { return includeCountryInfo; } - public void setIncludeCountryInfo(boolean includeCountryInfo) { + public void setIncludeCountryInfo(boolean includeCountryImnfo) { this.includeCountryInfo = includeCountryInfo; } @@ -216,7 +216,9 @@ public void setMaximumSpeed(double maximumSpeed){ this.maximumSpeed = maximumSpeed; } - public double getMaximumSpeed(){return maximumSpeed;} + public double getMaximumSpeed(){ + return maximumSpeed; + } public void setResponseFormat(String responseFormat) { if (!Helper.isEmpty(responseFormat)) { 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 8bab9b65d8..c1a9217aec 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 @@ -56,6 +56,8 @@ public class RouteProfileConfiguration { private int locationIndexResolution = 500; private int locationIndexSearchIterations = 4; + private double maximumSpeedLowerBound = 80; + public RouteProfileConfiguration() { extStorages = new HashMap<>(); graphBuilders = new HashMap<>(); @@ -356,4 +358,12 @@ public int getLocationIndexSearchIterations() { public void setLocationIndexSearchIterations(int locationIndexSearchIterations) { this.locationIndexSearchIterations = locationIndexSearchIterations; } + + public void setMaximumSpeedLowerBound(double maximumSpeedLowerBound){ + this.maximumSpeedLowerBound = maximumSpeedLowerBound; + } + + public double getMaximumSpeedLowerBound(){ + return maximumSpeedLowerBound; + } } \ No newline at end of file diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/GraphProcessContext.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/GraphProcessContext.java index 487b1ea0ef..0afa886919 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/GraphProcessContext.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/GraphProcessContext.java @@ -37,6 +37,7 @@ public class GraphProcessContext { private GraphBuilder[] arrGraphBuilders; private List storageBuilders; private GraphStorageBuilder[] arrStorageBuilders; + private double maximumSpeedLowerBound; public GraphProcessContext(RouteProfileConfiguration config) throws Exception { bbox = config.getExtent(); @@ -59,6 +60,8 @@ public GraphProcessContext(RouteProfileConfiguration config) throws Exception { arrGraphBuilders = graphBuilders.toArray(arrGraphBuilders); } } + + maximumSpeedLowerBound = config.getMaximumSpeedLowerBound(); } public void init(GraphHopper gh) { @@ -208,4 +211,8 @@ public void finish() { } } } + + public double getMaximumSpeedLowerBound(){ + return maximumSpeedLowerBound; + } } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index 49bdd693f7..a7035c2caf 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -78,6 +78,8 @@ public class ORSGraphHopper extends GraphHopper { private final CoreLMAlgoFactoryDecorator coreLMFactoryDecorator = new CoreLMAlgoFactoryDecorator(); + private double maximumSpeedLowerBound; + public ORSGraphHopper(GraphProcessContext procCntx) { processContext = procCntx; forDesktop(); @@ -87,6 +89,8 @@ public ORSGraphHopper(GraphProcessContext procCntx) { algoDecorators.add(getCHFactoryDecorator()); algoDecorators.add(getLMFactoryDecorator()); processContext.init(this); + maximumSpeedLowerBound = procCntx.getMaximumSpeedLowerBound(); + } @@ -99,6 +103,7 @@ public GraphHopper init(CmdArgs args) { GraphHopper ret = super.init(args); minNetworkSize = args.getInt("prepare.min_network_size", minNetworkSize); minOneWayNetworkSize = args.getInt("prepare.min_one_way_network_size", minOneWayNetworkSize); + return ret; } @@ -327,7 +332,7 @@ else if (ALT_ROUTE.equalsIgnoreCase(algoStr)) if(hints.has("user_speed")) { - weighting = new MaximumSpeedWeighting(encoder, hints, weighting); + weighting = new MaximumSpeedWeighting(encoder, hints, weighting, maximumSpeedLowerBound); } @@ -533,14 +538,14 @@ public void postProcessing() { } /* Maximum Speed Filter */ - if (routingProfileCategory !=0 & (encodingManager.hasEncoder("heavyvehicle") || encodingManager.hasEncoder("car-ors")) ) { + if ((routingProfileCategory & RoutingProfileCategory.DRIVING) !=0 ) { FlagEncoder flagEncoder = null; if(encodingManager.hasEncoder("heavyvehicle")) flagEncoder = getEncodingManager().getEncoder("heavyvehicle"); else if(encodingManager.hasEncoder("car-ors")) flagEncoder = getEncodingManager().getEncoder("car-ors"); - coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder)); + coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, maximumSpeedLowerBound)); } /* End filter sequence initialization */ diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index 088296993d..9699e1d9de 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -26,13 +26,15 @@ */ public class MaximumSpeedCoreEdgeFilter implements EdgeFilter { + private double maximumSpeedLowerBound; private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) != null) ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) - : 80; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. + : maximumSpeedLowerBound; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. private final DecimalEncodedValue avSpeedEnc; - public MaximumSpeedCoreEdgeFilter(FlagEncoder flagEncoder) { + public MaximumSpeedCoreEdgeFilter(FlagEncoder flagEncoder, double maximumSpeedLowerBound) { + this.maximumSpeedLowerBound = maximumSpeedLowerBound; this.avSpeedEnc = flagEncoder.getAverageSpeedEnc(); } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 3e5f8975db..98fd8e3f8c 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -28,6 +28,7 @@ */ public class MaximumSpeedWeighting implements Weighting { + private double maximumSpeedLowerBound; protected final static double SPEED_UNIT_CONVERTER = 3.6; //From km/h to m/s. private final double headingPenalty; private final double userMaxSpeed; @@ -36,9 +37,10 @@ public class MaximumSpeedWeighting implements Weighting { private boolean calculateWeight; private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) != null) ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) - : 80; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. + : maximumSpeedLowerBound; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. - public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighting weighting) { + public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighting weighting, double maximumSpeedLowerBound) { + this.maximumSpeedLowerBound = maximumSpeedLowerBound; this.avSpeedEnc = flagEncoder.getAverageSpeedEnc(); this.superWeighting = weighting; if(hintsMap.getDouble("user_speed",maxSpeed) < maxSpeed ){ From 803ebfe5705e80352f494eba464400e52fe88b9b Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Fri, 5 Jun 2020 18:14:30 +0200 Subject: [PATCH 30/38] Revert pom.xml back to master form. --- openrouteservice/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openrouteservice/pom.xml b/openrouteservice/pom.xml index a4bb9ea246..17fdc84d07 100644 --- a/openrouteservice/pom.xml +++ b/openrouteservice/pom.xml @@ -281,7 +281,6 @@ 3.0.3 - + com.typesafe From e996df71d54234f5bc4ad28f9fe8156a93325ac8 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Fri, 5 Jun 2020 18:54:05 +0200 Subject: [PATCH 31/38] Fixed API test and some obsolete user_speed. --- .../java/org/heigit/ors/v2/services/routing/ResultTest.java | 2 +- .../ors/routing/graphhopper/extensions/ORSGraphHopper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 e5e2c6bcf9..79a4f32e0e 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 @@ -1227,7 +1227,7 @@ public void testMaximumSpeed() { JSONObject body = new JSONObject(); body.put("coordinates", constructCoords("8.63348,49.41766|8.6441,49.4672")); body.put("preference", getParameter("preference")); - body.put("user_speed",80); + body.put("maximum_speed",80); //Test that the distance of the computed route. given() diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index a7035c2caf..04c0291e0d 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -331,7 +331,7 @@ else if (ALT_ROUTE.equalsIgnoreCase(algoStr)) "The max_visited_nodes parameter has to be below or equal to:" + getMaxVisitedNodes()); - if(hints.has("user_speed")) { + if(hints.has("maximum_speed")) { weighting = new MaximumSpeedWeighting(encoder, hints, weighting, maximumSpeedLowerBound); } From f1e9dbb403362cdc9ae5b8104ccd901468402d07 Mon Sep 17 00:00:00 2001 From: aoles Date: Sat, 6 Jun 2020 23:01:38 +0200 Subject: [PATCH 32/38] Add tests checking the requirements of maximum speed feature --- .../conf/app.config.test | 1 + .../ors/v2/services/routing/ParamsTest.java | 59 +++++++++++++++++++ .../ors/v2/services/routing/ResultTest.java | 19 +++++- .../RouteProfileConfiguration.java | 2 + .../RoutingManagerConfiguration.java | 3 + 5 files changed, 82 insertions(+), 2 deletions(-) diff --git a/openrouteservice-api-tests/conf/app.config.test b/openrouteservice-api-tests/conf/app.config.test index 8f7b66a75e..890e4a3e4d 100644 --- a/openrouteservice-api-tests/conf/app.config.test +++ b/openrouteservice-api-tests/conf/app.config.test @@ -163,6 +163,7 @@ encoder_options: "turn_costs=true|block_fords=false|use_acceleration=true", maximum_distance: 100000, elevation: true, + maximum_speed_lower_bound: 75, preparation: { min_network_size: 200, diff --git a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ParamsTest.java b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ParamsTest.java index 60e4e03238..1d4387c2e7 100644 --- a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ParamsTest.java +++ b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ParamsTest.java @@ -1733,4 +1733,63 @@ public void expectRejectRoundTripWithoutLength() { .body("error.code", is(RoutingErrorCodes.MISSING_PARAMETER)) .statusCode(400); } + + private JSONArray constructCoords(String coordString) { + JSONArray coordinates = new JSONArray(); + String[] coordPairs = coordString.split("\\|"); + for (String pair : coordPairs) { + JSONArray coord = new JSONArray(); + String[] pairCoords = pair.split(","); + coord.put(Double.parseDouble(pairCoords[0])); + coord.put(Double.parseDouble(pairCoords[1])); + coordinates.put(coord); + } + + return coordinates; + } + + @Test + public void testMaximumSpeedLowerBound() { + JSONObject body = new JSONObject(); + body.put("coordinates", constructCoords("8.63348,49.41766|8.6441,49.4672")); + body.put("preference", getParameter("preference")); + body.put("maximum_speed", 75); + + //Test that the distance of the computed route. + given() + .header("Accept", "application/json") + .header("Content-Type", "application/json") + .pathParam("profile", "driving-car") + .body(body.toString()) + .when() + .post(getEndPointPath() + "/{profile}") + .then() + .assertThat() + .body("any { it.key == 'routes' }", is(false)) + .body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE)) + .statusCode(400); + } + + @Test + public void testMaximumSpeedUnsupportedProfile() { + JSONObject body = new JSONObject(); + body.put("coordinates", constructCoords("8.63348,49.41766|8.6441,49.4672")); + body.put("preference", getParameter("preference")); + body.put("maximum_speed", 80); + + //Test that the distance of the computed route. + given() + .header("Accept", "application/json") + .header("Content-Type", "application/json") + .pathParam("profile", "cycling-regular") + .body(body.toString()) + .when() + .post(getEndPointPath() + "/{profile}") + .then() + .assertThat() + .body("any { it.key == 'routes' }", is(false)) + .body("error.code", is(RoutingErrorCodes.INCOMPATIBLE_PARAMETERS)) + .statusCode(400); + } + } 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 79a4f32e0e..559a91dc9f 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 @@ -1227,9 +1227,9 @@ public void testMaximumSpeed() { JSONObject body = new JSONObject(); body.put("coordinates", constructCoords("8.63348,49.41766|8.6441,49.4672")); body.put("preference", getParameter("preference")); - body.put("maximum_speed",80); + body.put("maximum_speed", 80); - //Test that the distance of the computed route. + //Test against default maximum speed lower bound setting given() .header("Accept", "application/json") .header("Content-Type", "application/json") @@ -1242,6 +1242,21 @@ public void testMaximumSpeed() { .body("any { it.key == 'routes' }", is(true)) .body("routes[0].summary.duration", is(1694.8f)) .statusCode(200); + + //Test profile-specific maximum speed lower bound + body.put("maximum_speed", 75); + given() + .header("Accept", "application/json") + .header("Content-Type", "application/json") + .pathParam("profile", "driving-hgv") + .body(body.toString()) + .when() + .post(getEndPointPath() + "/{profile}") + .then() + .assertThat() + .body("any { it.key == 'routes' }", is(true)) + .body("routes[0].summary.duration", is(1986.6f)) + .statusCode(200); } @Test 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 c1a9217aec..6cbb0ecb47 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 @@ -93,6 +93,8 @@ public RouteProfileConfiguration(RouteProfileConfiguration rpc) { hasMaximumSnappingRadius = rpc.hasMaximumSnappingRadius; extent = rpc.extent; + + maximumSpeedLowerBound = rpc.maximumSpeedLowerBound; } public Integer[] getProfilesTypes() { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/configuration/RoutingManagerConfiguration.java b/openrouteservice/src/main/java/org/heigit/ors/routing/configuration/RoutingManagerConfiguration.java index 3bb80cc5fa..9a6963b9db 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/configuration/RoutingManagerConfiguration.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/configuration/RoutingManagerConfiguration.java @@ -190,6 +190,9 @@ else if (defaultParams != null) { case "location_index_search_iterations": profile.setLocationIndexSearchIterations(Integer.parseInt(paramItem.getValue().toString())); break; + case "maximum_speed_lower_bound": + profile.setMaximumSpeedLowerBound(Double.parseDouble(paramItem.getValue().toString())); + break; default: } } From 977c6a314ce519088adc5f3779a62c6b283de15c Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 17 Jun 2020 13:25:53 +0200 Subject: [PATCH 33/38] Fixed ReultsTest.testMaximumSpeed(), moved maximum_speed_lower_bound in profile specific parameter section, added error for use with unsupported profiles. --- openrouteservice-api-tests/conf/app.config.test | 1 + .../heigit/ors/v2/services/routing/ResultTest.java | 5 ++--- .../heigit/ors/routing/RoutingProfileManager.java | 14 ++++++++------ .../org/heigit/ors/routing/RoutingRequest.java | 2 +- .../graphhopper/extensions/ORSGraphHopper.java | 10 ++++++---- .../core/MaximumSpeedCoreEdgeFilter.java | 5 +---- .../weighting/MaximumSpeedWeighting.java | 10 +--------- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/openrouteservice-api-tests/conf/app.config.test b/openrouteservice-api-tests/conf/app.config.test index 890e4a3e4d..d34a7dd29b 100644 --- a/openrouteservice-api-tests/conf/app.config.test +++ b/openrouteservice-api-tests/conf/app.config.test @@ -91,6 +91,7 @@ encoder_options: "turn_costs=true|block_fords=false|maximum_grade_level=1|use_acceleration=true", maximum_distance: 100000, elevation: true, + maximum_speed_lower_bound: 75, preparation: { min_network_size: 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 559a91dc9f..c5aed4c37f 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 @@ -1240,7 +1240,7 @@ public void testMaximumSpeed() { .then() .assertThat() .body("any { it.key == 'routes' }", is(true)) - .body("routes[0].summary.duration", is(1694.8f)) + .body("routes[0].summary.duration", is(1736.6f)) .statusCode(200); //Test profile-specific maximum speed lower bound @@ -1253,8 +1253,7 @@ public void testMaximumSpeed() { .when() .post(getEndPointPath() + "/{profile}") .then() - .assertThat() - .body("any { it.key == 'routes' }", is(true)) + .assertThat().body("any { it.key == 'routes' }", is(true)) .body("routes[0].summary.duration", is(1986.6f)) .statusCode(200); } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java index c9d211a19f..e9a0c2e7b7 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java @@ -20,10 +20,7 @@ import com.vividsolutions.jts.geom.Coordinate; import org.apache.commons.lang.NotImplementedException; import org.apache.log4j.Logger; -import org.heigit.ors.exceptions.InternalServerException; -import org.heigit.ors.exceptions.PointNotFoundException; -import org.heigit.ors.exceptions.RouteNotFoundException; -import org.heigit.ors.exceptions.ServerLimitExceededException; +import org.heigit.ors.exceptions.*; import org.heigit.ors.isochrones.IsochroneMap; import org.heigit.ors.isochrones.IsochroneSearchParameters; import org.heigit.ors.mapmatching.MapMatchingRequest; @@ -576,8 +573,13 @@ public RoutingProfile getRouteProfile(RoutingRequest req, boolean oneToMany) thr } } - if(searchParams.getMaximumSpeed() !=0 & searchParams.getMaximumSpeed() < config.getMaximumSpeedLowerBound()){ - throw new RuntimeException("The maximum speed must not be lower than " + config.getMaximumSpeedLowerBound() + " km/h."); + if(searchParams.hasMaximumSpeed()){ + if(searchParams.getMaximumSpeed() < config.getMaximumSpeedLowerBound()) { + throw new ParameterValueException("The maximum speed must not be lower than " + config.getMaximumSpeedLowerBound() + " km/h."); + } + if(!(rp.getGraphhopper().getEncodingManager().hasEncoder("heavyvehicle") || rp.getGraphhopper().getEncodingManager().hasEncoder("car-ors")) ){ + throw new ParameterValueException("The maximum speed feature can only be used with cars and heavy vehicles."); + } } return rp; diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java index ae7a85aa05..3694057522 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingRequest.java @@ -208,7 +208,7 @@ public boolean getIncludeCountryInfo() { return includeCountryInfo; } - public void setIncludeCountryInfo(boolean includeCountryImnfo) { + public void setIncludeCountryInfo(boolean includeCountryInfo) { this.includeCountryInfo = includeCountryInfo; } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java index 04c0291e0d..a04b9b5619 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopper.java @@ -540,12 +540,14 @@ public void postProcessing() { /* Maximum Speed Filter */ if ((routingProfileCategory & RoutingProfileCategory.DRIVING) !=0 ) { FlagEncoder flagEncoder = null; - if(encodingManager.hasEncoder("heavyvehicle")) + if(encodingManager.hasEncoder("heavyvehicle")) { flagEncoder = getEncodingManager().getEncoder("heavyvehicle"); - else if(encodingManager.hasEncoder("car-ors")) + coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, maximumSpeedLowerBound)); + } + else if(encodingManager.hasEncoder("car-ors")) { flagEncoder = getEncodingManager().getEncoder("car-ors"); - - coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, maximumSpeedLowerBound)); + coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, maximumSpeedLowerBound)); + } } /* End filter sequence initialization */ diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java index 9699e1d9de..4786326550 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/core/MaximumSpeedCoreEdgeFilter.java @@ -27,9 +27,6 @@ public class MaximumSpeedCoreEdgeFilter implements EdgeFilter { private double maximumSpeedLowerBound; - private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) != null) - ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) - : maximumSpeedLowerBound; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. private final DecimalEncodedValue avSpeedEnc; @@ -40,7 +37,7 @@ public MaximumSpeedCoreEdgeFilter(FlagEncoder flagEncoder, double maximumSpeedLo @Override public boolean accept(EdgeIteratorState edge) { - if ( (edge.get(avSpeedEnc) > maxSpeed) || (edge.getReverse(avSpeedEnc)) > maxSpeed ) { + if ( (edge.get(avSpeedEnc) > maximumSpeedLowerBound) || (edge.getReverse(avSpeedEnc)) > maximumSpeedLowerBound ) { //If the max speed of the road is greater than that of the limit include it in the core. return false; } else { diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 98fd8e3f8c..7b8f813354 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -28,26 +28,18 @@ */ public class MaximumSpeedWeighting implements Weighting { - private double maximumSpeedLowerBound; protected final static double SPEED_UNIT_CONVERTER = 3.6; //From km/h to m/s. private final double headingPenalty; private final double userMaxSpeed; private final Weighting superWeighting; private final DecimalEncodedValue avSpeedEnc; private boolean calculateWeight; - private double maxSpeed = ((AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) != null) - ? Double.parseDouble(AppConfig.getGlobal().getServiceParameter("routing.profiles.default_params","maximum_speed_lower_bound")) - : maximumSpeedLowerBound; //If there is a maximum_speed value in the app.config we use that. If not we set a default of 80. public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighting weighting, double maximumSpeedLowerBound) { - this.maximumSpeedLowerBound = maximumSpeedLowerBound; this.avSpeedEnc = flagEncoder.getAverageSpeedEnc(); this.superWeighting = weighting; - if(hintsMap.getDouble("user_speed",maxSpeed) < maxSpeed ){ - throw new RuntimeException("User speed should be <=" + maxSpeed); - } this.headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); - this.userMaxSpeed = hintsMap.getDouble("user_speed",maxSpeed); + this.userMaxSpeed = hintsMap.getDouble("user_speed", maximumSpeedLowerBound); this.calculateWeight = (superWeighting.getName() == "fastest"); } From f25fdacadab8d6c02c6669637458401f80cc7c56 Mon Sep 17 00:00:00 2001 From: Athanasios Kogios <51202721+star-pirate@users.noreply.github.com> Date: Wed, 17 Jun 2020 13:26:55 +0200 Subject: [PATCH 34/38] Fixed mistake in ResultsTest. --- .../java/org/heigit/ors/v2/services/routing/ResultTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 c5aed4c37f..a86522cfcd 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 @@ -1253,7 +1253,8 @@ public void testMaximumSpeed() { .when() .post(getEndPointPath() + "/{profile}") .then() - .assertThat().body("any { it.key == 'routes' }", is(true)) + .assertThat() + .body("any { it.key == 'routes' }", is(true)) .body("routes[0].summary.duration", is(1986.6f)) .statusCode(200); } From 11f28659c2069e3b15de2493504ea027bceb38b4 Mon Sep 17 00:00:00 2001 From: aoles Date: Sat, 20 Jun 2020 13:52:32 +0200 Subject: [PATCH 35/38] Fix broken API tests --- openrouteservice-api-tests/conf/app.config.test | 1 - .../java/org/heigit/ors/v2/services/routing/ResultTest.java | 2 +- .../java/org/heigit/ors/routing/RoutingProfileManager.java | 5 +++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openrouteservice-api-tests/conf/app.config.test b/openrouteservice-api-tests/conf/app.config.test index d34a7dd29b..890e4a3e4d 100644 --- a/openrouteservice-api-tests/conf/app.config.test +++ b/openrouteservice-api-tests/conf/app.config.test @@ -91,7 +91,6 @@ encoder_options: "turn_costs=true|block_fords=false|maximum_grade_level=1|use_acceleration=true", maximum_distance: 100000, elevation: true, - maximum_speed_lower_bound: 75, preparation: { min_network_size: 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 a86522cfcd..559a91dc9f 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 @@ -1240,7 +1240,7 @@ public void testMaximumSpeed() { .then() .assertThat() .body("any { it.key == 'routes' }", is(true)) - .body("routes[0].summary.duration", is(1736.6f)) + .body("routes[0].summary.duration", is(1694.8f)) .statusCode(200); //Test profile-specific maximum speed lower bound diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java index e9a0c2e7b7..358c832f3a 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfileManager.java @@ -20,6 +20,7 @@ import com.vividsolutions.jts.geom.Coordinate; import org.apache.commons.lang.NotImplementedException; import org.apache.log4j.Logger; +import org.heigit.ors.api.requests.routing.RouteRequest; import org.heigit.ors.exceptions.*; import org.heigit.ors.isochrones.IsochroneMap; import org.heigit.ors.isochrones.IsochroneSearchParameters; @@ -575,10 +576,10 @@ public RoutingProfile getRouteProfile(RoutingRequest req, boolean oneToMany) thr if(searchParams.hasMaximumSpeed()){ if(searchParams.getMaximumSpeed() < config.getMaximumSpeedLowerBound()) { - throw new ParameterValueException("The maximum speed must not be lower than " + config.getMaximumSpeedLowerBound() + " km/h."); + throw new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, RouteRequest.PARAM_MAXIMUM_SPEED, String.valueOf(searchParams.getMaximumSpeed()), "The maximum speed must not be lower than " + config.getMaximumSpeedLowerBound() + " km/h."); } if(!(rp.getGraphhopper().getEncodingManager().hasEncoder("heavyvehicle") || rp.getGraphhopper().getEncodingManager().hasEncoder("car-ors")) ){ - throw new ParameterValueException("The maximum speed feature can only be used with cars and heavy vehicles."); + throw new ParameterValueException(RoutingErrorCodes.INCOMPATIBLE_PARAMETERS, "The maximum speed feature can only be used with cars and heavy vehicles."); } } From 4d005e8529a8582ba30f3c94dc91d6c451e7df8c Mon Sep 17 00:00:00 2001 From: aoles Date: Sun, 21 Jun 2020 14:44:27 +0200 Subject: [PATCH 36/38] Fix MaximumSpeedWeighting and refactor API tests --- .../ors/v2/services/routing/ParamsTest.java | 15 +----------- .../ors/v2/services/routing/ResultTest.java | 20 +++------------- .../v2/services/utils/HelperFunctions.java | 24 ++++++++++--------- .../weighting/MaximumSpeedWeighting.java | 2 +- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ParamsTest.java b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ParamsTest.java index 1d4387c2e7..7bc4c1ebd9 100644 --- a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ParamsTest.java +++ b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ParamsTest.java @@ -27,6 +27,7 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.*; +import static org.heigit.ors.v2.services.utils.HelperFunctions.constructCoords; @EndPointAnnotation(name = "directions") @VersionAnnotation(version = "v2") @@ -1734,20 +1735,6 @@ public void expectRejectRoundTripWithoutLength() { .statusCode(400); } - private JSONArray constructCoords(String coordString) { - JSONArray coordinates = new JSONArray(); - String[] coordPairs = coordString.split("\\|"); - for (String pair : coordPairs) { - JSONArray coord = new JSONArray(); - String[] pairCoords = pair.split(","); - coord.put(Double.parseDouble(pairCoords[0])); - coord.put(Double.parseDouble(pairCoords[1])); - coordinates.put(coord); - } - - return coordinates; - } - @Test public void testMaximumSpeedLowerBound() { JSONObject body = new JSONObject(); 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 559a91dc9f..6e0e8d8aba 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 @@ -14,7 +14,6 @@ package org.heigit.ors.v2.services.routing; import io.restassured.response.Response; -import io.restassured.response.ValidatableResponse; import junit.framework.Assert; import org.heigit.ors.v2.services.common.EndPointAnnotation; import org.heigit.ors.v2.services.common.ServiceTest; @@ -45,6 +44,7 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.*; +import static org.heigit.ors.v2.services.utils.HelperFunctions.constructCoords; @EndPointAnnotation(name = "directions") @VersionAnnotation(version = "v2") @@ -1227,7 +1227,7 @@ public void testMaximumSpeed() { JSONObject body = new JSONObject(); body.put("coordinates", constructCoords("8.63348,49.41766|8.6441,49.4672")); body.put("preference", getParameter("preference")); - body.put("maximum_speed", 80); + body.put("maximum_speed", 85); //Test against default maximum speed lower bound setting given() @@ -1240,7 +1240,7 @@ public void testMaximumSpeed() { .then() .assertThat() .body("any { it.key == 'routes' }", is(true)) - .body("routes[0].summary.duration", is(1694.8f)) + .body("routes[0].summary.duration", is(1658.0f)) .statusCode(200); //Test profile-specific maximum speed lower bound @@ -3013,20 +3013,6 @@ public void testWaypointCount() { .body("features[0].properties.way_points[1]", is(93)) .statusCode(200); } - - private JSONArray constructCoords(String coordString) { - JSONArray coordinates = new JSONArray(); - String[] coordPairs = coordString.split("\\|"); - for (String pair : coordPairs) { - JSONArray coord = new JSONArray(); - String[] pairCoords = pair.split(","); - coord.put(Double.parseDouble(pairCoords[0])); - coord.put(Double.parseDouble(pairCoords[1])); - coordinates.put(coord); - } - - return coordinates; - } private JSONArray constructBearings(String coordString) { JSONArray coordinates = new JSONArray(); diff --git a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/utils/HelperFunctions.java b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/utils/HelperFunctions.java index bcb1271444..79261fdf36 100644 --- a/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/utils/HelperFunctions.java +++ b/openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/utils/HelperFunctions.java @@ -25,20 +25,22 @@ public static JSONArray fakeJSONLocations(int maximumSize) { } /** - * This function creates a {@link JSONArray} with fake coordinates. - * The size depends on maximumSize. + * This function creates a {@link JSONArray} with coordinates. * - * @param maximumSize number of maximum coordinates in the {@link JSONArray} + * @param coordString coordinates string * @return {@link JSONArray} */ - public List> fakeListLocations(int maximumSize) { - List> listOfBareCoordinatesList = new ArrayList<>(); - for (int i = 0; i < maximumSize; i++) { - List bareCoordinatesList = new ArrayList<>(); - bareCoordinatesList.add(8.681495); - bareCoordinatesList.add(49.41461); - listOfBareCoordinatesList.add(bareCoordinatesList); + public static JSONArray constructCoords(String coordString) { + JSONArray coordinates = new JSONArray(); + String[] coordPairs = coordString.split("\\|"); + for (String pair : coordPairs) { + JSONArray coord = new JSONArray(); + String[] pairCoords = pair.split(","); + coord.put(Double.parseDouble(pairCoords[0])); + coord.put(Double.parseDouble(pairCoords[1])); + coordinates.put(coord); } - return listOfBareCoordinatesList; + + return coordinates; } } diff --git a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java index 7b8f813354..2eac9b5312 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java +++ b/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/MaximumSpeedWeighting.java @@ -39,7 +39,7 @@ public MaximumSpeedWeighting(FlagEncoder flagEncoder, HintsMap hintsMap, Weighti this.avSpeedEnc = flagEncoder.getAverageSpeedEnc(); this.superWeighting = weighting; this.headingPenalty = hintsMap.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY); - this.userMaxSpeed = hintsMap.getDouble("user_speed", maximumSpeedLowerBound); + this.userMaxSpeed = hintsMap.getDouble("maximum_speed", maximumSpeedLowerBound); this.calculateWeight = (superWeighting.getName() == "fastest"); } From b97490c7481a22b66ab09f5066e77313b6c4e4ca Mon Sep 17 00:00:00 2001 From: aoles Date: Mon, 22 Jun 2020 12:26:58 +0200 Subject: [PATCH 37/38] Add CUSTOM_KEYS metadata to ApiModelProperty annotation --- .../org/heigit/ors/api/requests/routing/RouteRequest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java index f0ff257dcb..1bc294caa5 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java @@ -247,7 +247,9 @@ public class RouteRequest { @JsonIgnore private boolean hasAlternativeRoutes = false; - @ApiModelProperty(name = PARAM_MAXIMUM_SPEED, value = "The maximum speed specified by user.", example = "90") + @ApiModelProperty(name = PARAM_MAXIMUM_SPEED, value = "The maximum speed specified by user." + + "CUSTOM_KEYS:{'validWhen':{'ref':'profile','value':'driving-*'}}", + example = "90") @JsonProperty(PARAM_MAXIMUM_SPEED) private double maximumSpeed; @JsonIgnore From 140605285db05d236e315dc094d92d1fe965f31d Mon Sep 17 00:00:00 2001 From: aoles Date: Mon, 22 Jun 2020 12:46:13 +0200 Subject: [PATCH 38/38] Minor tweak to CUSTOM_KEYS metadata --- .../java/org/heigit/ors/api/requests/routing/RouteRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java index 1bc294caa5..2ffb115a46 100644 --- a/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java +++ b/openrouteservice/src/main/java/org/heigit/ors/api/requests/routing/RouteRequest.java @@ -248,7 +248,7 @@ public class RouteRequest { private boolean hasAlternativeRoutes = false; @ApiModelProperty(name = PARAM_MAXIMUM_SPEED, value = "The maximum speed specified by user." + - "CUSTOM_KEYS:{'validWhen':{'ref':'profile','value':'driving-*'}}", + "CUSTOM_KEYS:{'validWhen':{'ref':'profile','value':['driving-*']}}", example = "90") @JsonProperty(PARAM_MAXIMUM_SPEED) private double maximumSpeed;