use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class GraphHopper method loadOrPrepareLM.
/**
* For landmarks it is required to always call this method: either it creates the landmark data or it loads it.
*/
protected void loadOrPrepareLM(boolean closeEarly) {
for (LMProfile profile : lmPreparationHandler.getLMProfiles()) if (!getLMProfileVersion(profile.getProfile()).isEmpty() && !getLMProfileVersion(profile.getProfile()).equals("" + profilesByName.get(profile.getProfile()).getVersion()))
throw new IllegalArgumentException("LM preparation of " + profile.getProfile() + " already exists in storage and doesn't match configuration");
// we load landmark storages that already exist and prepare the other ones
List<LMConfig> lmConfigs = createLMConfigs(lmPreparationHandler.getLMProfiles());
List<LandmarkStorage> loaded = lmPreparationHandler.load(lmConfigs, ghStorage);
List<LMConfig> loadedConfigs = loaded.stream().map(LandmarkStorage::getLMConfig).collect(Collectors.toList());
List<LMConfig> configsToPrepare = lmConfigs.stream().filter(c -> !loadedConfigs.contains(c)).collect(Collectors.toList());
List<PrepareLandmarks> prepared = prepareLM(closeEarly, configsToPrepare);
// we map all profile names for which there is LM support to the according LM storages
landmarks = new LinkedHashMap<>();
for (LMProfile lmp : lmPreparationHandler.getLMProfiles()) {
// cross-querying
String prepProfile = lmp.usesOtherPreparation() ? lmp.getPreparationProfile() : lmp.getProfile();
Optional<LandmarkStorage> loadedLMS = loaded.stream().filter(lms -> lms.getLMConfig().getName().equals(prepProfile)).findFirst();
Optional<PrepareLandmarks> preparedLMS = prepared.stream().filter(pl -> pl.getLandmarkStorage().getLMConfig().getName().equals(prepProfile)).findFirst();
if (loadedLMS.isPresent() && preparedLMS.isPresent())
throw new IllegalStateException("LM should be either loaded or prepared, but not both: " + prepProfile);
else if (preparedLMS.isPresent()) {
setLMProfileVersion(lmp.getProfile(), profilesByName.get(lmp.getProfile()).getVersion());
landmarks.put(lmp.getProfile(), preparedLMS.get().getLandmarkStorage());
} else
loadedLMS.ifPresent(landmarkStorage -> landmarks.put(lmp.getProfile(), landmarkStorage));
}
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testLoadingCustomProfiles.
@Test
public void testLoadingCustomProfiles() {
CustomModel customModel = new CustomModel().setDistanceInfluence(123);
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(ghLoc).setOSMFile(testOsm).setProfiles(new CustomProfile("car").setCustomModel(customModel));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.importOrLoad();
hopper.close();
// load without problem
hopper = new GraphHopper().setProfiles(new CustomProfile("car").setCustomModel(customModel));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.setGraphHopperLocation(ghLoc);
assertTrue(hopper.load());
hopper.close();
// do not load changed CustomModel
customModel.setDistanceInfluence(100);
hopper = new GraphHopper().setProfiles(new CustomProfile("car").setCustomModel(customModel));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.setGraphHopperLocation(ghLoc);
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();
}
}
use of com.graphhopper.config.LMProfile 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.LMProfile in project graphhopper by graphhopper.
the class GraphHopperProfileTest method lmPreparationProfileChain_error.
@Test
public void lmPreparationProfileChain_error() {
final GraphHopper hopper = createHopper();
hopper.setProfiles(new Profile("profile1").setVehicle("car"), new Profile("profile2").setVehicle("bike"), new Profile("profile3").setVehicle("foot"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("profile1"), new LMProfile("profile2").setPreparationProfile("profile1"), new LMProfile("profile3").setPreparationProfile("profile2"));
assertIllegalArgument(hopper::load, "Cannot use 'profile2' as preparation_profile for LM profile 'profile3', because it uses another profile for preparation itself.");
}
use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.
the class ProfileResolverTest method defaultVehicle.
@Test
public void defaultVehicle() {
ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("car,foot,bike"), Arrays.asList(new Profile("my_bike").setVehicle("bike"), new Profile("your_car").setVehicle("car")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
// without specifying the vehicle we get an error, because there are multiple matches
assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
// use vehicle to specify profile
assertEquals("your_car", profileResolver.resolveProfile(new PMap().putObject("vehicle", "car")).getName());
assertEquals("my_bike", profileResolver.resolveProfile(new PMap().putObject("vehicle", "bike")).getName());
}
Aggregations