Search in sources :

Example 31 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class MapMatchingResourceTurnCostsTest method createConfig.

private static GraphHopperServerConfiguration createConfig() {
    GraphHopperServerConfiguration config = new GraphHopperServerConfiguration();
    config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car|turn_costs=true,bike").putObject("datareader.file", "../map-matching/files/leipzig_germany.osm.pbf").putObject("graph.location", DIR).setProfiles(Arrays.asList(new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(true), new Profile("car_no_tc").setVehicle("car").setWeighting("fastest"), new Profile("bike").setVehicle("bike").setWeighting("fastest"))).setLMProfiles(Arrays.asList(new LMProfile("car"), new LMProfile("bike"), new LMProfile("car_no_tc").setPreparationProfile("car"))).setCHProfiles(Collections.singletonList(new CHProfile("car_no_tc")));
    return config;
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GraphHopperServerConfiguration(com.graphhopper.application.GraphHopperServerConfiguration) LMProfile(com.graphhopper.config.LMProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile)

Example 32 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class RouteResourceCustomModelLMTest method createConfig.

private static GraphHopperServerConfiguration createConfig() {
    GraphHopperServerConfiguration config = new GraphHopperServerTestConfiguration();
    config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car,foot").putObject("datareader.file", "../core/files/andorra.osm.pbf").putObject("graph.location", DIR).putObject("graph.encoded_values", "surface").setProfiles(Arrays.asList(// give strange profile names to ensure that we do not mix vehicle and profile:
    new CustomProfile("car_custom").setCustomModel(new CustomModel()).setVehicle("car"), new Profile("foot_profile").setVehicle("foot").setWeighting("fastest"), new CustomProfile("foot_custom").setCustomModel(new CustomModel()).setVehicle("foot"))).setLMProfiles(Arrays.asList(new LMProfile("car_custom"), new LMProfile("foot_custom")));
    return config;
}
Also used : GraphHopperServerConfiguration(com.graphhopper.application.GraphHopperServerConfiguration) GraphHopperServerTestConfiguration(com.graphhopper.application.util.GraphHopperServerTestConfiguration) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) LMProfile(com.graphhopper.config.LMProfile) CustomModel(com.graphhopper.util.CustomModel) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile)

Example 33 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class RouteResourceTurnCostsLegacyTest method createConfig.

private static GraphHopperServerConfiguration createConfig() {
    GraphHopperServerConfiguration config = new GraphHopperServerTestConfiguration();
    config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car|turn_costs=true").putObject("prepare.min_network_size", 0).putObject("datareader.file", "../core/files/moscow.osm.gz").putObject("graph.encoded_values", "road_class,surface,road_environment,max_speed").putObject("graph.location", DIR).setProfiles(Arrays.asList(new Profile("my_car_turn_costs").setVehicle("car").setWeighting("fastest").setTurnCosts(true), new Profile("my_car_no_turn_costs").setVehicle("car").setWeighting("fastest").setTurnCosts(false))).setCHProfiles(Arrays.asList(new CHProfile("my_car_turn_costs"), new CHProfile("my_car_no_turn_costs"))).setLMProfiles(Arrays.asList(new LMProfile("my_car_no_turn_costs"), // no need for a second LM preparation: we can just cross query here
    new LMProfile("my_car_turn_costs").setPreparationProfile("my_car_no_turn_costs")));
    return config;
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GraphHopperServerConfiguration(com.graphhopper.application.GraphHopperServerConfiguration) GraphHopperServerTestConfiguration(com.graphhopper.application.util.GraphHopperServerTestConfiguration) LMProfile(com.graphhopper.config.LMProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile)

Example 34 with LMProfile

use of com.graphhopper.config.LMProfile 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)

Example 35 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class GraphHopper method checkProfilesConsistency.

private void checkProfilesConsistency() {
    EncodingManager encodingManager = getEncodingManager();
    for (Profile profile : profilesByName.values()) {
        if (!encodingManager.hasEncoder(profile.getVehicle())) {
            throw new IllegalArgumentException("Unknown vehicle '" + profile.getVehicle() + "' in profile: " + profile + ". Make sure all vehicles used in 'profiles' exist in 'graph.flag_encoders'");
        }
        FlagEncoder encoder = encodingManager.getEncoder(profile.getVehicle());
        if (profile.isTurnCosts() && !encoder.supportsTurnCosts()) {
            throw new IllegalArgumentException("The profile '" + profile.getName() + "' was configured with " + "'turn_costs=true', but the corresponding vehicle '" + profile.getVehicle() + "' does not support turn costs." + "\nYou need to add `|turn_costs=true` to the vehicle in `graph.flag_encoders`");
        }
        try {
            createWeighting(profile, new PMap());
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Could not create weighting for profile: '" + profile.getName() + "'.\n" + "Profile: " + profile + "\n" + "Error: " + e.getMessage());
        }
        if (profile instanceof CustomProfile) {
            CustomModel customModel = ((CustomProfile) profile).getCustomModel();
            if (customModel == null)
                throw new IllegalArgumentException("custom model for profile '" + profile.getName() + "' was empty");
            if (!CustomWeighting.NAME.equals(profile.getWeighting()))
                throw new IllegalArgumentException("profile '" + profile.getName() + "' has a custom model but " + "weighting=" + profile.getWeighting() + " was defined");
        }
    }
    Set<String> chProfileSet = new LinkedHashSet<>(chPreparationHandler.getCHProfiles().size());
    for (CHProfile chProfile : chPreparationHandler.getCHProfiles()) {
        boolean added = chProfileSet.add(chProfile.getProfile());
        if (!added) {
            throw new IllegalArgumentException("Duplicate CH reference to profile '" + chProfile.getProfile() + "'");
        }
        if (!profilesByName.containsKey(chProfile.getProfile())) {
            throw new IllegalArgumentException("CH profile references unknown profile '" + chProfile.getProfile() + "'");
        }
    }
    Map<String, LMProfile> lmProfileMap = new LinkedHashMap<>(lmPreparationHandler.getLMProfiles().size());
    for (LMProfile lmProfile : lmPreparationHandler.getLMProfiles()) {
        LMProfile previous = lmProfileMap.put(lmProfile.getProfile(), lmProfile);
        if (previous != null) {
            throw new IllegalArgumentException("Multiple LM profiles are using the same profile '" + lmProfile.getProfile() + "'");
        }
        if (!profilesByName.containsKey(lmProfile.getProfile())) {
            throw new IllegalArgumentException("LM profile references unknown profile '" + lmProfile.getProfile() + "'");
        }
        if (lmProfile.usesOtherPreparation() && !profilesByName.containsKey(lmProfile.getPreparationProfile())) {
            throw new IllegalArgumentException("LM profile references unknown preparation profile '" + lmProfile.getPreparationProfile() + "'");
        }
    }
    for (LMProfile lmProfile : lmPreparationHandler.getLMProfiles()) {
        if (lmProfile.usesOtherPreparation() && !lmProfileMap.containsKey(lmProfile.getPreparationProfile())) {
            throw new IllegalArgumentException("Unknown LM preparation profile '" + lmProfile.getPreparationProfile() + "' in LM profile '" + lmProfile.getProfile() + "' cannot be used as preparation_profile");
        }
        if (lmProfile.usesOtherPreparation() && lmProfileMap.get(lmProfile.getPreparationProfile()).usesOtherPreparation()) {
            throw new IllegalArgumentException("Cannot use '" + lmProfile.getPreparationProfile() + "' as preparation_profile for LM profile '" + lmProfile.getProfile() + "', because it uses another profile for preparation itself.");
        }
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) LMProfile(com.graphhopper.config.LMProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile)

Aggregations

LMProfile (com.graphhopper.config.LMProfile)48 Profile (com.graphhopper.config.Profile)41 CHProfile (com.graphhopper.config.CHProfile)33 Test (org.junit.jupiter.api.Test)24 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)15 PMap (com.graphhopper.util.PMap)12 GraphHopper (com.graphhopper.GraphHopper)10 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)6 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 File (java.io.File)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 Gpx (com.graphhopper.jackson.Gpx)3 EdgeMatch (com.graphhopper.matching.EdgeMatch)3 MapMatching (com.graphhopper.matching.MapMatching)3 MatchResult (com.graphhopper.matching.MatchResult)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3