use of com.graphhopper.util.Parameters.Landmark 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));
}
}
Aggregations