Search in sources :

Example 11 with Profile

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

the class GraphHopperOSMTest method testLoadingLMAndCHProfiles.

@Test
public void testLoadingLMAndCHProfiles() {
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(ghLoc).setOSMFile(testOsm).setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
    hopper.importOrLoad();
    hopper.close();
    // load without problem
    hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
    hopper.setGraphHopperLocation(ghLoc);
    assertTrue(hopper.load());
    hopper.close();
    // problem: changed weighting in profile although LM preparation was enabled
    hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
    hopper.setGraphHopperLocation(ghLoc);
    // do not load CH
    try {
        assertFalse(hopper.load());
        fail("load should fail");
    } catch (Exception ex) {
        assertEquals("LM preparation of car already exists in storage and doesn't match configuration", ex.getMessage());
    } finally {
        hopper.close();
    }
    // problem: changed weighting in profile although CH preparation was enabled
    hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
    hopper.setGraphHopperLocation(ghLoc);
    // do not load LM
    try {
        assertFalse(hopper.load());
        fail("load should fail");
    } catch (Exception ex) {
        assertEquals("CH preparation of car already exists in storage and doesn't match configuration", ex.getMessage());
    } finally {
        hopper.close();
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) 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) Test(org.junit.jupiter.api.Test)

Example 12 with Profile

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

the class GraphHopperOSMTest method testSortedGraph_noCH.

@Test
public void testSortedGraph_noCH() {
    final String profile = "profile";
    final String vehicle = "car";
    final String weighting = "fastest";
    instance = new GraphHopper().setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(false).setSortGraph(true).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
    instance.importOrLoad();
    ResponsePath rsp = instance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile).setAlgorithm(DIJKSTRA_BI)).getBest();
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getPoints().size());
    assertEquals(new GHPoint(51.24921503475044, 9.431716451757769), rsp.getPoints().get(0));
    assertEquals(new GHPoint(52.0, 9.0), rsp.getPoints().get(1));
    assertEquals(new GHPoint(51.199999850988384, 9.39999970197677), rsp.getPoints().get(2));
    GHRequest req = new GHRequest(51.2492152, 9.4317166, 51.2, 9.4);
    req.setProfile(profile);
    boolean old = instance.getEncodingManager().isEnableInstructions();
    req.putHint("instructions", true);
    instance.route(req);
    assertEquals(old, instance.getEncodingManager().isEnableInstructions());
    req.putHint("instructions", false);
    instance.route(req);
    assertEquals(old, instance.getEncodingManager().isEnableInstructions(), "route method should not change instance field");
}
Also used : 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 13 with Profile

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

the class GraphHopperOSMTest method testPrepare.

@Test
public void testPrepare() {
    final String profile = "profile";
    final String vehicle = "car";
    final String weighting = "shortest";
    instance = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
    instance.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    instance.importOrLoad();
    GHResponse rsp = instance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile).setAlgorithm(DIJKSTRA_BI));
    assertFalse(rsp.hasErrors());
    assertEquals(Helper.createPointList(51.249215, 9.431716, 52.0, 9.0, 51.2, 9.4), rsp.getBest().getPoints());
    assertEquals(3, rsp.getBest().getPoints().size());
}
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)

Example 14 with Profile

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

the class GraphHopperOSMTest method testFootOnly.

@Test
public void testFootOnly() {
    // now only footable ways are imported => no A D C and B D E => the other both ways have pillar nodes!
    final String profile = "foot_profile";
    final String vehicle = "foot";
    final String weighting = "fastest";
    instance = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm3);
    instance.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    instance.importOrLoad();
    ((LocationIndexTree) instance.getLocationIndex()).setMaxRegionSearch(300);
    assertEquals(2, instance.getGraphHopperStorage().getNodes());
    assertEquals(2, instance.getGraphHopperStorage().getAllEdges().length());
    // A to E only for foot
    GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.19, 52).setProfile(profile));
    assertFalse(grsp.hasErrors());
    ResponsePath rsp = grsp.getBest();
    // the last points snaps to the edge
    assertEquals(Helper.createPointList(11.1, 50, 10, 51, 11.194015, 51.995013), rsp.getPoints());
}
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) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Test(org.junit.jupiter.api.Test)

Example 15 with Profile

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

the class OSMReaderTest method testRoutingRequestFails_issue665.

@Test
public void testRoutingRequestFails_issue665() {
    GraphHopper hopper = new GraphHopper().setOSMFile(getClass().getResource(file7).getFile()).setProfiles(new Profile("profile1").setVehicle("car").setWeighting("fastest"), new Profile("profile2").setVehicle("motorcycle").setWeighting("curvature")).setGraphHopperLocation(dir);
    hopper.importOrLoad();
    GHRequest req = new GHRequest(48.977277, 8.256896, 48.978876, 8.254884).setProfile("profile2");
    GHResponse ghRsp = hopper.route(req);
    assertFalse(ghRsp.hasErrors(), ghRsp.getErrors().toString());
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) Profile(com.graphhopper.config.Profile) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

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