Search in sources :

Example 16 with CHProfile

use of com.graphhopper.config.CHProfile 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 17 with CHProfile

use of com.graphhopper.config.CHProfile 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 18 with CHProfile

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

the class GraphHopperTest method testCircularJunctionInstructionsWithCH.

@Test
public void testCircularJunctionInstructionsWithCH() {
    String profile1 = "profile1";
    String profile2 = "profile2";
    String vehicle1 = "car";
    String vehicle2 = "bike";
    String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(BERLIN).setProfiles(new Profile(profile1).setVehicle(vehicle1).setWeighting(weighting), new Profile(profile2).setVehicle(vehicle2).setWeighting(weighting)).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile1), new CHProfile(profile2));
    hopper.setMinNetworkSize(0);
    hopper.importOrLoad();
    assertEquals(2, hopper.getCHGraphs().size());
    GHResponse rsp = hopper.route(new GHRequest(52.513505, 13.350443, 52.513505, 13.350245).setProfile(profile1));
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    Instruction instr = rsp.getBest().getInstructions().get(1);
    assertTrue(instr instanceof RoundaboutInstruction);
    assertEquals(5, ((RoundaboutInstruction) instr).getExitNumber());
}
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 19 with CHProfile

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

the class GraphHopperTest method testCurbsides.

@Test
public void testCurbsides() {
    GraphHopper h = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(BAYREUTH).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest").setTurnCosts(true));
    h.getCHPreparationHandler().setCHProfiles(new CHProfile("my_profile"));
    h.importOrLoad();
    // depending on the curbside parameters we take very different routes
    GHPoint p = new GHPoint(50.015072, 11.499145);
    GHPoint q = new GHPoint(50.014141, 11.497552);
    final String itz = "Itzgrund";
    final String rotmain = "An den Rotmainauen";
    final String bayreuth = "Bayreuther Straße, KU 18";
    final String kulmbach = "Kulmbacher Straße, KU 18";
    final String adamSeiler = "Adam-Seiler-Straße";
    final String friedhof = "Friedhofsweg";
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_RIGHT), 344, asList(itz, rotmain, rotmain));
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_RIGHT, CURBSIDE_LEFT), 1564, asList(itz, rotmain, rotmain, bayreuth, adamSeiler, adamSeiler, friedhof, kulmbach, rotmain));
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_RIGHT), 1199, asList(itz, bayreuth, adamSeiler, adamSeiler, friedhof, kulmbach, itz, rotmain, rotmain));
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_LEFT, CURBSIDE_LEFT), 266, asList(itz, bayreuth, rotmain));
    // without restricting anything we get the shortest path
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_ANY, CURBSIDE_ANY), 266, asList(itz, bayreuth, rotmain));
    assertCurbsidesPath(h, p, q, asList(CURBSIDE_ANY, ""), 266, asList(itz, bayreuth, rotmain));
    assertCurbsidesPath(h, p, q, Collections.<String>emptyList(), 266, asList(itz, bayreuth, rotmain));
    // when the start/target is the same its a bit unclear how to interpret the curbside parameters. here we decided
    // to return an empty path if the curbsides of start/target are the same or one of the is not specified
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_RIGHT, CURBSIDE_RIGHT), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_RIGHT, CURBSIDE_ANY), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_RIGHT, ""), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_ANY, CURBSIDE_RIGHT), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList("", CURBSIDE_RIGHT), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_LEFT, CURBSIDE_LEFT), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_LEFT, CURBSIDE_ANY), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_LEFT, ""), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_ANY, CURBSIDE_LEFT), 0, Collections.<String>emptyList());
    assertCurbsidesPath(h, p, p, asList("", CURBSIDE_LEFT), 0, Collections.<String>emptyList());
    // when going from p to p and one curbside is right and the other is left, we expect driving a loop back to
    // where we came from
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_RIGHT, CURBSIDE_LEFT), 1908, asList(itz, rotmain, rotmain, bayreuth, adamSeiler, adamSeiler, friedhof, kulmbach, rotmain, rotmain, itz));
    assertCurbsidesPath(h, p, p, asList(CURBSIDE_LEFT, CURBSIDE_RIGHT), 855, asList(itz, bayreuth, adamSeiler, adamSeiler, friedhof, kulmbach, itz));
}
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 20 with CHProfile

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

the class GraphHopperTest method testMonacoDifferentAlgorithms.

@ParameterizedTest
@CsvSource({ DIJKSTRA + ",false,511", ASTAR + ",false,444", DIJKSTRA_BI + ",false,228", ASTAR_BI + ",false,184", ASTAR_BI + ",true,49", DIJKSTRA_BI + ",true,48" })
public void testMonacoDifferentAlgorithms(String algo, boolean withCH, int expectedVisitedNodes) {
    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.setMinNetworkSize(0);
    hopper.importOrLoad();
    GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setAlgorithm(algo).setProfile("profile");
    req.putHint(CH.DISABLE, !withCH);
    GHResponse rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(expectedVisitedNodes, rsp.getHints().getLong("visited_nodes.sum", 0));
    ResponsePath res = rsp.getBest();
    assertEquals(3586.9, res.getDistance(), .1);
    assertEquals(277112, res.getTime(), 10);
    assertEquals(91, res.getPoints().size());
    assertEquals(43.7276852, res.getWaypoints().getLat(0), 1e-7);
    assertEquals(43.7495432, res.getWaypoints().getLat(1), 1e-7);
}
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) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CHProfile (com.graphhopper.config.CHProfile)66 Profile (com.graphhopper.config.Profile)63 LMProfile (com.graphhopper.config.LMProfile)58 Test (org.junit.jupiter.api.Test)39 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 PMap (com.graphhopper.util.PMap)10 GHPoint (com.graphhopper.util.shapes.GHPoint)9 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)8 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)8 GraphHopper (com.graphhopper.GraphHopper)6 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 CountryRuleFactory (com.graphhopper.routing.util.countryrules.CountryRuleFactory)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 JtsModule (com.bedatadriven.jackson.datatype.jts.JtsModule)1 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1