use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopper method loadOrPrepareCH.
protected void loadOrPrepareCH(boolean closeEarly) {
for (CHProfile profile : chPreparationHandler.getCHProfiles()) if (!getCHProfileVersion(profile.getProfile()).isEmpty() && !getCHProfileVersion(profile.getProfile()).equals("" + profilesByName.get(profile.getProfile()).getVersion()))
throw new IllegalArgumentException("CH preparation of " + profile.getProfile() + " already exists in storage and doesn't match configuration");
// we load ch graphs that already exist and prepare the other ones
List<CHConfig> chConfigs = createCHConfigs(chPreparationHandler.getCHProfiles());
Map<String, RoutingCHGraph> loaded = chPreparationHandler.load(ghStorage, chConfigs);
List<CHConfig> configsToPrepare = chConfigs.stream().filter(c -> !loaded.containsKey(c.getName())).collect(Collectors.toList());
Map<String, PrepareContractionHierarchies.Result> prepared = prepareCH(closeEarly, configsToPrepare);
// we map all profile names for which there is CH support to the according CH graphs
chGraphs = new LinkedHashMap<>();
for (CHProfile profile : chPreparationHandler.getCHProfiles()) {
if (loaded.containsKey(profile.getProfile()) && prepared.containsKey(profile.getProfile()))
throw new IllegalStateException("CH graph should be either loaded or prepared, but not both: " + profile.getProfile());
else if (prepared.containsKey(profile.getProfile())) {
setCHProfileVersion(profile.getProfile(), profilesByName.get(profile.getProfile()).getVersion());
PrepareContractionHierarchies.Result res = prepared.get(profile.getProfile());
chGraphs.put(profile.getProfile(), ghStorage.createCHGraph(res.getCHStorage(), res.getCHConfig()));
} else if (loaded.containsKey(profile.getProfile())) {
chGraphs.put(profile.getProfile(), loaded.get(profile.getProfile()));
} else
throw new IllegalStateException("CH graph should be either loaded or prepared: " + profile.getProfile());
}
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testMultipleCHPreparationsInParallel.
@Test
public void testMultipleCHPreparationsInParallel() {
HashMap<String, Integer> shortcutCountMap = new HashMap<>();
// try all parallelization modes
for (int threadCount = 1; threadCount < 6; threadCount++) {
GraphHopper hopper = new GraphHopper().setStoreOnFlush(false).setProfiles(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.getCHPreparationHandler().setCHProfiles(new CHProfile("car_profile"), new CHProfile("moto_profile"), new CHProfile("mtb_profile"), new CHProfile("bike_profile"), new CHProfile("foot_profile")).setPreparationThreads(threadCount);
hopper.importOrLoad();
assertEquals(5, hopper.getCHGraphs().size());
for (Map.Entry<String, RoutingCHGraph> chGraph : hopper.getCHGraphs().entrySet()) {
String name = chGraph.getKey();
Integer shortcutCount = shortcutCountMap.get(name);
if (shortcutCount == null)
shortcutCountMap.put(name, chGraph.getValue().getShortcuts());
else
assertEquals((long) shortcutCount, chGraph.getValue().getShortcuts());
String keyError = Parameters.CH.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.CH.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.CHProfile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testLoadingLMAndCHProfiles.
@Test
public void testLoadingLMAndCHProfiles() {
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(ghLoc).setOSMFile(testOsm).setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
hopper.importOrLoad();
hopper.close();
// load without problem
hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
hopper.setGraphHopperLocation(ghLoc);
assertTrue(hopper.load());
hopper.close();
// problem: changed weighting in profile although LM preparation was enabled
hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.setGraphHopperLocation(ghLoc);
// do not load CH
try {
assertFalse(hopper.load());
fail("load should fail");
} catch (Exception ex) {
assertEquals("LM preparation of car already exists in storage and doesn't match configuration", ex.getMessage());
} finally {
hopper.close();
}
// problem: changed weighting in profile although CH preparation was enabled
hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
hopper.setGraphHopperLocation(ghLoc);
// do not load LM
try {
assertFalse(hopper.load());
fail("load should fail");
} catch (Exception ex) {
assertEquals("CH preparation of car already exists in storage and doesn't match configuration", ex.getMessage());
} finally {
hopper.close();
}
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testPrepare.
@Test
public void testPrepare() {
final String profile = "profile";
final String vehicle = "car";
final String weighting = "shortest";
instance = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
instance.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
instance.importOrLoad();
GHResponse rsp = instance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile).setAlgorithm(DIJKSTRA_BI));
assertFalse(rsp.hasErrors());
assertEquals(Helper.createPointList(51.249215, 9.431716, 52.0, 9.0, 51.2, 9.4), rsp.getBest().getPoints());
assertEquals(3, rsp.getBest().getPoints().size());
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testFootOnly.
@Test
public void testFootOnly() {
// now only footable ways are imported => no A D C and B D E => the other both ways have pillar nodes!
final String profile = "foot_profile";
final String vehicle = "foot";
final String weighting = "fastest";
instance = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm3);
instance.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
instance.importOrLoad();
((LocationIndexTree) instance.getLocationIndex()).setMaxRegionSearch(300);
assertEquals(2, instance.getGraphHopperStorage().getNodes());
assertEquals(2, instance.getGraphHopperStorage().getAllEdges().length());
// A to E only for foot
GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.19, 52).setProfile(profile));
assertFalse(grsp.hasErrors());
ResponsePath rsp = grsp.getBest();
// the last points snaps to the edge
assertEquals(Helper.createPointList(11.1, 50, 10, 51, 11.194015, 51.995013), rsp.getPoints());
}
Aggregations