use of com.graphhopper.routing.lm.LMConfig 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.routing.lm.LMConfig in project graphhopper by graphhopper.
the class GraphHopper method createLMConfigs.
private List<LMConfig> createLMConfigs(List<LMProfile> lmProfiles) {
List<LMConfig> lmConfigs = new ArrayList<>();
for (LMProfile lmProfile : lmProfiles) {
if (lmProfile.usesOtherPreparation())
continue;
Profile profile = profilesByName.get(lmProfile.getProfile());
// Note that we have to make sure the weighting used for LM preparation does not include turn costs, because
// the LM preparation is running node-based and the landmark weights will be wrong if there are non-zero
// turn costs, see discussion in #1960
// Running the preparation without turn costs is also useful to allow e.g. changing the u_turn_costs per
// request (we have to use the minimum weight settings (= no turn costs) for the preparation)
Weighting weighting = createWeighting(profile, new PMap(), true);
lmConfigs.add(new LMConfig(profile.getName(), weighting));
}
return lmConfigs;
}
Aggregations