Search in sources :

Example 56 with Profile

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

the class GraphHopperTest method testNorthBayreuthDestination.

@Test
public void testNorthBayreuthDestination() {
    final String profile = "profile";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(BAYREUTH).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting));
    hopper.importOrLoad();
    GHRequest req = new GHRequest(49.985307, 11.50628, 49.985731, 11.507465).setProfile(profile);
    GHResponse rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(550, rsp.getBest().getDistance(), 1);
}
Also used : 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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 57 with Profile

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

the class GraphHopperTest method connectionNotFound.

@Test
public void connectionNotFound() {
    final String profile = "profile";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(BAYREUTH).setProfiles(new Profile("profile").setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("profile"));
    hopper.setMinNetworkSize(0);
    hopper.importOrLoad();
    // here from and to both snap to small subnetworks that are disconnected from the main graph and
    // since we set min network size to 0 we expect a connection not found error
    GHPoint from = new GHPoint(49.97964, 11.539593);
    GHPoint to = new GHPoint(50.029247, 11.582851);
    GHRequest req = new GHRequest(from, to).setProfile(profile);
    GHResponse res = hopper.route(req);
    assertEquals("[com.graphhopper.util.exceptions.ConnectionNotFoundException: Connection between locations not found]", res.getErrors().toString());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) 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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with Profile

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

the class GraphHopperTest method testMonacoWithInstructions.

@Test
public void testMonacoWithInstructions() {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "shortest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).importOrLoad();
    GHResponse rsp = hopper.route(new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setAlgorithm(ASTAR).setProfile(profile));
    // identify the number of counts to compare with CH foot route
    assertEquals(706, rsp.getHints().getLong("visited_nodes.sum", 0));
    ResponsePath res = rsp.getBest();
    assertEquals(3437.1, res.getDistance(), .1);
    assertEquals(85, res.getPoints().size());
    assertEquals(43.7276852, res.getWaypoints().getLat(0), 1e-7);
    assertEquals(43.7495432, res.getWaypoints().getLat(1), 1e-7);
    InstructionList il = res.getInstructions();
    assertEquals(16, il.size());
    // TODO roundabout fine tuning -> enter + leave roundabout (+ two roundabouts -> is it necessary if we do not leave the street?)
    Translation tr = hopper.getTranslationMap().getWithFallBack(Locale.US);
    assertEquals("continue onto Avenue des Guelfes", il.get(0).getTurnDescription(tr));
    assertEquals("turn slight left onto Avenue des Papalins", il.get(1).getTurnDescription(tr));
    assertEquals("turn sharp right onto Quai Jean-Charles Rey", il.get(4).getTurnDescription(tr));
    assertEquals("turn left", il.get(5).getTurnDescription(tr));
    assertEquals("turn right onto Avenue Albert II", il.get(6).getTurnDescription(tr));
    assertEquals(11, il.get(0).getDistance(), 1);
    assertEquals(96, il.get(1).getDistance(), 1);
    assertEquals(178, il.get(2).getDistance(), 1);
    assertEquals(13, il.get(3).getDistance(), 1);
    assertEquals(10, il.get(4).getDistance(), 1);
    assertEquals(42, il.get(5).getDistance(), 1);
    assertEquals(7, il.get(0).getTime() / 1000);
    assertEquals(69, il.get(1).getTime() / 1000);
    assertEquals(128, il.get(2).getTime() / 1000);
    assertEquals(9, il.get(3).getTime() / 1000);
    assertEquals(7, il.get(4).getTime() / 1000);
    assertEquals(30, il.get(5).getTime() / 1000);
    assertEquals(85, res.getPoints().size());
}
Also used : 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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 59 with Profile

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

the class GraphHopperTest method testCompareAlgos.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testCompareAlgos(boolean turnCosts) {
    final String profile = "car";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MOSCOW).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(turnCosts));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profile));
    hopper.importOrLoad();
    long seed = System.nanoTime();
    Random rnd = new Random(seed);
    for (int i = 0; i < 100; i++) {
        BBox bounds = hopper.getGraphHopperStorage().getBounds();
        double lat1 = bounds.minLat + rnd.nextDouble() * (bounds.maxLat - bounds.minLat);
        double lat2 = bounds.minLat + rnd.nextDouble() * (bounds.maxLat - bounds.minLat);
        double lon1 = bounds.minLon + rnd.nextDouble() * (bounds.maxLon - bounds.minLon);
        double lon2 = bounds.minLon + rnd.nextDouble() * (bounds.maxLon - bounds.minLon);
        GHRequest req = new GHRequest(lat1, lon1, lat2, lon2);
        req.setProfile(profile);
        req.getHints().putObject(CH.DISABLE, false).putObject(Landmark.DISABLE, true);
        ResponsePath pathCH = hopper.route(req).getBest();
        req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, false);
        ResponsePath pathLM = hopper.route(req).getBest();
        req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, true);
        ResponsePath path = hopper.route(req).getBest();
        String failMessage = "seed: " + seed + ", i=" + i;
        assertEquals(path.hasErrors(), pathCH.hasErrors(), failMessage);
        assertEquals(path.hasErrors(), pathLM.hasErrors(), failMessage);
        if (!path.hasErrors()) {
            assertEquals(path.getDistance(), pathCH.getDistance(), 0.1, failMessage);
            assertEquals(path.getDistance(), pathLM.getDistance(), 0.1, failMessage);
            assertEquals(path.getTime(), pathCH.getTime(), failMessage);
            assertEquals(path.getTime(), pathLM.getTime(), failMessage);
        }
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) BBox(com.graphhopper.util.shapes.BBox) 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) GHPoint(com.graphhopper.util.shapes.GHPoint) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 60 with Profile

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

the class GraphHopperTest method testMonacoPathDetails.

@Test
public void testMonacoPathDetails() {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "shortest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).importOrLoad();
    GHRequest request = new GHRequest();
    request.addPoint(new GHPoint(43.727687, 7.418737));
    request.addPoint(new GHPoint(43.74958, 7.436566));
    request.addPoint(new GHPoint(43.727687, 7.418737));
    request.setAlgorithm(ASTAR).setProfile(profile);
    request.setPathDetails(Collections.singletonList(Parameters.Details.AVERAGE_SPEED));
    GHResponse rsp = hopper.route(request);
    ResponsePath res = rsp.getBest();
    Map<String, List<PathDetail>> details = res.getPathDetails();
    assertEquals(1, details.size());
    List<PathDetail> detailList = details.get(Parameters.Details.AVERAGE_SPEED);
    assertEquals(9, detailList.size());
    assertEquals(5.0, detailList.get(0).getValue());
    assertEquals(0, detailList.get(0).getFirst());
    assertEquals(3.0, detailList.get(1).getValue());
    assertEquals(res.getPoints().size() - 1, detailList.get(8).getLast());
}
Also used : PathDetail(com.graphhopper.util.details.PathDetail) Arrays.asList(java.util.Arrays.asList) 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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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