Skip to content

Commit

Permalink
refactor: move method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Fendrich committed Jan 27, 2025
1 parent a4ee961 commit 34a90ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);

}
}

0 comments on commit 34a90ca

Please sign in to comment.