Search in sources :

Example 51 with Profile

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

the class GraphHopperTest method testMonacoStraightVia.

@Test
public void testMonacoStraightVia() {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).importOrLoad();
    GHRequest rq = new GHRequest().addPoint(new GHPoint(43.741069, 7.426854)).addPoint(new GHPoint(43.740371, 7.426946)).addPoint(new GHPoint(43.740794, 7.427294)).setProfile(profile);
    rq.putHint(Routing.PASS_THROUGH, true);
    GHResponse rsp = hopper.route(rq);
    ResponsePath res = rsp.getBest();
    assertEquals(297, res.getDistance(), 5.);
    assertEquals(23, res.getPoints().size());
    // test if start and first point are identical leading to an empty path, #788
    rq = new GHRequest().addPoint(new GHPoint(43.741069, 7.426854)).addPoint(new GHPoint(43.741069, 7.426854)).addPoint(new GHPoint(43.740371, 7.426946)).setProfile(profile);
    rq.putHint(Routing.PASS_THROUGH, true);
    rsp = hopper.route(rq);
    assertEquals(91, rsp.getBest().getDistance(), 5.);
}
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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 52 with Profile

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

the class GraphHopperTest method testMonacoVia.

@Test
public void testMonacoVia() {
    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();
    Translation tr = hopper.getTranslationMap().getWithFallBack(Locale.US);
    GHResponse rsp = hopper.route(new GHRequest().addPoint(new GHPoint(43.727687, 7.418737)).addPoint(new GHPoint(43.74958, 7.436566)).addPoint(new GHPoint(43.727687, 7.418737)).setAlgorithm(ASTAR).setProfile(profile));
    ResponsePath res = rsp.getBest();
    assertEquals(6874.2, res.getDistance(), .1);
    assertEquals(170, res.getPoints().size());
    InstructionList il = res.getInstructions();
    assertEquals(30, il.size());
    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("waypoint 1", il.get(15).getTurnDescription(tr));
    assertEquals(Instruction.U_TURN_UNKNOWN, il.get(16).getSign());
    assertEquals("continue onto Avenue Albert II", il.get(23).getTurnDescription(tr));
    assertEquals("turn left", il.get(24).getTurnDescription(tr));
    assertEquals("turn right onto Quai Jean-Charles Rey", il.get(25).getTurnDescription(tr));
    assertEquals("turn sharp left onto Avenue des Papalins", il.get(26).getTurnDescription(tr));
    assertEquals("turn slight right onto Avenue des Guelfes", il.get(28).getTurnDescription(tr));
    assertEquals("arrive at destination", il.get(29).getTurnDescription(tr));
    assertEquals(11, il.get(0).getDistance(), 1);
    assertEquals(97, 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);
    // special case of identical start and end point
    rsp = hopper.route(new GHRequest().addPoint(new GHPoint(43.727687, 7.418737)).addPoint(new GHPoint(43.727687, 7.418737)).setAlgorithm(ASTAR).setProfile(profile));
    res = rsp.getBest();
    assertEquals(0, res.getDistance(), .1);
    assertEquals(0, res.getRouteWeight(), .1);
    assertEquals(1, res.getPoints().size());
    assertEquals(1, res.getInstructions().size());
    assertEquals("arrive at destination", res.getInstructions().get(0).getTurnDescription(tr));
    assertEquals(Instruction.FINISH, res.getInstructions().get(0).getSign());
    rsp = hopper.route(new GHRequest().setPoints(Arrays.asList(new GHPoint(43.727687, 7.418737), new GHPoint(43.727687, 7.418737), new GHPoint(43.727687, 7.418737))).setAlgorithm(ASTAR).setProfile(profile));
    res = rsp.getBest();
    assertEquals(0, res.getDistance(), .1);
    assertEquals(0, res.getRouteWeight(), .1);
    assertEquals(1, res.getPoints().size());
    assertEquals(2, res.getInstructions().size());
    assertEquals(Instruction.REACHED_VIA, res.getInstructions().get(0).getSign());
    assertEquals(Instruction.FINISH, res.getInstructions().get(1).getSign());
}
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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 53 with Profile

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

the class GraphHopperTest method testOneWaySubnetwork_issue1807.

@Test
public void testOneWaySubnetwork_issue1807() {
    // There is a straight-only turn relation at the junction of Franziskastraße and Gudulastraße, which restricts
    // turning onto Gudulastraße. However, Gudulastraße can also not be accessed from the south/west, because
    // its a one-way. This creates a subnetwork that is not accessible at all. We can only detect this if we
    // consider the turn restrictions during the subnetwork search.
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(ESSEN).setMinNetworkSize(50).setProfiles(new Profile("foot").setVehicle("foot").setWeighting("fastest"), new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(true));
    hopper.importOrLoad();
    GHPoint p = new GHPoint(51.433417, 7.009395);
    GHPoint q = new GHPoint(51.432872, 7.010066);
    GHRequest req = new GHRequest(p, q);
    // using the foot profile we do not care about the turn restriction
    req.setProfile("foot");
    GHResponse rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(95, rsp.getBest().getDistance(), 1);
    // Using the car profile there is no way we can reach the destination and the subnetwork is supposed to be removed
    // such that the destination snaps to a point that can be reached.
    req.setProfile("car");
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(658, rsp.getBest().getDistance(), 1);
}
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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 54 with Profile

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

the class GraphHopperTest method testRoundTour.

@Test
public void testRoundTour() {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).importOrLoad();
    GHRequest rq = new GHRequest().addPoint(new GHPoint(43.741069, 7.426854)).setHeadings(Collections.singletonList(50.)).setProfile(profile).setAlgorithm(ROUND_TRIP);
    rq.putHint(RoundTrip.DISTANCE, 1000);
    rq.putHint(RoundTrip.SEED, 0);
    GHResponse rsp = hopper.route(rq);
    assertEquals(1, rsp.getAll().size());
    ResponsePath res = rsp.getBest();
    assertEquals(1.49, rsp.getBest().getDistance() / 1000f, .01);
    assertEquals(19, rsp.getBest().getTime() / 1000f / 60, 1);
    assertEquals(66, res.getPoints().size());
}
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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 55 with Profile

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

the class GraphHopperTest method testSRTMWithInstructions.

@Test
public void testSRTMWithInstructions() {
    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);
    hopper.setElevationProvider(new SRTMProvider(DIR));
    hopper.importOrLoad();
    GHResponse rsp = hopper.route(new GHRequest(43.730729, 7.421288, 43.727697, 7.419199).setAlgorithm(ASTAR).setProfile(profile));
    ResponsePath res = rsp.getBest();
    assertEquals(1614.3, res.getDistance(), .1);
    assertEquals(55, res.getPoints().size());
    assertTrue(res.getPoints().is3D());
    InstructionList il = res.getInstructions();
    assertEquals(12, il.size());
    assertTrue(il.get(0).getPoints().is3D());
    String str = res.getPoints().toString();
    assertEquals("(43.730684662577524,7.421283725164733,62.0), (43.7306797,7.4213823,66.0), " + "(43.731098,7.4215463,45.0), (43.7312991,7.42159,45.0), (43.7313271,7.4214147,45.0), " + "(43.7312506,7.4213664,45.0), (43.7312822,7.4211156,52.0), (43.7313624,7.4211455,52.0), " + "(43.7313714,7.4211233,52.0), (43.7314858,7.4211734,52.0), (43.7315753,7.4208688,52.0), " + "(43.7316061,7.4208249,52.0), (43.7316404,7.4208503,52.0), (43.7316741,7.4210502,52.0), " + "(43.7316276,7.4214636,45.0), (43.7316391,7.4215065,45.0), (43.7316664,7.4214904,45.0), " + "(43.7317185,7.4211861,52.0), (43.7319676,7.4206159,19.0), (43.732038,7.4203936,20.0), " + "(43.7322266,7.4196414,26.0), (43.7323236,7.4192656,26.0), (43.7323374,7.4190461,26.0), " + "(43.7323875,7.4189195,26.0), (43.731974,7.4181688,29.0), (43.7316421,7.4173042,23.0), " + "(43.7315686,7.4170356,31.0), (43.7314269,7.4166815,31.0), (43.7312401,7.4163184,49.0), " + "(43.7308286,7.4157613,29.399999618530273), (43.730662,7.4155599,22.0), " + "(43.7303643,7.4151193,51.0), (43.729579,7.4137274,40.0), (43.7295167,7.4137244,40.0), " + "(43.7294669,7.4137725,40.0), (43.7285987,7.4149068,23.0), (43.7285167,7.4149272,22.0), " + "(43.7283974,7.4148646,22.0), (43.7285619,7.4151365,23.0), (43.7285774,7.4152444,23.0), " + "(43.7285763,7.4159759,21.0), (43.7285238,7.4161982,20.0), (43.7284592,7.4163655,18.0), " + "(43.7281669,7.4168192,18.0), (43.7281442,7.4169449,18.0), (43.7281684,7.4172435,14.0), " + "(43.7282784,7.4179606,14.0), (43.7282757,7.418175,11.0), (43.7282319,7.4183683,11.0), " + "(43.7281482,7.4185473,11.0), (43.7280654,7.4186535,11.0), (43.7279259,7.418748,11.0), " + "(43.727779,7.4187731,11.0), (43.7276825,7.4190072,11.0), " + "(43.72767974015672,7.419198523220426,11.0)", str);
    assertEquals(84, res.getAscend(), 1e-1);
    assertEquals(135, res.getDescend(), 1e-1);
    assertEquals(55, res.getPoints().size());
    assertEquals(new GHPoint3D(43.73068455771767, 7.421283689825812, 62.0), res.getPoints().get(0));
    assertEquals(new GHPoint3D(43.727679637988224, 7.419198521975086, 11.0), res.getPoints().get(res.getPoints().size() - 1));
    assertEquals(62, res.getPoints().get(0).getEle(), 1e-2);
    assertEquals(66, res.getPoints().get(1).getEle(), 1e-2);
    assertEquals(52, res.getPoints().get(10).getEle(), 1e-2);
}
Also used : GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider) 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