29
29
import com .graphhopper .routing .RoutingAlgorithmFactorySimple ;
30
30
import com .graphhopper .routing .ch .CHPreparationHandler ;
31
31
import com .graphhopper .routing .ch .CHRoutingAlgorithmFactory ;
32
- import com .graphhopper .routing .lm .LMConfig ;
33
- import com .graphhopper .routing .lm .LMPreparationHandler ;
34
32
import com .graphhopper .routing .ev .DefaultEncodedValueFactory ;
35
33
import com .graphhopper .routing .ev .EncodedValueFactory ;
36
34
import com .graphhopper .routing .ev .EnumEncodedValue ;
37
35
import com .graphhopper .routing .ev .RoadEnvironment ;
36
+ import com .graphhopper .routing .lm .LMConfig ;
37
+ import com .graphhopper .routing .lm .LMPreparationHandler ;
38
38
import com .graphhopper .routing .querygraph .QueryGraph ;
39
39
import com .graphhopper .routing .subnetwork .PrepareRoutingSubnetworks ;
40
40
import com .graphhopper .routing .template .AlternativeRoutingTemplate ;
@@ -1045,68 +1045,57 @@ public List<Path> calcPaths(GHRequest request, GHResponse ghRsp) {
1045
1045
1046
1046
try {
1047
1047
validateRequest (request );
1048
- PMap hints = request .getHints ();
1049
1048
final boolean disableCH = getDisableCH (request .getHints ());
1050
1049
final boolean disableLM = getDisableLM (request .getHints ());
1051
- String algoStr = request .getAlgorithm ();
1052
- if (algoStr .isEmpty ())
1053
- algoStr = chPreparationHandler .isEnabled () && !disableCH ? DIJKSTRA_BI : ASTAR_BI ;
1054
-
1055
1050
Profile profile = profilesByName .get (request .getProfile ());
1056
- if (profile == null ) {
1051
+ if (profile == null )
1057
1052
throw new IllegalArgumentException ("The requested profile '" + request .getProfile () + "' does not exist.\n Available profiles: " + profilesByName .keySet ());
1058
- }
1059
- if (!profile .isTurnCosts () && !request .getCurbsides ().isEmpty ()) {
1060
- List <String > turnCostProfiles = new ArrayList <>();
1061
- for (Profile p : profilesByName .values ()) {
1062
- if (p .isTurnCosts ()) {
1063
- turnCostProfiles .add (p .getName ());
1064
- }
1065
- }
1053
+ if (!profile .isTurnCosts () && !request .getCurbsides ().isEmpty ())
1066
1054
throw new IllegalArgumentException ("To make use of the " + CURBSIDE + " parameter you need to use a profile that supports turn costs" +
1067
- "\n The following profiles do support turn costs: " + turnCostProfiles );
1068
- }
1055
+ "\n The following profiles do support turn costs: " + getTurnCostProfiles ());
1069
1056
1070
1057
// todo later: should we be able to control this using the edge_based parameter?
1071
1058
TraversalMode tMode = profile .isTurnCosts () ? TraversalMode .EDGE_BASED : TraversalMode .NODE_BASED ;
1072
- List <GHPoint > points = request .getPoints ();
1073
1059
RoutingAlgorithmFactory algorithmFactory = getAlgorithmFactory (profile .getName (), disableCH , disableLM );
1074
1060
Weighting weighting ;
1075
1061
Graph graph = ghStorage ;
1076
1062
if (chPreparationHandler .isEnabled () && !disableCH ) {
1077
1063
if (!(algorithmFactory instanceof CHRoutingAlgorithmFactory ))
1078
1064
throw new IllegalStateException ("Although CH was enabled a non-CH algorithm factory was returned " + algorithmFactory );
1079
1065
1080
- if (hints .has (Routing .BLOCK_AREA ))
1066
+ if (request . getHints () .has (Routing .BLOCK_AREA ))
1081
1067
throw new IllegalArgumentException ("When CH is enabled the " + Parameters .Routing .BLOCK_AREA + " cannot be specified" );
1082
1068
1083
1069
CHConfig chConfig = ((CHRoutingAlgorithmFactory ) algorithmFactory ).getCHConfig ();
1084
1070
weighting = chConfig .getWeighting ();
1085
1071
graph = ghStorage .getCHGraph (chConfig );
1086
1072
} else {
1087
- checkNonChMaxWaypointDistance (points );
1088
- final int uTurnCostsInt = hints .getInt (Routing .U_TURN_COSTS , INFINITE_U_TURN_COSTS );
1073
+ checkNonChMaxWaypointDistance (request . getPoints () );
1074
+ final int uTurnCostsInt = request . getHints () .getInt (Routing .U_TURN_COSTS , INFINITE_U_TURN_COSTS );
1089
1075
if (uTurnCostsInt != INFINITE_U_TURN_COSTS && !tMode .isEdgeBased ()) {
1090
1076
throw new IllegalArgumentException ("Finite u-turn costs can only be used for edge-based routing, use `" + Routing .EDGE_BASED + "=true'" );
1091
1077
}
1092
1078
FlagEncoder encoder = encodingManager .getEncoder (profile .getVehicle ());
1093
- weighting = createWeighting (profile , hints );
1094
- if (hints .has (Routing .BLOCK_AREA ))
1079
+ weighting = createWeighting (profile , request . getHints () );
1080
+ if (request . getHints () .has (Routing .BLOCK_AREA ))
1095
1081
weighting = new BlockAreaWeighting (weighting , GraphEdgeIdFinder .createBlockArea (ghStorage , locationIndex ,
1096
- points , hints , DefaultEdgeFilter .allEdges (encoder )));
1082
+ request . getPoints (), request . getHints () , DefaultEdgeFilter .allEdges (encoder )));
1097
1083
}
1098
1084
ghRsp .addDebugInfo ("tmode:" + tMode .toString ());
1099
1085
1086
+ String algoStr = request .getAlgorithm ();
1087
+ if (algoStr .isEmpty ())
1088
+ algoStr = chPreparationHandler .isEnabled () && !disableCH ? DIJKSTRA_BI : ASTAR_BI ;
1100
1089
RoutingTemplate routingTemplate = createRoutingTemplate (request , ghRsp , algoStr , weighting );
1101
1090
1102
1091
StopWatch sw = new StopWatch ().start ();
1103
- List <QueryResult > qResults = routingTemplate .lookup (points );
1092
+ List <QueryResult > qResults = routingTemplate .lookup (request . getPoints () );
1104
1093
ghRsp .addDebugInfo ("idLookup:" + sw .stop ().getSeconds () + "s" );
1105
1094
if (ghRsp .hasErrors ())
1106
1095
return Collections .emptyList ();
1107
1096
1108
1097
QueryGraph queryGraph = QueryGraph .create (graph , qResults );
1109
- int maxVisitedNodesForRequest = hints .getInt (Routing .MAX_VISITED_NODES , routingConfig .getMaxVisitedNodes ());
1098
+ int maxVisitedNodesForRequest = request . getHints () .getInt (Routing .MAX_VISITED_NODES , routingConfig .getMaxVisitedNodes ());
1110
1099
if (maxVisitedNodesForRequest > routingConfig .getMaxVisitedNodes ())
1111
1100
throw new IllegalArgumentException ("The max_visited_nodes parameter has to be below or equal to:" + routingConfig .getMaxVisitedNodes ());
1112
1101
@@ -1115,15 +1104,15 @@ public List<Path> calcPaths(GHRequest request, GHResponse ghRsp) {
1115
1104
traversalMode (tMode ).
1116
1105
weighting (weighting ).
1117
1106
maxVisitedNodes (maxVisitedNodesForRequest ).
1118
- hints (hints ).
1107
+ hints (request . getHints () ).
1119
1108
build ();
1120
1109
1121
1110
// do the actual route calculation !
1122
1111
List <Path > altPaths = routingTemplate .calcPaths (queryGraph , algorithmFactory , algoOpts );
1123
1112
1124
- boolean tmpEnableInstructions = hints .getBool (Routing .INSTRUCTIONS , encodingManager .isEnableInstructions ());
1125
- boolean tmpCalcPoints = hints .getBool (Routing .CALC_POINTS , routingConfig .isCalcPoints ());
1126
- double wayPointMaxDistance = hints .getDouble (Routing .WAY_POINT_MAX_DISTANCE , 1d );
1113
+ boolean tmpEnableInstructions = request . getHints () .getBool (Routing .INSTRUCTIONS , encodingManager .isEnableInstructions ());
1114
+ boolean tmpCalcPoints = request . getHints () .getBool (Routing .CALC_POINTS , routingConfig .isCalcPoints ());
1115
+ double wayPointMaxDistance = request . getHints () .getDouble (Routing .WAY_POINT_MAX_DISTANCE , 1d );
1127
1116
1128
1117
DouglasPeucker peucker = new DouglasPeucker ().setMaxDistance (wayPointMaxDistance );
1129
1118
PathMerger pathMerger = new PathMerger (queryGraph .getBaseGraph (), weighting ).
@@ -1144,6 +1133,16 @@ public List<Path> calcPaths(GHRequest request, GHResponse ghRsp) {
1144
1133
}
1145
1134
}
1146
1135
1136
+ private List <String > getTurnCostProfiles () {
1137
+ List <String > turnCostProfiles = new ArrayList <>();
1138
+ for (Profile p : profilesByName .values ()) {
1139
+ if (p .isTurnCosts ()) {
1140
+ turnCostProfiles .add (p .getName ());
1141
+ }
1142
+ }
1143
+ return turnCostProfiles ;
1144
+ }
1145
+
1147
1146
protected void validateRequest (GHRequest request ) {
1148
1147
if (Helper .isEmpty (request .getProfile ()))
1149
1148
throw new IllegalArgumentException ("You need to specify a profile to perform a routing request, see docs/core/profiles.md" );
0 commit comments