Skip to content

Commit ec5824f

Browse files
authored
Use Astar by default for edge-based CH (graphhopper#2054)
1 parent a626215 commit ec5824f

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

core/src/main/java/com/graphhopper/routing/AStarBidirectionEdgeCHNoSOD.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ private double getMinCurrToPathWeight() {
107107
return currTo.weight + weightApprox.approximate(currTo.adjNode, true);
108108
}
109109

110-
111110
@Override
112111
public String getName() {
113112
return "astarbi|ch|edge_based|no_sod";

core/src/main/java/com/graphhopper/routing/Router.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949

5050
import static com.graphhopper.routing.weighting.Weighting.INFINITE_U_TURN_COSTS;
5151
import static com.graphhopper.util.Helper.DIST_EARTH;
52-
import static com.graphhopper.util.Parameters.Algorithms.*;
52+
import static com.graphhopper.util.Parameters.Algorithms.ALT_ROUTE;
53+
import static com.graphhopper.util.Parameters.Algorithms.ROUND_TRIP;
5354
import static com.graphhopper.util.Parameters.Routing.CURBSIDE;
5455
import static com.graphhopper.util.Parameters.Routing.POINT_HINT;
5556

@@ -133,10 +134,7 @@ public List<Path> route(GHRequest request, GHResponse ghRsp) {
133134
}
134135
ghRsp.addDebugInfo("tmode:" + tMode.toString());
135136

136-
String algoStr = request.getAlgorithm();
137-
if (algoStr.isEmpty())
138-
algoStr = chEnabled && !disableCH ? DIJKSTRA_BI : ASTAR_BI;
139-
RoutingTemplate routingTemplate = createRoutingTemplate(request, ghRsp, algoStr, weighting);
137+
RoutingTemplate routingTemplate = createRoutingTemplate(request, ghRsp, request.getAlgorithm(), weighting);
140138

141139
StopWatch sw = new StopWatch().start();
142140
List<QueryResult> qResults = routingTemplate.lookup(request.getPoints());
@@ -150,7 +148,7 @@ public List<Path> route(GHRequest request, GHResponse ghRsp) {
150148
throw new IllegalArgumentException("The max_visited_nodes parameter has to be below or equal to:" + routerConfig.getMaxVisitedNodes());
151149

152150
AlgorithmOptions algoOpts = AlgorithmOptions.start().
153-
algorithm(algoStr).
151+
algorithm(request.getAlgorithm()).
154152
traversalMode(tMode).
155153
weighting(weighting).
156154
maxVisitedNodes(maxVisitedNodesForRequest).

core/src/main/java/com/graphhopper/routing/RoutingAlgorithmFactorySimple.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) {
4444
} else if (DIJKSTRA.equalsIgnoreCase(algoStr)) {
4545
ra = new Dijkstra(g, weighting, opts.getTraversalMode());
4646

47-
} else if (ASTAR_BI.equalsIgnoreCase(algoStr)) {
47+
} else if (ASTAR_BI.equalsIgnoreCase(algoStr) || Helper.isEmpty(opts.getAlgorithm())) {
4848
AStarBidirection aStarBi = new AStarBidirection(g, weighting,
4949
opts.getTraversalMode());
5050
aStarBi.setApproximation(getApproximation(ASTAR_BI, opts, g.getNodeAccess()));

core/src/main/java/com/graphhopper/routing/ch/CHRoutingAlgorithmFactory.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.graphhopper.routing.*;
2222
import com.graphhopper.routing.weighting.Weighting;
2323
import com.graphhopper.storage.*;
24+
import com.graphhopper.util.Helper;
2425

2526
import static com.graphhopper.util.Parameters.Algorithms.*;
2627

@@ -37,7 +38,7 @@ public RoutingAlgorithm createAlgo(Graph graph, AlgorithmOptions opts) {
3738
// graph we have to use: the CH graph. Same with opts.weighting: The CHConfig already contains a weighting
3839
// and we cannot really use it here. The real reason we do this the way its done atm is that graph might be
3940
// a QueryGraph that wraps (our) CHGraph.
40-
RoutingAlgorithm algo = doCreateAlgo(graph, opts);
41+
RoutingAlgorithm algo = doCreateAlgo(graph, AlgorithmOptions.start(opts).weighting(getWeighting()).build());
4142
algo.setMaxVisitedNodes(opts.getMaxVisitedNodes());
4243
return algo;
4344
}
@@ -50,16 +51,16 @@ private RoutingAlgorithm doCreateAlgo(Graph graph, AlgorithmOptions opts) {
5051
if (turnCostStorage == null) {
5152
throw new IllegalArgumentException("For edge-based CH you need a turn cost extension");
5253
}
53-
RoutingCHGraph g = new RoutingCHGraphImpl(graph, graph.wrapWeighting(getWeighting()));
54+
RoutingCHGraph g = new RoutingCHGraphImpl(graph, graph.wrapWeighting(opts.getWeighting()));
5455
return createAlgoEdgeBased(g, opts);
5556
} else {
56-
RoutingCHGraph g = new RoutingCHGraphImpl(graph, chConfig.getWeighting());
57+
RoutingCHGraph g = new RoutingCHGraphImpl(graph, opts.getWeighting());
5758
return createAlgoNodeBased(g, opts);
5859
}
5960
}
6061

6162
private RoutingAlgorithm createAlgoEdgeBased(RoutingCHGraph g, AlgorithmOptions opts) {
62-
if (ASTAR_BI.equals(opts.getAlgorithm())) {
63+
if (ASTAR_BI.equals(opts.getAlgorithm()) || Helper.isEmpty(opts.getAlgorithm())) {
6364
return new AStarBidirectionEdgeCHNoSOD(g)
6465
.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, g.getGraph().getNodeAccess()));
6566
} else if (DIJKSTRA_BI.equals(opts.getAlgorithm())) {
@@ -75,7 +76,7 @@ private RoutingAlgorithm createAlgoNodeBased(RoutingCHGraph g, AlgorithmOptions
7576
if (ASTAR_BI.equals(opts.getAlgorithm())) {
7677
return new AStarBidirectionCH(g)
7778
.setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, g.getGraph().getNodeAccess()));
78-
} else if (DIJKSTRA_BI.equals(opts.getAlgorithm())) {
79+
} else if (DIJKSTRA_BI.equals(opts.getAlgorithm()) || Helper.isEmpty(opts.getAlgorithm())) {
7980
if (opts.getHints().getBool("stall_on_demand", true)) {
8081
return new DijkstraBidirectionCH(g);
8182
} else {

core/src/main/java/com/graphhopper/routing/lm/LMRoutingAlgorithmFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.graphhopper.routing.*;
2323
import com.graphhopper.routing.weighting.Weighting;
2424
import com.graphhopper.storage.Graph;
25+
import com.graphhopper.util.Helper;
2526
import com.graphhopper.util.Parameters;
2627

2728
import static com.graphhopper.util.Parameters.Algorithms.*;
@@ -58,7 +59,7 @@ public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) {
5859
algo.setApproximation(getApproximator(g, activeLM, epsilon));
5960
algo.setMaxVisitedNodes(opts.getMaxVisitedNodes());
6061
return algo;
61-
} else if (ASTAR_BI.equalsIgnoreCase(algoStr)) {
62+
} else if (ASTAR_BI.equalsIgnoreCase(algoStr) || Helper.isEmpty(opts.getAlgorithm())) {
6263
double epsilon = opts.getHints().getDouble(Parameters.Algorithms.AStarBi.EPSILON, 1);
6364
AStarBidirection algo = new AStarBidirection(g, weighting, opts.getTraversalMode());
6465
algo.setApproximation(getApproximator(g, activeLM, epsilon));

0 commit comments

Comments
 (0)