Search in sources :

Example 1 with LMConfig

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));
    }
}
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)

Example 2 with LMConfig

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;
}
Also used : Weighting(com.graphhopper.routing.weighting.Weighting) CustomWeighting(com.graphhopper.routing.weighting.custom.CustomWeighting) LMProfile(com.graphhopper.config.LMProfile) LMConfig(com.graphhopper.routing.lm.LMConfig) LMProfile(com.graphhopper.config.LMProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile)

Aggregations

CHProfile (com.graphhopper.config.CHProfile)2 LMProfile (com.graphhopper.config.LMProfile)2 Profile (com.graphhopper.config.Profile)2 LMConfig (com.graphhopper.routing.lm.LMConfig)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)2 CustomWeighting (com.graphhopper.routing.weighting.custom.CustomWeighting)2 JtsModule (com.bedatadriven.jackson.datatype.jts.JtsModule)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)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 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