Search in sources :

Example 66 with Profile

use of com.graphhopper.config.Profile 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 67 with Profile

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

the class GraphHopperTest method testCrossQuery.

@Test
public void testCrossQuery() {
    final String profile1 = "p1";
    final String profile2 = "p2";
    final String profile3 = "p3";
    final String vehicle = "car";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile1).setVehicle("car").setWeighting("short_fastest").putHint("short_fastest.distance_factor", 0.07), new Profile(profile2).setVehicle("car").setWeighting("short_fastest").putHint("short_fastest.distance_factor", 0.10), new Profile(profile3).setVehicle("car").setWeighting("short_fastest").putHint("short_fastest.distance_factor", 0.15)).setStoreOnFlush(true);
    hopper.getLMPreparationHandler().setLMProfiles(// this works because profile1's weight is the lowest for every edge
    new LMProfile(profile1), new LMProfile(profile2).setPreparationProfile(profile1), new LMProfile(profile3).setPreparationProfile(profile1));
    hopper.setMinNetworkSize(0);
    hopper.importOrLoad();
    // flex
    testCrossQueryAssert(profile1, hopper, 528.3, 166, true);
    testCrossQueryAssert(profile2, hopper, 635.8, 160, true);
    testCrossQueryAssert(profile3, hopper, 815.2, 158, true);
    // LM (should be the same as flex, but with less visited nodes!)
    testCrossQueryAssert(profile1, hopper, 528.3, 74, false);
    testCrossQueryAssert(profile2, hopper, 635.8, 124, false);
    // this is actually interesting: the number of visited nodes *increases* once again (while it strictly decreases
    // with rising distance factor for flex): cross-querying 'works', but performs *worse*, because the landmarks
    // were not customized for the weighting in use. Creating a separate LM preparation for profile3 yields 74
    testCrossQueryAssert(profile3, hopper, 815.2, 162, false);
}
Also used : 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 68 with Profile

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

the class GraphHopperTest method testSRTMWithTunnelInterpolation.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testSRTMWithTunnelInterpolation(boolean withTunnelInterpolation) {
    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);
    if (!withTunnelInterpolation) {
        hopper.getEncodingManagerBuilder().add(new OSMRoadEnvironmentParser() {

            @Override
            public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
                // do not change RoadEnvironment to avoid triggering tunnel interpolation
                return edgeFlags;
            }
        }).addIfAbsent(new DefaultFlagEncoderFactory(), vehicle);
    }
    hopper.setElevationProvider(new SRTMProvider(DIR));
    hopper.importOrLoad();
    GHPoint from = new GHPoint(43.7405647, 7.4299266);
    GHPoint to = new GHPoint(43.7378990, 7.4279780);
    // make sure we hit tower nodes, because all we really want is test the elevation interpolation
    assertEquals(Snap.Position.TOWER, hopper.getLocationIndex().findClosest(from.lat, from.lon, EdgeFilter.ALL_EDGES).getSnappedPosition());
    assertEquals(Snap.Position.TOWER, hopper.getLocationIndex().findClosest(to.lat, to.lon, EdgeFilter.ALL_EDGES).getSnappedPosition());
    GHResponse rsp = hopper.route(new GHRequest(from, to).setProfile(profile));
    ResponsePath res = rsp.getBest();
    PointList pointList = res.getPoints();
    assertEquals(6, pointList.size());
    assertTrue(pointList.is3D());
    if (withTunnelInterpolation) {
        assertEquals(351.8, res.getDistance(), .1);
        assertEquals(17, pointList.getEle(0), .1);
        assertEquals(19.04, pointList.getEle(1), .1);
        assertEquals(21.67, pointList.getEle(2), .1);
        assertEquals(25.03, pointList.getEle(3), .1);
        assertEquals(28.65, pointList.getEle(4), .1);
        assertEquals(34.00, pointList.getEle(5), .1);
    } else {
        assertEquals(358.3, res.getDistance(), .1);
        assertEquals(17.0, pointList.getEle(0), .1);
        assertEquals(23.0, pointList.getEle(1), .1);
        assertEquals(23.0, pointList.getEle(2), .1);
        assertEquals(41.0, pointList.getEle(3), .1);
        assertEquals(19.0, pointList.getEle(4), .1);
        assertEquals(34.0, pointList.getEle(5), .1);
    }
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) 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) OSMRoadEnvironmentParser(com.graphhopper.routing.util.parsers.OSMRoadEnvironmentParser) IntsRef(com.graphhopper.storage.IntsRef) GHPoint(com.graphhopper.util.shapes.GHPoint) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 69 with Profile

use of com.graphhopper.config.Profile 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 70 with Profile

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

the class GraphHopperTest method testKremsCyclewayInstructionsWithWayTypeInfo.

@Test
public void testKremsCyclewayInstructionsWithWayTypeInfo() {
    final String profile1 = "foot_profile";
    final String profile2 = "bike_profile";
    final String vehicle1 = "foot";
    final String vehicle2 = "bike";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(KREMS).setProfiles(new Profile(profile1).setVehicle(vehicle1).setWeighting(weighting), new Profile(profile2).setVehicle(vehicle2).setWeighting(weighting)).setStoreOnFlush(true).importOrLoad();
    Translation tr = hopper.getTranslationMap().getWithFallBack(Locale.US);
    GHResponse rsp = hopper.route(new GHRequest(48.410987, 15.599492, 48.383419, 15.659294).setProfile(profile2));
    assertFalse(rsp.hasErrors());
    ResponsePath res = rsp.getBest();
    assertEquals(6931.8, res.getDistance(), .1);
    assertEquals(103, res.getPoints().size());
    InstructionList il = res.getInstructions();
    assertEquals(19, il.size());
    assertEquals("continue onto Obere Landstraße", il.get(0).getTurnDescription(tr));
    assertEquals(69.28, (Double) il.get(0).getExtraInfoJSON().get("heading"), .01);
    assertEquals("turn left onto Kirchengasse", il.get(1).getTurnDescription(tr));
    assertEquals("turn right onto Pfarrplatz", il.get(2).getTurnDescription(tr));
    assertEquals("turn right onto Margarethenstraße", il.get(3).getTurnDescription(tr));
    assertEquals("keep left onto Hoher Markt", il.get(4).getTurnDescription(tr));
    assertEquals("turn right onto Wegscheid", il.get(6).getTurnDescription(tr));
    assertEquals("turn right onto Ringstraße, L73", il.get(8).getTurnDescription(tr));
    assertEquals("keep left onto Eyblparkstraße", il.get(9).getTurnDescription(tr));
    assertEquals("keep left onto Austraße", il.get(10).getTurnDescription(tr));
    assertEquals("keep left onto Rechte Kremszeile", il.get(11).getTurnDescription(tr));
    // ..
    assertEquals("turn right onto Treppelweg", il.get(15).getTurnDescription(tr));
    // do not return 'get off bike' for foot
    rsp = hopper.route(new GHRequest(48.410987, 15.599492, 48.411172, 15.600371).setAlgorithm(ASTAR).setProfile(profile1));
    assertFalse(rsp.hasErrors());
    il = rsp.getBest().getInstructions();
    assertEquals("continue onto Obere Landstraße", il.get(0).getTurnDescription(tr));
}
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