New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move ProfileResolver out of GraphHopper class #1958
Changes from 28 commits
1f890aa
b461512
aeffb34
a021160
4267ea5
aedcc4d
9a43eef
8d1eeda
e3e628b
13c02ea
18d117a
2c97604
ff55558
3751974
c9c7e36
798177a
96fec57
12f06fb
7a0844b
df15f83
8d57c53
757cc1d
4c770ec
cb7b451
409cad2
95d5ed2
e774c1c
8696944
ac9280f
1427822
00c74ab
48c997b
4d60cfb
f3c63e9
e55c94d
50116c5
019beb4
116a864
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,10 @@ | |
import com.graphhopper.reader.DataReader; | ||
import com.graphhopper.reader.dem.*; | ||
import com.graphhopper.reader.osm.conditional.DateRangeParser; | ||
import com.graphhopper.routing.*; | ||
import com.graphhopper.routing.AlgorithmOptions; | ||
import com.graphhopper.routing.Path; | ||
import com.graphhopper.routing.RoutingAlgorithmFactory; | ||
import com.graphhopper.routing.RoutingAlgorithmFactorySimple; | ||
import com.graphhopper.routing.ch.CHPreparationHandler; | ||
import com.graphhopper.routing.ch.CHRoutingAlgorithmFactory; | ||
import com.graphhopper.routing.lm.LMPreparationHandler; | ||
|
@@ -102,8 +105,6 @@ public class GraphHopper implements GraphHopperAPI { | |
private boolean smoothElevation = false; | ||
// for routing | ||
private final RoutingConfig routingConfig = new RoutingConfig(); | ||
private ProfileResolver profileResolver = new ProfileResolver(); | ||
|
||
// for index | ||
private LocationIndex locationIndex; | ||
private int preciseIndexResolution = 300; | ||
|
@@ -140,13 +141,6 @@ protected GraphHopper loadGraph(GraphHopperStorage g) { | |
return this; | ||
} | ||
|
||
FlagEncoder getDefaultVehicle() { | ||
if (encodingManager == null) | ||
throw new IllegalStateException("No encoding manager specified or loaded"); | ||
|
||
return profileResolver.getDefaultVehicle(encodingManager); | ||
} | ||
|
||
public EncodingManager getEncodingManager() { | ||
return encodingManager; | ||
} | ||
|
@@ -491,15 +485,6 @@ public GraphHopper setTagParserFactory(TagParserFactory factory) { | |
return this; | ||
} | ||
|
||
public ProfileResolver getProfileResolver() { | ||
return this.profileResolver; | ||
} | ||
|
||
public GraphHopper setProfileResolver(ProfileResolver profileResolver) { | ||
this.profileResolver = profileResolver; | ||
return this; | ||
} | ||
|
||
/** | ||
* Reads the configuration from a {@link GraphHopperConfig} object which can be manually filled, or more typically | ||
* is read from `config.yml`. | ||
|
@@ -824,6 +809,9 @@ public boolean load(String graphHopperFolder) { | |
} | ||
|
||
private void checkProfilesConsistency() { | ||
if (profilesByName.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few odd cases where we do not use |
||
throw new IllegalArgumentException("No routing profiles have been specified, you need to configure at least one"); | ||
} | ||
for (ProfileConfig profile : profilesByName.values()) { | ||
if (!encodingManager.hasEncoder(profile.getVehicle())) { | ||
throw new IllegalArgumentException("Unknown vehicle '" + profile.getVehicle() + "' in profile: " + profile + ". Make sure all vehicles used in 'profiles' exist in 'graph.flag_encoders'"); | ||
|
@@ -864,13 +852,6 @@ private void checkProfilesConsistency() { | |
} | ||
} | ||
|
||
public ProfileConfig resolveProfile(HintsMap hints) { | ||
if (encodingManager == null) | ||
throw new IllegalStateException("No encoding manager specified or loaded"); | ||
|
||
return profileResolver.resolveProfile(encodingManager, chPreparationHandler.getCHProfiles(), lmPreparationHandler.getLMProfiles(), hints); | ||
} | ||
|
||
public RoutingAlgorithmFactory getAlgorithmFactory(String profile, boolean disableCH, boolean disableLM) { | ||
if (chPreparationHandler.isEnabled() && disableCH && !chPreparationHandler.isDisablingAllowed()) { | ||
throw new IllegalArgumentException("Disabling CH is not allowed on the server side"); | ||
|
@@ -1030,6 +1011,17 @@ public List<Path> calcPaths(GHRequest request, GHResponse ghRsp) { | |
Lock readLock = readWriteLock.readLock(); | ||
readLock.lock(); | ||
try { | ||
if (!request.getVehicle().isEmpty()) | ||
throw new IllegalArgumentException("GHRequest may no longer contain a vehicle, use the profile parameter instead, see #1958"); | ||
if (!request.getWeighting().isEmpty()) | ||
throw new IllegalArgumentException("GHRequest may no longer contain a weighting, use the profile parameter instead, see #1958"); | ||
if (request.getHints().has(Routing.TURN_COSTS)) | ||
throw new IllegalArgumentException("GHRequest may no longer contain the turn_costs=true/false parameter, use the profile parameter instead, see #1958"); | ||
if (request.getHints().has(Routing.EDGE_BASED)) | ||
throw new IllegalArgumentException("GHRequest may no longer contain the edge_based=true/false parameter, use the profile parameter instead, see #1958"); | ||
|
||
// todo later: do not allow things like short_fastest.distance_factor or u_turn_costs unless CH is disabled and only under certain conditions for LM | ||
|
||
HintsMap hints = request.getHints(); | ||
boolean disableCH = hints.getBool(CH.DISABLE, false); | ||
if (chPreparationHandler.isEnabled() && !chPreparationHandler.isDisablingAllowed() && disableCH) | ||
|
@@ -1056,10 +1048,17 @@ public List<Path> calcPaths(GHRequest request, GHResponse ghRsp) { | |
// For example see #734 | ||
checkIfPointsAreInBounds(points); | ||
|
||
ProfileConfig profile = resolveProfile(hints); | ||
if (Helper.isEmpty(request.getProfile())) { | ||
throw new IllegalArgumentException("You need to specify a profile to perform a routing request, see #1958"); | ||
} | ||
ProfileConfig profile = profilesByName.get(request.getProfile()); | ||
if (profile == null) { | ||
throw new IllegalArgumentException("The requested profile '" + request.getProfile() + "' does not exist"); | ||
} | ||
if (!profile.isTurnCosts() && !request.getCurbsides().isEmpty()) | ||
throw new IllegalArgumentException("To make use of the " + CURBSIDE + " parameter you need to use a profile that supports turn costs"); | ||
|
||
// todo later: should we be able to control this using the edge_based parameter? | ||
TraversalMode tMode = profile.isTurnCosts() ? TraversalMode.EDGE_BASED : TraversalMode.NODE_BASED; | ||
|
||
RoutingAlgorithmFactory algorithmFactory = getAlgorithmFactory(profile.getName(), disableCH, disableLM); | ||
|
@@ -1350,13 +1349,20 @@ public DefaultWeightingFactory(EncodingManager encodingManager, GraphHopperStora | |
this.ghStorage = ghStorage; | ||
} | ||
|
||
public Weighting createWeighting(ProfileConfig profile, PMap hints) { | ||
public Weighting createWeighting(ProfileConfig profile, PMap requestHints) { | ||
// Merge profile hints with request hints, the request hints take precedence. | ||
// Note that so far we do not check if overwriting the profile hints actually works with the preparation | ||
// for LM/CH. Later we should also limit the number of parameters that can be used to modify the profile. | ||
PMap hints = new PMap(); | ||
hints.putAll(profile.getHints()); | ||
hints.putAll(requestHints); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are (the very simple) rules how we merge the profile hints with the request hints. The only thing I am wondering now is how we do this for block_area? Shall we do this in a similar way (use hints from profile and overwrite with request hints)? Do we need this here or is it ok to only create block areas from request hints (not the profile) here, and add this in #1776? Its still a bit unfortunate that we do not do the block_area stuff inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmmh, we would need to add it to the list of shapes
I would postpone this and properly support this in CustomWeighting.
Yeah, although we only need this because of the is-in-area check which we could keep out of the Weighting creation somehow. |
||
|
||
FlagEncoder encoder = encodingManager.getEncoder(profile.getVehicle()); | ||
TurnCostProvider turnCostProvider; | ||
if (profile.isTurnCosts() && !hints.getBool("__disable_turn_costs_for_lm_preparation", false)) { | ||
if (!encoder.supportsTurnCosts()) | ||
throw new IllegalArgumentException("Encoder " + encoder + " does not support turn costs"); | ||
int uTurnCosts = profile.getHints().getInt(Routing.U_TURN_COSTS, INFINITE_U_TURN_COSTS); | ||
int uTurnCosts = hints.getInt(Routing.U_TURN_COSTS, INFINITE_U_TURN_COSTS); | ||
turnCostProvider = new DefaultTurnCostProvider(encoder, ghStorage.getTurnCostStorage(), uTurnCosts); | ||
} else { | ||
turnCostProvider = NO_TURN_COST_PROVIDER; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we discussed this in #1859 already: We'll def. remove vehicle+weighting from the HintsMap, but maybe in a follow-up PR? Since the profile parameter will be required it makes sense to keep it as a separate field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I would also use it here and remove weighting and vehicle in a later PR