From 34a90ca701d74ba87d9ae15b11ec08214b2a1f37 Mon Sep 17 00:00:00 2001 From: Sascha Fendrich Date: Mon, 27 Jan 2025 11:27:45 +0100 Subject: [PATCH] refactor: move method --- .../heigit/ors/routing/RoutingProfile.java | 39 ---------------- .../heigit/ors/routing/RoutingRequest.java | 44 +++++++++++++++++-- 2 files changed, 40 insertions(+), 43 deletions(-) diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfile.java b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfile.java index 1ee6b03c9e..799ec22f9a 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfile.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingProfile.java @@ -13,11 +13,9 @@ */ package org.heigit.ors.routing; -import com.graphhopper.GHRequest; import com.graphhopper.config.CHProfile; import com.graphhopper.storage.GraphHopperStorage; import com.graphhopper.storage.StorableProperties; -import com.graphhopper.util.Parameters; import org.apache.log4j.Logger; import org.heigit.ors.config.EngineProperties; import org.heigit.ors.config.profile.ExecutionProperties; @@ -27,7 +25,6 @@ import org.heigit.ors.routing.graphhopper.extensions.storages.builders.BordersGraphStorageBuilder; import org.heigit.ors.routing.graphhopper.extensions.storages.builders.GraphStorageBuilder; import org.heigit.ors.routing.pathprocessors.ORSPathProcessorFactory; -import org.heigit.ors.util.ProfileTools; import org.heigit.ors.util.TimeUtility; import java.io.File; @@ -181,42 +178,6 @@ public Double getAstarEpsilon() { return astarEpsilon; } - /** - * Set the speedup techniques used for calculating the route. - * Reults in usage of CH, Core or ALT/AStar, if they are enabled. - * - * @param routingRequest - * @param req Request whose hints will be set - * @param useCH Should CH be enabled - * @param useCore Should Core be enabled - * @param useALT Should ALT be enabled - */ - public void setSpeedups(GHRequest req, boolean useCH, boolean useCore, boolean useALT, String profileNameCH, RoutingRequest routingRequest) { - String requestProfileName = req.getProfile(); - - //Priority: CH->Core->ALT - String profileNameNoTC = requestProfileName.replace("_with_turn_costs", ""); - - ORSGraphHopper gh = routingRequest.profile().getGraphhopper(); - - useCH = useCH && gh.isCHAvailable(profileNameCH); - useCore = useCore && !useCH && (gh.isCoreAvailable(requestProfileName) || gh.isCoreAvailable(profileNameNoTC)); - useALT = useALT && !useCH && !useCore && gh.isLMAvailable(requestProfileName); - - req.getHints().putObject(ProfileTools.KEY_CH_DISABLE, !useCH); - req.getHints().putObject(ProfileTools.KEY_CORE_DISABLE, !useCore); - req.getHints().putObject(ProfileTools.KEY_LM_DISABLE, !useALT); - - if (useCH) { - req.setAlgorithm(Parameters.Algorithms.DIJKSTRA_BI); - req.setProfile(profileNameCH); - } - if (useCore && !gh.isCoreAvailable(requestProfileName) && gh.isCoreAvailable(profileNameNoTC)) - // fallback to a core profile without turn costs if one is available - req.setProfile(profileNameNoTC); - - } - public boolean equals(Object o) { return o != null && o.getClass().equals(RoutingProfile.class) && this.hashCode() == o.hashCode(); } diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingRequest.java b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingRequest.java index 250ba4891c..0bb9c148c5 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/RoutingRequest.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/RoutingRequest.java @@ -480,15 +480,15 @@ else if (bearings[1] == null) if (flexibleMode == ProfileTools.KEY_FLEX_STATIC) //Speedup order: useCH, useCore, useALT // TODO Future improvement: profileNameCH is an ugly hack and is required because of the hard-coded turnCost=false for CH - routingProfile.setSpeedups(req, true, true, true, searchCntx.profileNameCH(), this); + setSpeedups(req, true, true, true, searchCntx.profileNameCH()); if (flexibleMode == ProfileTools.KEY_FLEX_PREPROCESSED) { - routingProfile.setSpeedups(req, false, optimized, true, searchCntx.profileNameCH(), this); + setSpeedups(req, false, optimized, true, searchCntx.profileNameCH()); } //cannot use CH or CoreALT with requests where the weighting of non-predefined edges might change if (flexibleMode == ProfileTools.KEY_FLEX_FULLY) - routingProfile.setSpeedups(req, false, false, true, searchCntx.profileNameCH(), this); + setSpeedups(req, false, false, true, searchCntx.profileNameCH()); if (searchParams.isTimeDependent()) { String key; @@ -588,7 +588,7 @@ private GHResponse computeRoundTripRoute(double lat0, double lon0, WayPointBeari throw new IllegalArgumentException("Unsupported weighting " + weightingMethod + " for profile + " + profileType); //Roundtrip not possible with preprocessed edges. - routingProfile.setSpeedups(req, false, false, true, searchCntx.profileNameCH(), this); + setSpeedups(req, false, false, true, searchCntx.profileNameCH()); if (routingProfile.getAstarEpsilon() != null) req.getHints().putObject("astarbi.epsilon", routingProfile.getAstarEpsilon()); @@ -903,4 +903,40 @@ boolean requiresTimeDependentAlgorithm(RouteSearchContext searchCntx) { return flagEncoder.hasEncodedValue(EncodingManager.getKey(flagEncoder, ConditionalEdges.SPEED)) || profile().getGraphhopper().isTrafficEnabled(); } + + /** + * Set the speedup techniques used for calculating the route. + * Reults in usage of CH, Core or ALT/AStar, if they are enabled. + * + * @param req Request whose hints will be set + * @param useCH Should CH be enabled + * @param useCore Should Core be enabled + * @param useALT Should ALT be enabled + * @param profileNameCH + */ + public void setSpeedups(GHRequest req, boolean useCH, boolean useCore, boolean useALT, String profileNameCH) { + String requestProfileName = req.getProfile(); + + //Priority: CH->Core->ALT + String profileNameNoTC = requestProfileName.replace("_with_turn_costs", ""); + + ORSGraphHopper gh = profile().getGraphhopper(); + + useCH = useCH && gh.isCHAvailable(profileNameCH); + useCore = useCore && !useCH && (gh.isCoreAvailable(requestProfileName) || gh.isCoreAvailable(profileNameNoTC)); + useALT = useALT && !useCH && !useCore && gh.isLMAvailable(requestProfileName); + + req.getHints().putObject(ProfileTools.KEY_CH_DISABLE, !useCH); + req.getHints().putObject(ProfileTools.KEY_CORE_DISABLE, !useCore); + req.getHints().putObject(ProfileTools.KEY_LM_DISABLE, !useALT); + + if (useCH) { + req.setAlgorithm(Parameters.Algorithms.DIJKSTRA_BI); + req.setProfile(profileNameCH); + } + if (useCore && !gh.isCoreAvailable(requestProfileName) && gh.isCoreAvailable(profileNameNoTC)) + // fallback to a core profile without turn costs if one is available + req.setProfile(profileNameNoTC); + + } }