Search in sources :

Example 96 with Profile

use of com.graphhopper.config.Profile 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 97 with Profile

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

the class GraphHopperStorageTest method testLoadGraph_implicitEncodedValues_issue1862.

@Test
public void testLoadGraph_implicitEncodedValues_issue1862() {
    Helper.removeDir(new File(defaultGraphLoc));
    encodingManager = new EncodingManager.Builder().add(createCarFlagEncoder()).add(new BikeFlagEncoder()).build();
    graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), false).create(defaultSize);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 8, 13);
    na.setNode(2, 2, 10);
    na.setNode(3, 5, 9);
    GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 2).setDistance(10));
    GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 3).setDistance(10));
    int nodes = graph.getNodes();
    int edges = graph.getAllEdges().length();
    graph.flush();
    Helper.close(graph);
    // load without configured FlagEncoders
    GraphHopper hopper = new GraphHopper();
    hopper.setProfiles(Arrays.asList(new Profile("p_car").setVehicle("car").setWeighting("fastest"), new Profile("p_bike").setVehicle("bike").setWeighting("fastest")));
    hopper.setGraphHopperLocation(defaultGraphLoc);
    assertTrue(hopper.load());
    graph = hopper.getGraphHopperStorage();
    assertEquals(nodes, graph.getNodes());
    assertEquals(edges, graph.getAllEdges().length());
    Helper.close(graph);
    hopper = new GraphHopper();
    // load via explicitly configured FlagEncoders then we can define only one profile
    hopper.getEncodingManagerBuilder().add(createCarFlagEncoder()).add(new BikeFlagEncoder());
    hopper.setProfiles(Collections.singletonList(new Profile("p_car").setVehicle("car").setWeighting("fastest")));
    hopper.setGraphHopperLocation(defaultGraphLoc);
    assertTrue(hopper.load());
    graph = hopper.getGraphHopperStorage();
    assertEquals(nodes, graph.getNodes());
    assertEquals(edges, graph.getAllEdges().length());
    Helper.close(graph);
    Helper.removeDir(new File(defaultGraphLoc));
}
Also used : BikeFlagEncoder(com.graphhopper.routing.util.BikeFlagEncoder) GraphHopper(com.graphhopper.GraphHopper) File(java.io.File) Profile(com.graphhopper.config.Profile) Test(org.junit.jupiter.api.Test)

Example 98 with Profile

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

the class GraphHopperStorageLMTest method testLoad.

@Test
public void testLoad() {
    String defaultGraphLoc = "./target/ghstorage_lm";
    Helper.removeDir(new File(defaultGraphLoc));
    CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager.Builder().add(carFlagEncoder).add(Subnetwork.create("my_profile")).build();
    GraphHopperStorage graph = GraphBuilder.start(encodingManager).setRAM(defaultGraphLoc, true).create();
    // 0-1
    ReaderWay way_0_1 = new ReaderWay(27l);
    way_0_1.setTag("highway", "primary");
    way_0_1.setTag("maxheight", "4.4");
    GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(0, 1).setDistance(1));
    updateDistancesFor(graph, 0, 0.00, 0.00);
    updateDistancesFor(graph, 1, 0.01, 0.01);
    graph.getEdgeIteratorState(0, 1).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_0_1));
    // 1-2
    ReaderWay way_1_2 = new ReaderWay(28l);
    way_1_2.setTag("highway", "primary");
    way_1_2.setTag("maxweight", "45");
    GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(1, 2).setDistance(1));
    updateDistancesFor(graph, 2, 0.02, 0.02);
    graph.getEdgeIteratorState(1, 2).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_1_2));
    graph.flush();
    graph.close();
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    // does lm preparation
    hopper.importOrLoad();
    EncodingManager em = hopper.getEncodingManager();
    assertNotNull(em);
    assertEquals(1, em.fetchEdgeEncoders().size());
    assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
    hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    // just loads the LM data
    hopper.importOrLoad();
    assertEquals(1, em.fetchEdgeEncoders().size());
    assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) LMProfile(com.graphhopper.config.LMProfile) ReaderWay(com.graphhopper.reader.ReaderWay) GraphHopper(com.graphhopper.GraphHopper) File(java.io.File) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test)

Example 99 with Profile

use of com.graphhopper.config.Profile 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 100 with Profile

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

the class RealtimeIT method init.

@BeforeAll
public static void init() {
    GraphHopperConfig ghConfig = new GraphHopperConfig();
    ghConfig.putObject("gtfs.file", "files/sample-feed");
    ghConfig.putObject("graph.location", GRAPH_LOC);
    ghConfig.setProfiles(Arrays.asList(new Profile("foot").setVehicle("foot").setWeighting("fastest"), new Profile("car").setVehicle("car").setWeighting("fastest")));
    Helper.removeDir(new File(GRAPH_LOC));
    graphHopperGtfs = new GraphHopperGtfs(ghConfig);
    graphHopperGtfs.init(ghConfig);
    graphHopperGtfs.importOrLoad();
    graphHopperGtfs.close();
    // Re-load read only
    graphHopperGtfs = new GraphHopperGtfs(ghConfig);
    graphHopperGtfs.init(ghConfig);
    graphHopperGtfs.importOrLoad();
    graphHopperFactory = new PtRouterImpl.Factory(ghConfig, new TranslationMap().doImport(), graphHopperGtfs.getGraphHopperStorage(), graphHopperGtfs.getLocationIndex(), graphHopperGtfs.getGtfsStorage());
}
Also used : GraphHopperGtfs(com.graphhopper.gtfs.GraphHopperGtfs) TranslationMap(com.graphhopper.util.TranslationMap) PtRouterImpl(com.graphhopper.gtfs.PtRouterImpl) File(java.io.File) Profile(com.graphhopper.config.Profile) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Profile (com.graphhopper.config.Profile)203 LMProfile (com.graphhopper.config.LMProfile)167 CHProfile (com.graphhopper.config.CHProfile)164 Test (org.junit.jupiter.api.Test)138 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)84 GraphHopper (com.graphhopper.GraphHopper)54 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)54 GHPoint (com.graphhopper.util.shapes.GHPoint)35 ArrayList (java.util.ArrayList)29 File (java.io.File)25 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)19 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)19 PMap (com.graphhopper.util.PMap)14 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)11 BeforeAll (org.junit.jupiter.api.BeforeAll)10 Weighting (com.graphhopper.routing.weighting.Weighting)9 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)8 TranslationMap (com.graphhopper.util.TranslationMap)7 Snap (com.graphhopper.storage.index.Snap)6 GHRequest (com.graphhopper.GHRequest)5