use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class Measurement method createConfigFromArgs.
private GraphHopperConfig createConfigFromArgs(PMap args) {
GraphHopperConfig ghConfig = new GraphHopperConfig(args);
String encodingManagerString = args.getString("graph.flag_encoders", "car");
List<FlagEncoder> tmpEncoders = EncodingManager.create(encodingManagerString).fetchEdgeEncoders();
if (tmpEncoders.size() != 1) {
logger.warn("You configured multiple encoders, only the first one is used for the measurements");
}
vehicle = tmpEncoders.get(0).toString();
boolean turnCosts = tmpEncoders.get(0).supportsTurnCosts();
int uTurnCosts = args.getInt("measurement.u_turn_costs", 40);
String weighting = args.getString("measurement.weighting", "fastest");
boolean useCHEdge = args.getBool("measurement.ch.edge", true);
boolean useCHNode = args.getBool("measurement.ch.node", true);
boolean useLM = args.getBool("measurement.lm", true);
String customModelFile = args.getString("measurement.custom_model_file", "");
List<Profile> profiles = new ArrayList<>();
if (!customModelFile.isEmpty()) {
if (!weighting.equals(CustomWeighting.NAME))
throw new IllegalArgumentException("To make use of a custom model you need to set measurement.weighting to 'custom'");
// use custom profile(s) as specified in the given custom model file
CustomModel customModel = loadCustomModel(customModelFile);
profiles.add(new CustomProfile("profile_no_tc").setCustomModel(customModel).setVehicle(vehicle).setTurnCosts(false));
if (turnCosts)
profiles.add(new CustomProfile("profile_tc").setCustomModel(customModel).setVehicle(vehicle).setTurnCosts(true).putHint(U_TURN_COSTS, uTurnCosts));
} else {
// use standard profiles
profiles.add(new Profile("profile_no_tc").setVehicle(vehicle).setWeighting(weighting).setTurnCosts(false));
if (turnCosts)
profiles.add(new Profile("profile_tc").setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true).putHint(U_TURN_COSTS, uTurnCosts));
}
ghConfig.setProfiles(profiles);
List<CHProfile> chProfiles = new ArrayList<>();
if (useCHNode)
chProfiles.add(new CHProfile("profile_no_tc"));
if (useCHEdge)
chProfiles.add(new CHProfile("profile_tc"));
ghConfig.setCHProfiles(chProfiles);
List<LMProfile> lmProfiles = new ArrayList<>();
if (useLM) {
lmProfiles.add(new LMProfile("profile_no_tc"));
if (turnCosts)
// no need for a second LM preparation, we can do cross queries here
lmProfiles.add(new LMProfile("profile_tc").setPreparationProfile("profile_no_tc"));
}
ghConfig.setLMProfiles(lmProfiles);
return ghConfig;
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class MiniGraphUI method main.
public static void main(String[] strs) {
PMap args = PMap.read(strs);
args.putObject("datareader.file", args.getString("datareader.file", "core/files/monaco.osm.gz"));
args.putObject("graph.location", args.getString("graph.location", "tools/target/mini-graph-ui-gh"));
args.putObject("graph.flag_encoders", args.getString("graph.flag_encoders", "car"));
GraphHopperConfig ghConfig = new GraphHopperConfig(args);
ghConfig.setProfiles(Arrays.asList(new Profile("profile").setVehicle("car").setWeighting("fastest")));
ghConfig.setCHProfiles(Arrays.asList(new CHProfile("profile")));
ghConfig.setLMProfiles(Arrays.asList(new LMProfile("profile")));
GraphHopper hopper = new GraphHopper().init(ghConfig).importOrLoad();
boolean debug = args.getBool("minigraphui.debug", false);
boolean useCH = args.getBool("minigraphui.useCH", false);
new MiniGraphUI(hopper, debug, useCH).visualize();
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class RoutingExample method customizableRouting.
public static void customizableRouting(String ghLoc) {
GraphHopper hopper = new GraphHopper();
hopper.setOSMFile(ghLoc);
hopper.setGraphHopperLocation("target/routing-custom-graph-cache");
hopper.setProfiles(new CustomProfile("car_custom").setCustomModel(new CustomModel()).setVehicle("car"));
// The hybrid mode uses the "landmark algorithm" and is up to 15x faster than the flexible mode (Dijkstra).
// Still it is slower than the speed mode ("contraction hierarchies algorithm") ...
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car_custom"));
hopper.importOrLoad();
// ... but for the hybrid mode we can customize the route calculation even at request time:
// 1. a request with default preferences
GHRequest req = new GHRequest().setProfile("car_custom").addPoint(new GHPoint(42.506472, 1.522475)).addPoint(new GHPoint(42.513108, 1.536005));
GHResponse res = hopper.route(req);
if (res.hasErrors())
throw new RuntimeException(res.getErrors().toString());
assert Math.round(res.getBest().getTime() / 1000d) == 96;
// 2. now avoid primary roads and reduce maximum speed, see docs/core/custom-models.md for an in-depth explanation
// and also the blog posts https://www.graphhopper.com/?s=customizable+routing
CustomModel model = new CustomModel();
model.addToPriority(If("road_class == PRIMARY", MULTIPLY, 0.5));
// unconditional limit to 100km/h
model.addToPriority(If("true", LIMIT, 100));
req.setCustomModel(model);
res = hopper.route(req);
if (res.hasErrors())
throw new RuntimeException(res.getErrors().toString());
assert Math.round(res.getBest().getTime() / 1000d) == 165;
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testMultipleLMPreparationsInParallel.
@Test
public void testMultipleLMPreparationsInParallel() {
HashMap<String, Integer> landmarkCount = new HashMap<>();
// try all parallelization modes
for (int threadCount = 1; threadCount < 6; threadCount++) {
GraphHopper hopper = new GraphHopper().setStoreOnFlush(false).setProfiles(Arrays.asList(new Profile("car_profile").setVehicle("car").setWeighting("fastest"), new Profile("moto_profile").setVehicle("motorcycle").setWeighting("fastest"), new Profile("mtb_profile").setVehicle("mtb").setWeighting("fastest"), new Profile("bike_profile").setVehicle("racingbike").setWeighting("fastest"), new Profile("foot_profile").setVehicle("foot").setWeighting("fastest"))).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car_profile"), new LMProfile("moto_profile"), new LMProfile("mtb_profile"), new LMProfile("bike_profile"), new LMProfile("foot_profile")).setPreparationThreads(threadCount);
hopper.importOrLoad();
assertEquals(5, hopper.getLandmarks().size());
for (Map.Entry<String, LandmarkStorage> landmarks : hopper.getLandmarks().entrySet()) {
String name = landmarks.getKey();
Integer landmarksCount = landmarkCount.get(name);
if (landmarksCount == null)
landmarkCount.put(name, landmarks.getValue().getSubnetworksWithLandmarks());
else
assertEquals((int) landmarksCount, landmarks.getValue().getSubnetworksWithLandmarks());
String keyError = Parameters.Landmark.PREPARE + "error." + name;
String valueError = hopper.getGraphHopperStorage().getProperties().get(keyError);
assertTrue(valueError.isEmpty(), "Properties for " + name + " should NOT contain error " + valueError + " [" + threadCount + "]");
String key = Parameters.Landmark.PREPARE + "date." + name;
String value = hopper.getGraphHopperStorage().getProperties().get(key);
assertFalse(value.isEmpty(), "Properties for " + name + " did NOT contain finish date [" + threadCount + "]");
}
hopper.close();
}
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class ProfileResolverTest method defaultWeighting.
@Test
public void defaultWeighting() {
ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("bike,car,foot"), Arrays.asList(new Profile("fast_bike").setVehicle("bike").setWeighting("fastest"), new Profile("short_bike").setVehicle("bike").setWeighting("shortest")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
// without specifying the weighting we get an error, because there are multiple matches
assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
// use weighting to specify profile
assertEquals("short_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "shortest")).getName());
assertEquals("fast_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "fastest")).getName());
}
Aggregations