Search in sources :

Example 61 with Profile

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

the class GraphHopperTest method testCHOnOffWithTurnCosts.

@Test
public void testCHOnOffWithTurnCosts() {
    final String profile = "my_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(true)).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.importOrLoad();
    GHRequest req = new GHRequest(55.813357, 37.5958585, 55.811042, 37.594689);
    req.setProfile("my_car");
    // with CH
    req.putHint(CH.DISABLE, true);
    GHResponse rsp1 = hopper.route(req);
    assertEquals(1044, rsp1.getBest().getDistance(), 1);
    // without CH
    req.putHint(CH.DISABLE, false);
    GHResponse rsp2 = hopper.route(req);
    assertEquals(1044, rsp2.getBest().getDistance(), 1);
    // just a quick check that we did not run the same algorithm twice
    assertNotEquals(rsp1.getHints().getInt("visited_nodes.sum", -1), rsp2.getHints().getInt("visited_nodes.sum", -1));
}
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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with Profile

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

the class GraphHopperTest method testNorthBayreuthBlockedEdges.

@Test
public void testNorthBayreuthBlockedEdges() {
    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.985272, 11.506151, 49.986107, 11.507202).setProfile(profile);
    GHResponse rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(122, rsp.getBest().getDistance(), 1);
    // block point 49.985759,11.50687
    req.putHint(Routing.BLOCK_AREA, "49.985759,11.50687");
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(365, rsp.getBest().getDistance(), 1);
    req = new GHRequest(49.975845, 11.522598, 50.026821, 11.497364).setProfile(profile);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(6685, rsp.getBest().getDistance(), 1);
    // block by area
    String someArea = "49.97986,11.472902,50.003946,11.534357";
    req.putHint(Routing.BLOCK_AREA, someArea);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(13988, rsp.getBest().getDistance(), 1);
    // Add blocked point to above area, to increase detour
    req.putHint(Routing.BLOCK_AREA, "50.017578,11.547527;" + someArea);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(14601, rsp.getBest().getDistance(), 1);
    // block by edge IDs -> i.e. use small circular area
    req.putHint(Routing.BLOCK_AREA, "49.979929,11.520066,200");
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(12173, rsp.getBest().getDistance(), 1);
    req.putHint(Routing.BLOCK_AREA, "49.980868,11.516397,150");
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(12173, rsp.getBest().getDistance(), 1);
    // block by edge IDs -> i.e. use small rectangular area
    req.putHint(Routing.BLOCK_AREA, "49.981875,11.515818,49.979522,11.521407");
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(12173, rsp.getBest().getDistance(), 1);
    // blocking works for all weightings
    req = new GHRequest(50.009504, 11.490669, 50.024726, 11.496162).setProfile(profile);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(1807, rsp.getBest().getDistance(), 1);
    req.putHint(Routing.BLOCK_AREA, "50.018277,11.492336");
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(3363, rsp.getBest().getDistance(), 1);
    // query point and snapped point are different => block snapped point only => show that block_area changes lookup
    req = new GHRequest(49.984465, 11.507009, 49.986107, 11.507202).setProfile(profile);
    rsp = hopper.route(req);
    assertEquals(11.506, rsp.getBest().getWaypoints().getLon(0), 0.001);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(155, rsp.getBest().getDistance(), 10);
    req.putHint(Routing.BLOCK_AREA, "49.984434,11.505212,49.985394,11.506333");
    rsp = hopper.route(req);
    assertEquals(11.508, rsp.getBest().getWaypoints().getLon(0), 0.001);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(1185, rsp.getBest().getDistance(), 10);
    // first point is contained in block_area => error
    req = new GHRequest(49.979, 11.516, 49.986107, 11.507202).setProfile(profile);
    req.putHint(Routing.BLOCK_AREA, "49.981875,11.515818,49.979522,11.521407");
    rsp = hopper.route(req);
    assertTrue(rsp.hasErrors(), "expected errors");
}
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 63 with Profile

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

the class GraphHopperTest method testFlexMode_631.

@Test
public void testFlexMode_631() {
    final String profile = "car_profile";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profile).setMaximumLMWeight(2000));
    hopper.importOrLoad();
    GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profile);
    // request speed mode
    req.putHint(Landmark.DISABLE, true);
    req.putHint(CH.DISABLE, false);
    GHResponse rsp = hopper.route(req);
    long chSum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertTrue(chSum < 70, "Too many visited nodes for ch mode " + chSum);
    ResponsePath bestPath = rsp.getBest();
    assertEquals(3587, bestPath.getDistance(), 1);
    assertEquals(91, bestPath.getPoints().size());
    // request flex mode
    req.setAlgorithm(Parameters.Algorithms.ASTAR_BI);
    req.putHint(Landmark.DISABLE, true);
    req.putHint(CH.DISABLE, true);
    rsp = hopper.route(req);
    long flexSum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertTrue(flexSum > 60, "Too few visited nodes for flex mode " + flexSum);
    bestPath = rsp.getBest();
    assertEquals(3587, bestPath.getDistance(), 1);
    assertEquals(91, bestPath.getPoints().size());
    // request hybrid mode
    req.putHint(Landmark.DISABLE, false);
    req.putHint(CH.DISABLE, true);
    rsp = hopper.route(req);
    long hSum = rsp.getHints().getLong("visited_nodes.sum", 0);
    // hybrid is better than CH: 40 vs. 42 !
    assertTrue(hSum != chSum, "Visited nodes for hybrid mode should be different to CH but " + hSum + "==" + chSum);
    assertTrue(hSum < flexSum, "Too many visited nodes for hybrid mode " + hSum + ">=" + flexSum);
    bestPath = rsp.getBest();
    assertEquals(3587, bestPath.getDistance(), 1);
    assertEquals(91, bestPath.getPoints().size());
// note: combining hybrid & speed mode is currently not possible and should be avoided: #1082
}
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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with Profile

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

the class GraphHopperTest method testMonacoNonChMaxWaypointDistanceMultiplePoints.

@Test
public void testMonacoNonChMaxWaypointDistanceMultiplePoints() {
    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();
    GHPoint from = new GHPoint(43.741069, 7.426854);
    GHPoint via = new GHPoint(43.744445, 7.429483);
    GHPoint to = new GHPoint(43.727697, 7.419199);
    GHRequest req = new GHRequest().setPoints(Arrays.asList(from, via, to)).setProfile(profile);
    // Fail since points are too far
    hopper.getRouterConfig().setNonChMaxWaypointDistance(1000);
    GHResponse rsp = hopper.route(req);
    assertTrue(rsp.hasErrors());
    String errorString = rsp.getErrors().toString();
    assertTrue(errorString.contains("Point 2 is too far from Point 1"), errorString);
    PointDistanceExceededException exception = (PointDistanceExceededException) rsp.getErrors().get(0);
    assertEquals(1, exception.getDetails().get("from"));
    assertEquals(2, exception.getDetails().get("to"));
    // Succeed since points are not far anymore
    hopper.getRouterConfig().setNonChMaxWaypointDistance(Integer.MAX_VALUE);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
}
Also used : PointDistanceExceededException(com.graphhopper.util.exceptions.PointDistanceExceededException) 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 65 with Profile

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

the class GraphHopperTest method testAlternativeRoutesBike.

@Test
public void testAlternativeRoutesBike() {
    final String profile = "profile";
    final String vehicle = "bike";
    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(50.028917, 11.496506, 49.985228, 11.600876).setAlgorithm(ALT_ROUTE).setProfile(profile);
    req.putHint("alternative_route.max_paths", 3);
    GHResponse rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(3, rsp.getAll().size());
    // via ramsenthal
    assertEquals(2865, rsp.getAll().get(0).getTime() / 1000);
    // via unterwaiz
    assertEquals(3318, rsp.getAll().get(1).getTime() / 1000);
    // via eselslohe -> theta; BTW: here smaller time as 2nd alternative due to priority influences time order
    assertEquals(3093, rsp.getAll().get(2).getTime() / 1000);
}
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)

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