Search in sources :

Example 1 with Landmark

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));
    }
}
Also used : com.graphhopper.routing.ev(com.graphhopper.routing.ev) RoundTrip(com.graphhopper.util.Parameters.Algorithms.RoundTrip) com.graphhopper.routing(com.graphhopper.routing) LoggerFactory(org.slf4j.LoggerFactory) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) DirectoryStream(java.nio.file.DirectoryStream) JtsModule(com.bedatadriven.jackson.datatype.jts.JtsModule) LMConfig(com.graphhopper.routing.lm.LMConfig) Path(java.nio.file.Path) DateFormat(java.text.DateFormat) DefaultTagParserFactory(com.graphhopper.routing.util.parsers.DefaultTagParserFactory) PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) Landmark(com.graphhopper.util.Parameters.Landmark) Helper(com.graphhopper.util.Helper) PrepareRoutingSubnetworks(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) com.graphhopper.reader.dem(com.graphhopper.reader.dem) UncheckedIOException(java.io.UncheckedIOException) GHUtility.readCountries(com.graphhopper.util.GHUtility.readCountries) com.graphhopper.routing.util(com.graphhopper.routing.util) LMProfile(com.graphhopper.config.LMProfile) java.util(java.util) CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Routing(com.graphhopper.util.Parameters.Routing) PrepareJob(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepareJob) CHPreparationHandler(com.graphhopper.routing.ch.CHPreparationHandler) Profile(com.graphhopper.config.Profile) OSMReader(com.graphhopper.reader.osm.OSMReader) com.graphhopper.storage(com.graphhopper.storage) DateRangeParser(com.graphhopper.reader.osm.conditional.DateRangeParser) com.graphhopper.util(com.graphhopper.util) Logger(org.slf4j.Logger) LocationIndex(com.graphhopper.storage.index.LocationIndex) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) CHProfile(com.graphhopper.config.CHProfile) File(java.io.File) TagParserFactory(com.graphhopper.routing.util.parsers.TagParserFactory) LMPreparationHandler(com.graphhopper.routing.lm.LMPreparationHandler) Paths(java.nio.file.Paths) PrepareLandmarks(com.graphhopper.routing.lm.PrepareLandmarks) Weighting(com.graphhopper.routing.weighting.Weighting) CustomWeighting(com.graphhopper.routing.weighting.custom.CustomWeighting) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) BufferedReader(java.io.BufferedReader) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) PrepareLandmarks(com.graphhopper.routing.lm.PrepareLandmarks) LMProfile(com.graphhopper.config.LMProfile) LMConfig(com.graphhopper.routing.lm.LMConfig)

Aggregations

JtsModule (com.bedatadriven.jackson.datatype.jts.JtsModule)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CHProfile (com.graphhopper.config.CHProfile)1 LMProfile (com.graphhopper.config.LMProfile)1 Profile (com.graphhopper.config.Profile)1 com.graphhopper.reader.dem (com.graphhopper.reader.dem)1 OSMReader (com.graphhopper.reader.osm.OSMReader)1 DateRangeParser (com.graphhopper.reader.osm.conditional.DateRangeParser)1 com.graphhopper.routing (com.graphhopper.routing)1 CHPreparationHandler (com.graphhopper.routing.ch.CHPreparationHandler)1 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)1 com.graphhopper.routing.ev (com.graphhopper.routing.ev)1 LMConfig (com.graphhopper.routing.lm.LMConfig)1 LMPreparationHandler (com.graphhopper.routing.lm.LMPreparationHandler)1 LandmarkStorage (com.graphhopper.routing.lm.LandmarkStorage)1 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)1 PrepareRoutingSubnetworks (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks)1 PrepareJob (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepareJob)1 com.graphhopper.routing.util (com.graphhopper.routing.util)1 CountryRuleFactory (com.graphhopper.routing.util.countryrules.CountryRuleFactory)1