Search in sources :

Example 31 with CHProfile

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

the class CHProfileSelectorTest method onlyEdgeBasedPresent.

@Test
public void onlyEdgeBasedPresent() {
    List<Profile> profiles = Collections.singletonList(fastCarEdge);
    List<CHProfile> chProfiles = Collections.singletonList(new CHProfile("fast_car_edge"));
    assertCHProfileSelectionError(NO_MATCH_ERROR, profiles, chProfiles, false, null);
    assertCHProfileSelectionError(NO_MATCH_ERROR, profiles, chProfiles, false, 20);
    assertProfileFound(profiles.get(0), profiles, chProfiles, true, null);
    assertProfileFound(profiles.get(0), profiles, chProfiles, null, null);
}
Also used : CHProfile(com.graphhopper.config.CHProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Example 32 with CHProfile

use of com.graphhopper.config.CHProfile 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 33 with CHProfile

use of com.graphhopper.config.CHProfile 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 34 with CHProfile

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

the class RoutingExampleTC method createGraphHopperInstance.

// see RoutingExample for more details
static GraphHopper createGraphHopperInstance(String ghLoc) {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile(ghLoc);
    hopper.setGraphHopperLocation("target/routing-tc-graph-cache");
    // by enabling turn costs for the FlagEncoder, turn restriction constraints like 'no_left_turn' will be taken
    // from OSM
    Profile profile = new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(true).putHint("u_turn_costs", 40);
    hopper.setProfiles(profile);
    // enable CH for our profile. since turn costs are enabled this will take more time and memory to prepare than
    // without turn costs.
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile.getName()));
    hopper.importOrLoad();
    return hopper;
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GraphHopper(com.graphhopper.GraphHopper) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile)

Example 35 with CHProfile

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

the class GraphHopperOSMTest method testLoadOSM.

@Test
public void testLoadOSM() {
    String profile = "car_profile";
    String vehicle = "car";
    String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setStoreOnFlush(true).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.importOrLoad();
    GHResponse rsp = hopper.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().size());
    hopper.close();
    // no encoding manager necessary
    hopper = new GraphHopper().setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.setGraphHopperLocation(ghLoc);
    assertTrue(hopper.load());
    rsp = hopper.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().size());
    hopper.close();
    try {
        rsp = hopper.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
        fail();
    } catch (Exception ex) {
        assertEquals("You need to create a new GraphHopper instance as it is already closed", ex.getMessage());
    }
    try {
        hopper.getLocationIndex().findClosest(51.2492152, 9.4317166, EdgeFilter.ALL_EDGES);
        fail();
    } catch (Exception ex) {
        assertEquals("You need to create a new LocationIndex instance as it is already closed", ex.getMessage());
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) 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)

Aggregations

CHProfile (com.graphhopper.config.CHProfile)66 Profile (com.graphhopper.config.Profile)63 LMProfile (com.graphhopper.config.LMProfile)58 Test (org.junit.jupiter.api.Test)39 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 PMap (com.graphhopper.util.PMap)10 GHPoint (com.graphhopper.util.shapes.GHPoint)9 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)8 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)8 GraphHopper (com.graphhopper.GraphHopper)6 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 CountryRuleFactory (com.graphhopper.routing.util.countryrules.CountryRuleFactory)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 JtsModule (com.bedatadriven.jackson.datatype.jts.JtsModule)1 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1