use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class RouteResourceCustomModelTest method createConfig.
private static GraphHopperServerConfiguration createConfig() {
GraphHopperServerConfiguration config = new GraphHopperServerTestConfiguration();
config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "bike,car,foot,wheelchair,roads").putObject("prepare.min_network_size", 200).putObject("datareader.file", "../core/files/north-bayreuth.osm.gz").putObject("graph.location", DIR).putObject("graph.encoded_values", "max_height,max_weight,max_width,hazmat,toll,surface,track_type").putObject("custom_model_folder", "./src/test/resources/com/graphhopper/application/resources").setProfiles(Arrays.asList(new Profile("wheelchair"), new CustomProfile("roads").setCustomModel(new CustomModel()).setVehicle("roads"), new CustomProfile("car").setCustomModel(new CustomModel()).setVehicle("car"), new CustomProfile("bike").setCustomModel(new CustomModel().setDistanceInfluence(0)).setVehicle("bike"), new Profile("bike_fastest").setWeighting("fastest").setVehicle("bike"), new CustomProfile("truck").setVehicle("car").putHint("custom_model_file", "truck.yml"), new CustomProfile("cargo_bike").setVehicle("bike").putHint("custom_model_file", "cargo_bike.yml"), new CustomProfile("json_bike").setVehicle("bike").putHint("custom_model_file", "json_bike.json"), new Profile("foot_profile").setVehicle("foot").setWeighting("fastest"), new CustomProfile("car_no_unclassified").setCustomModel(new CustomModel(new CustomModel().addToPriority(If("road_class == UNCLASSIFIED", LIMIT, 0)))).setVehicle("car"), new CustomProfile("custom_bike").setCustomModel(new CustomModel().addToSpeed(If("road_class == PRIMARY", LIMIT, 28)).addToPriority(If("max_width < 1.2", MULTIPLY, 0))).setVehicle("bike"), new CustomProfile("custom_bike2").setCustomModel(new CustomModel(new CustomModel().addToPriority(If("road_class == TERTIARY || road_class == TRACK", MULTIPLY, 0)))).setVehicle("bike"), new CustomProfile("custom_bike3").setCustomModel(new CustomModel(new CustomModel().addToSpeed(If("road_class == TERTIARY || road_class == TRACK", MULTIPLY, 10)).addToSpeed(If("true", LIMIT, 40)))).setVehicle("bike"))).setCHProfiles(Arrays.asList(new CHProfile("truck"), new CHProfile("car_no_unclassified")));
return config;
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class RouteResourceIssue1574Test method createConfig.
private static GraphHopperServerConfiguration createConfig() {
GraphHopperServerConfiguration config = new GraphHopperServerTestConfiguration();
// this is the reason we put this test into an extra file: we can only reproduce the bug of issue 1574 by increasing the one-way-network size
config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car").putObject("prepare.min_network_size", 0).putObject("datareader.file", "../core/files/andorra.osm.pbf").putObject("graph.location", DIR).setProfiles(Collections.singletonList(new Profile("car_profile").setVehicle("car").setWeighting("fastest"))).setCHProfiles(Collections.singletonList(new CHProfile("car_profile")));
return config;
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class RouteResourceTurnCostsLegacyTest method createConfig.
private static GraphHopperServerConfiguration createConfig() {
GraphHopperServerConfiguration config = new GraphHopperServerTestConfiguration();
config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car|turn_costs=true").putObject("prepare.min_network_size", 0).putObject("datareader.file", "../core/files/moscow.osm.gz").putObject("graph.encoded_values", "road_class,surface,road_environment,max_speed").putObject("graph.location", DIR).setProfiles(Arrays.asList(new Profile("my_car_turn_costs").setVehicle("car").setWeighting("fastest").setTurnCosts(true), new Profile("my_car_no_turn_costs").setVehicle("car").setWeighting("fastest").setTurnCosts(false))).setCHProfiles(Arrays.asList(new CHProfile("my_car_turn_costs"), new CHProfile("my_car_no_turn_costs"))).setLMProfiles(Arrays.asList(new LMProfile("my_car_no_turn_costs"), // no need for a second LM preparation: we can just cross query here
new LMProfile("my_car_turn_costs").setPreparationProfile("my_car_no_turn_costs")));
return config;
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopper method checkProfilesConsistency.
private void checkProfilesConsistency() {
EncodingManager encodingManager = getEncodingManager();
for (Profile 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'");
}
FlagEncoder encoder = encodingManager.getEncoder(profile.getVehicle());
if (profile.isTurnCosts() && !encoder.supportsTurnCosts()) {
throw new IllegalArgumentException("The profile '" + profile.getName() + "' was configured with " + "'turn_costs=true', but the corresponding vehicle '" + profile.getVehicle() + "' does not support turn costs." + "\nYou need to add `|turn_costs=true` to the vehicle in `graph.flag_encoders`");
}
try {
createWeighting(profile, new PMap());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not create weighting for profile: '" + profile.getName() + "'.\n" + "Profile: " + profile + "\n" + "Error: " + e.getMessage());
}
if (profile instanceof CustomProfile) {
CustomModel customModel = ((CustomProfile) profile).getCustomModel();
if (customModel == null)
throw new IllegalArgumentException("custom model for profile '" + profile.getName() + "' was empty");
if (!CustomWeighting.NAME.equals(profile.getWeighting()))
throw new IllegalArgumentException("profile '" + profile.getName() + "' has a custom model but " + "weighting=" + profile.getWeighting() + " was defined");
}
}
Set<String> chProfileSet = new LinkedHashSet<>(chPreparationHandler.getCHProfiles().size());
for (CHProfile chProfile : chPreparationHandler.getCHProfiles()) {
boolean added = chProfileSet.add(chProfile.getProfile());
if (!added) {
throw new IllegalArgumentException("Duplicate CH reference to profile '" + chProfile.getProfile() + "'");
}
if (!profilesByName.containsKey(chProfile.getProfile())) {
throw new IllegalArgumentException("CH profile references unknown profile '" + chProfile.getProfile() + "'");
}
}
Map<String, LMProfile> lmProfileMap = new LinkedHashMap<>(lmPreparationHandler.getLMProfiles().size());
for (LMProfile lmProfile : lmPreparationHandler.getLMProfiles()) {
LMProfile previous = lmProfileMap.put(lmProfile.getProfile(), lmProfile);
if (previous != null) {
throw new IllegalArgumentException("Multiple LM profiles are using the same profile '" + lmProfile.getProfile() + "'");
}
if (!profilesByName.containsKey(lmProfile.getProfile())) {
throw new IllegalArgumentException("LM profile references unknown profile '" + lmProfile.getProfile() + "'");
}
if (lmProfile.usesOtherPreparation() && !profilesByName.containsKey(lmProfile.getPreparationProfile())) {
throw new IllegalArgumentException("LM profile references unknown preparation profile '" + lmProfile.getPreparationProfile() + "'");
}
}
for (LMProfile lmProfile : lmPreparationHandler.getLMProfiles()) {
if (lmProfile.usesOtherPreparation() && !lmProfileMap.containsKey(lmProfile.getPreparationProfile())) {
throw new IllegalArgumentException("Unknown LM preparation profile '" + lmProfile.getPreparationProfile() + "' in LM profile '" + lmProfile.getProfile() + "' cannot be used as preparation_profile");
}
if (lmProfile.usesOtherPreparation() && lmProfileMap.get(lmProfile.getPreparationProfile()).usesOtherPreparation()) {
throw new IllegalArgumentException("Cannot use '" + lmProfile.getPreparationProfile() + "' as preparation_profile for LM profile '" + lmProfile.getProfile() + "', because it uses another profile for preparation itself.");
}
}
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class CHProfileSelectorTest method multipleVehiclesMissingWeighting.
@Test
public void multipleVehiclesMissingWeighting() {
// this is a common use-case, there are multiple vehicles for one weighting
List<Profile> profiles = new ArrayList<>();
List<CHProfile> chProfiles = new ArrayList<>();
for (String vehicle : Arrays.asList("car", "bike", "motorcycle", "bike2", "foot")) {
profiles.add(new Profile(vehicle).setVehicle(vehicle).setWeighting("short_fastest").setTurnCosts(false));
chProfiles.add(new CHProfile(vehicle));
}
// we do not specify the weighting but this is ok, because there is only one in use
String weighting = null;
assertProfileFound(profiles.get(0), profiles, chProfiles, "car", weighting, null, null);
assertProfileFound(profiles.get(1), profiles, chProfiles, "bike", weighting, null, null);
assertProfileFound(profiles.get(2), profiles, chProfiles, "motorcycle", weighting, null, null);
assertProfileFound(profiles.get(3), profiles, chProfiles, "bike2", weighting, null, null);
assertProfileFound(profiles.get(4), profiles, chProfiles, "foot", weighting, null, null);
}
Aggregations