Skip to content

Commit

Permalink
Minor cleanup in GraphHopper and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
easbar committed Feb 6, 2020
1 parent a03a938 commit 5a1f85a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 14 additions & 12 deletions core/src/main/java/com/graphhopper/GraphHopper.java
Expand Up @@ -1030,6 +1030,14 @@ public List<Path> calcPaths(GHRequest request, GHResponse ghRsp) {
if (!lmFactoryDecorator.isDisablingAllowed() && disableLM)
throw new IllegalArgumentException("Disabling LM not allowed on the server-side");

if (chFactoryDecorator.isEnabled() && !disableCH) {
if (request.hasFavoredHeading(0))
throw new IllegalArgumentException("The 'heading' parameter is currently not supported for speed mode, you need to disable speed mode with `ch.disable=true`. See issue #483");

if (request.getHints().getBool(Routing.PASS_THROUGH, false))
throw new IllegalArgumentException("The '" + Parameters.Routing.PASS_THROUGH + "' parameter is currently not supported for speed mode, you need to disable speed mode with `ch.disable=true`. See issue #1765");
}

String algoStr = request.getAlgorithm();
if (algoStr.isEmpty())
algoStr = chFactoryDecorator.isEnabled() && !disableCH ? DIJKSTRA_BI : ASTAR_BI;
Expand All @@ -1047,27 +1055,21 @@ public List<Path> calcPaths(GHRequest request, GHResponse ghRsp) {
? new DefaultTurnCostProvider(encoder, ghStorage.getTurnCostStorage(), uTurnCostsInt)
: NO_TURN_COST_PROVIDER;

RoutingAlgorithmFactory tmpAlgoFactory = getAlgorithmFactory(hints);
RoutingAlgorithmFactory algorithmFactory = getAlgorithmFactory(hints);
Weighting weighting;
Graph graph = ghStorage;
if (chFactoryDecorator.isEnabled() && !disableCH) {
if (request.hasFavoredHeading(0))
throw new IllegalArgumentException("The 'heading' parameter is currently not supported for speed mode, you need to disable speed mode with `ch.disable=true`. See issue #483");

if (request.getHints().getBool(Routing.PASS_THROUGH, false))
throw new IllegalArgumentException("The '" + Parameters.Routing.PASS_THROUGH + "' parameter is currently not supported for speed mode, you need to disable speed mode with `ch.disable=true`. See issue #1765");

// if LM is enabled we have the LMFactory with the CH algo!
RoutingAlgorithmFactory chAlgoFactory = tmpAlgoFactory;
if (tmpAlgoFactory instanceof LMAlgoFactoryDecorator.LMRAFactory)
chAlgoFactory = ((LMAlgoFactoryDecorator.LMRAFactory) tmpAlgoFactory).getDefaultAlgoFactory();
RoutingAlgorithmFactory chAlgoFactory = algorithmFactory;
if (algorithmFactory instanceof LMAlgoFactoryDecorator.LMRAFactory)
chAlgoFactory = ((LMAlgoFactoryDecorator.LMRAFactory) algorithmFactory).getDefaultAlgoFactory();

if (chAlgoFactory instanceof CHRoutingAlgorithmFactory) {
CHProfile chProfile = ((CHRoutingAlgorithmFactory) chAlgoFactory).getCHProfile();
weighting = chProfile.getWeighting();
graph = ghStorage.getCHGraph(chProfile);
} else {
throw new IllegalStateException("Although CH was enabled a non-CH algorithm factory was returned " + tmpAlgoFactory);
throw new IllegalStateException("Although CH was enabled a non-CH algorithm factory was returned " + algorithmFactory);
}
} else {
checkNonChMaxWaypointDistance(points);
Expand Down Expand Up @@ -1103,7 +1105,7 @@ else if (ALT_ROUTE.equalsIgnoreCase(algoStr))
build();

// do the actual route calculation !
List<Path> altPaths = routingTemplate.calcPaths(queryGraph, tmpAlgoFactory, algoOpts);
List<Path> altPaths = routingTemplate.calcPaths(queryGraph, algorithmFactory, algoOpts);

boolean tmpEnableInstructions = hints.getBool(Routing.INSTRUCTIONS, getEncodingManager().isEnableInstructions());
boolean tmpCalcPoints = hints.getBool(Routing.CALC_POINTS, calcPoints);
Expand Down
Expand Up @@ -120,7 +120,7 @@ public void testLoadOSMNoCH() {
setDataReaderFile(testOsm);
gh.importOrLoad();

assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof CHRoutingAlgorithmFactory);

GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
Expand All @@ -141,7 +141,7 @@ public void testLoadOSMNoCH() {
setDataReaderFile(testOsm).
init(new GraphHopperConfig().put("graph.flag_encoders", "car").put(Parameters.CH.PREPARE + "weightings", "no"));

assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof CHRoutingAlgorithmFactory);
gh.close();
}

Expand Down

0 comments on commit 5a1f85a

Please sign in to comment.