Search in sources :

Example 26 with LMProfile

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

the class Measurement method createConfigFromArgs.

private GraphHopperConfig createConfigFromArgs(PMap args) {
    GraphHopperConfig ghConfig = new GraphHopperConfig(args);
    String encodingManagerString = args.getString("graph.flag_encoders", "car");
    List<FlagEncoder> tmpEncoders = EncodingManager.create(encodingManagerString).fetchEdgeEncoders();
    if (tmpEncoders.size() != 1) {
        logger.warn("You configured multiple encoders, only the first one is used for the measurements");
    }
    vehicle = tmpEncoders.get(0).toString();
    boolean turnCosts = tmpEncoders.get(0).supportsTurnCosts();
    int uTurnCosts = args.getInt("measurement.u_turn_costs", 40);
    String weighting = args.getString("measurement.weighting", "fastest");
    boolean useCHEdge = args.getBool("measurement.ch.edge", true);
    boolean useCHNode = args.getBool("measurement.ch.node", true);
    boolean useLM = args.getBool("measurement.lm", true);
    String customModelFile = args.getString("measurement.custom_model_file", "");
    List<Profile> profiles = new ArrayList<>();
    if (!customModelFile.isEmpty()) {
        if (!weighting.equals(CustomWeighting.NAME))
            throw new IllegalArgumentException("To make use of a custom model you need to set measurement.weighting to 'custom'");
        // use custom profile(s) as specified in the given custom model file
        CustomModel customModel = loadCustomModel(customModelFile);
        profiles.add(new CustomProfile("profile_no_tc").setCustomModel(customModel).setVehicle(vehicle).setTurnCosts(false));
        if (turnCosts)
            profiles.add(new CustomProfile("profile_tc").setCustomModel(customModel).setVehicle(vehicle).setTurnCosts(true).putHint(U_TURN_COSTS, uTurnCosts));
    } else {
        // use standard profiles
        profiles.add(new Profile("profile_no_tc").setVehicle(vehicle).setWeighting(weighting).setTurnCosts(false));
        if (turnCosts)
            profiles.add(new Profile("profile_tc").setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true).putHint(U_TURN_COSTS, uTurnCosts));
    }
    ghConfig.setProfiles(profiles);
    List<CHProfile> chProfiles = new ArrayList<>();
    if (useCHNode)
        chProfiles.add(new CHProfile("profile_no_tc"));
    if (useCHEdge)
        chProfiles.add(new CHProfile("profile_tc"));
    ghConfig.setCHProfiles(chProfiles);
    List<LMProfile> lmProfiles = new ArrayList<>();
    if (useLM) {
        lmProfiles.add(new LMProfile("profile_no_tc"));
        if (turnCosts)
            // no need for a second LM preparation, we can do cross queries here
            lmProfiles.add(new LMProfile("profile_tc").setPreparationProfile("profile_no_tc"));
    }
    ghConfig.setLMProfiles(lmProfiles);
    return ghConfig;
}
Also used : CHProfile(com.graphhopper.config.CHProfile) IntArrayList(com.carrotsearch.hppc.IntArrayList) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) LMProfile(com.graphhopper.config.LMProfile)

Example 27 with LMProfile

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

the class MiniGraphUI method main.

public static void main(String[] strs) {
    PMap args = PMap.read(strs);
    args.putObject("datareader.file", args.getString("datareader.file", "core/files/monaco.osm.gz"));
    args.putObject("graph.location", args.getString("graph.location", "tools/target/mini-graph-ui-gh"));
    args.putObject("graph.flag_encoders", args.getString("graph.flag_encoders", "car"));
    GraphHopperConfig ghConfig = new GraphHopperConfig(args);
    ghConfig.setProfiles(Arrays.asList(new Profile("profile").setVehicle("car").setWeighting("fastest")));
    ghConfig.setCHProfiles(Arrays.asList(new CHProfile("profile")));
    ghConfig.setLMProfiles(Arrays.asList(new LMProfile("profile")));
    GraphHopper hopper = new GraphHopper().init(ghConfig).importOrLoad();
    boolean debug = args.getBool("minigraphui.debug", false);
    boolean useCH = args.getBool("minigraphui.useCH", false);
    new MiniGraphUI(hopper, debug, useCH).visualize();
}
Also used : CHProfile(com.graphhopper.config.CHProfile) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) GraphHopperConfig(com.graphhopper.GraphHopperConfig)

Example 28 with LMProfile

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

the class RoutingExample method customizableRouting.

public static void customizableRouting(String ghLoc) {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile(ghLoc);
    hopper.setGraphHopperLocation("target/routing-custom-graph-cache");
    hopper.setProfiles(new CustomProfile("car_custom").setCustomModel(new CustomModel()).setVehicle("car"));
    // The hybrid mode uses the "landmark algorithm" and is up to 15x faster than the flexible mode (Dijkstra).
    // Still it is slower than the speed mode ("contraction hierarchies algorithm") ...
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car_custom"));
    hopper.importOrLoad();
    // ... but for the hybrid mode we can customize the route calculation even at request time:
    // 1. a request with default preferences
    GHRequest req = new GHRequest().setProfile("car_custom").addPoint(new GHPoint(42.506472, 1.522475)).addPoint(new GHPoint(42.513108, 1.536005));
    GHResponse res = hopper.route(req);
    if (res.hasErrors())
        throw new RuntimeException(res.getErrors().toString());
    assert Math.round(res.getBest().getTime() / 1000d) == 96;
    // 2. now avoid primary roads and reduce maximum speed, see docs/core/custom-models.md for an in-depth explanation
    // and also the blog posts https://www.graphhopper.com/?s=customizable+routing
    CustomModel model = new CustomModel();
    model.addToPriority(If("road_class == PRIMARY", MULTIPLY, 0.5));
    // unconditional limit to 100km/h
    model.addToPriority(If("true", LIMIT, 100));
    req.setCustomModel(model);
    res = hopper.route(req);
    if (res.hasErrors())
        throw new RuntimeException(res.getErrors().toString());
    assert Math.round(res.getBest().getTime() / 1000d) == 165;
}
Also used : GHRequest(com.graphhopper.GHRequest) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse)

Example 29 with LMProfile

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

the class GraphHopperOSMTest method testMultipleLMPreparationsInParallel.

@Test
public void testMultipleLMPreparationsInParallel() {
    HashMap<String, Integer> landmarkCount = new HashMap<>();
    // try all parallelization modes
    for (int threadCount = 1; threadCount < 6; threadCount++) {
        GraphHopper hopper = new GraphHopper().setStoreOnFlush(false).setProfiles(Arrays.asList(new Profile("car_profile").setVehicle("car").setWeighting("fastest"), new Profile("moto_profile").setVehicle("motorcycle").setWeighting("fastest"), new Profile("mtb_profile").setVehicle("mtb").setWeighting("fastest"), new Profile("bike_profile").setVehicle("racingbike").setWeighting("fastest"), new Profile("foot_profile").setVehicle("foot").setWeighting("fastest"))).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
        hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car_profile"), new LMProfile("moto_profile"), new LMProfile("mtb_profile"), new LMProfile("bike_profile"), new LMProfile("foot_profile")).setPreparationThreads(threadCount);
        hopper.importOrLoad();
        assertEquals(5, hopper.getLandmarks().size());
        for (Map.Entry<String, LandmarkStorage> landmarks : hopper.getLandmarks().entrySet()) {
            String name = landmarks.getKey();
            Integer landmarksCount = landmarkCount.get(name);
            if (landmarksCount == null)
                landmarkCount.put(name, landmarks.getValue().getSubnetworksWithLandmarks());
            else
                assertEquals((int) landmarksCount, landmarks.getValue().getSubnetworksWithLandmarks());
            String keyError = Parameters.Landmark.PREPARE + "error." + name;
            String valueError = hopper.getGraphHopperStorage().getProperties().get(keyError);
            assertTrue(valueError.isEmpty(), "Properties for " + name + " should NOT contain error " + valueError + " [" + threadCount + "]");
            String key = Parameters.Landmark.PREPARE + "date." + name;
            String value = hopper.getGraphHopperStorage().getProperties().get(key);
            assertFalse(value.isEmpty(), "Properties for " + name + " did NOT contain finish date [" + threadCount + "]");
        }
        hopper.close();
    }
}
Also used : LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) LMProfile(com.graphhopper.config.LMProfile) GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Example 30 with LMProfile

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

the class ProfileResolverTest method defaultWeighting.

@Test
public void defaultWeighting() {
    ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("bike,car,foot"), Arrays.asList(new Profile("fast_bike").setVehicle("bike").setWeighting("fastest"), new Profile("short_bike").setVehicle("bike").setWeighting("shortest")), Collections.<CHProfile>emptyList(), Collections.<LMProfile>emptyList());
    // without specifying the weighting we get an error, because there are multiple matches
    assertMultiMatchError(profileResolver, new PMap(), "There are multiple profiles matching your request");
    // use weighting to specify profile
    assertEquals("short_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "shortest")).getName());
    assertEquals("fast_bike", profileResolver.resolveProfile(new PMap().putObject("weighting", "fastest")).getName());
}
Also used : PMap(com.graphhopper.util.PMap) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) CHProfileSelectorTest(com.graphhopper.routing.ch.CHProfileSelectorTest) LMProfileSelectorTest(com.graphhopper.routing.lm.LMProfileSelectorTest)

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