use of com.graphhopper.routing.weighting.custom.CustomProfile 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.routing.weighting.custom.CustomProfile in project graphhopper by graphhopper.
the class RouteResourceCustomModelLMTest method createConfig.
private static GraphHopperServerConfiguration createConfig() {
GraphHopperServerConfiguration config = new GraphHopperServerTestConfiguration();
config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car,foot").putObject("datareader.file", "../core/files/andorra.osm.pbf").putObject("graph.location", DIR).putObject("graph.encoded_values", "surface").setProfiles(Arrays.asList(// give strange profile names to ensure that we do not mix vehicle and profile:
new CustomProfile("car_custom").setCustomModel(new CustomModel()).setVehicle("car"), new Profile("foot_profile").setVehicle("foot").setWeighting("fastest"), new CustomProfile("foot_custom").setCustomModel(new CustomModel()).setVehicle("foot"))).setLMProfiles(Arrays.asList(new LMProfile("car_custom"), new LMProfile("foot_custom")));
return config;
}
use of com.graphhopper.routing.weighting.custom.CustomProfile 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.routing.weighting.custom.CustomProfile in project graphhopper by graphhopper.
the class GraphHopperTest method testImportCloseAndLoad.
private void testImportCloseAndLoad(boolean ch, boolean lm, boolean sort, boolean custom) {
final String vehicle = "foot";
final String profileName = "profile";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setStoreOnFlush(true).setSortGraph(sort);
Profile profile = new Profile(profileName).setVehicle(vehicle).setWeighting("fastest");
if (custom) {
JsonFeature area51Feature = new JsonFeature();
area51Feature.setGeometry(new GeometryFactory().createPolygon(new Coordinate[] { new Coordinate(7.4174, 43.7345), new Coordinate(7.4198, 43.7355), new Coordinate(7.4207, 43.7344), new Coordinate(7.4174, 43.7345) }));
CustomModel customModel = new CustomModel().setDistanceInfluence(0);
customModel.getPriority().add(Statement.If("in_area51", Statement.Op.MULTIPLY, 0.1));
customModel.getAreas().put("area51", area51Feature);
profile = new CustomProfile(profileName).setCustomModel(customModel).setVehicle(vehicle);
}
hopper.setProfiles(profile);
if (ch) {
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profileName));
}
if (lm) {
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profileName));
}
hopper.importAndClose();
hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(profile).setStoreOnFlush(true).setAllowWrites(false);
if (ch) {
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profileName));
}
if (lm) {
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profileName));
}
hopper.importOrLoad();
if (ch) {
GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName);
req.putHint(CH.DISABLE, false);
req.putHint(Landmark.DISABLE, true);
GHResponse rsp = hopper.route(req);
ResponsePath bestPath = rsp.getBest();
long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
assertNotEquals(sum, 0);
assertTrue(sum < 155, "Too many nodes visited " + sum);
assertEquals(3535, bestPath.getDistance(), 1);
assertEquals(115, bestPath.getPoints().size());
}
if (lm) {
GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName).setAlgorithm(Parameters.Algorithms.ASTAR_BI);
req.putHint(CH.DISABLE, true);
req.putHint(Landmark.DISABLE, false);
GHResponse rsp = hopper.route(req);
ResponsePath bestPath = rsp.getBest();
long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
assertNotEquals(sum, 0);
assertTrue(sum < 125, "Too many nodes visited " + sum);
assertEquals(3535, bestPath.getDistance(), 1);
assertEquals(115, bestPath.getPoints().size());
}
// flexible
GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName);
req.putHint(CH.DISABLE, true);
req.putHint(Landmark.DISABLE, true);
GHResponse rsp = hopper.route(req);
ResponsePath bestPath = rsp.getBest();
long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
assertNotEquals(sum, 0);
assertTrue(sum > 120, "Too few nodes visited " + sum);
assertEquals(3535, bestPath.getDistance(), 1);
assertEquals(115, bestPath.getPoints().size());
hopper.close();
}
Aggregations