Search in sources :

Example 11 with LMProfile

use of com.graphhopper.config.LMProfile 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 12 with LMProfile

use of com.graphhopper.config.LMProfile 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 13 with LMProfile

use of com.graphhopper.config.LMProfile 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 14 with LMProfile

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

the class MapMatchingTest method setup.

@BeforeAll
public static void setup() {
    Helper.removeDir(new File(GH_LOCATION));
    graphHopper = new GraphHopper();
    graphHopper.setOSMFile("../map-matching/files/leipzig_germany.osm.pbf");
    graphHopper.setGraphHopperLocation(GH_LOCATION);
    graphHopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    graphHopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    graphHopper.importOrLoad();
}
Also used : LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) File(java.io.File) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 15 with LMProfile

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

the class MapMatching2Test method testIssue13.

@Test
public void testIssue13() throws IOException {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile("../map-matching/files/map-issue13.osm.gz");
    hopper.setGraphHopperLocation(GH_LOCATION);
    hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    hopper.importOrLoad();
    MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-13.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    // make sure no virtual edges are returned
    int edgeCount = hopper.getGraphHopperStorage().getAllEdges().length();
    for (EdgeMatch em : mr.getEdgeMatches()) {
        assertTrue(em.getEdgeState().getEdge() < edgeCount, "result contains virtual edges:" + em.getEdgeState().toString());
        validateEdgeMatch(em);
    }
    assertEquals(mr.getGpxEntriesLength(), mr.getMatchLength(), 2.5);
    assertEquals(28790, mr.getMatchMillis(), 50);
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) EdgeMatch(com.graphhopper.matching.EdgeMatch) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) MatchResult(com.graphhopper.matching.MatchResult) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Aggregations

LMProfile (com.graphhopper.config.LMProfile)48 Profile (com.graphhopper.config.Profile)41 CHProfile (com.graphhopper.config.CHProfile)33 Test (org.junit.jupiter.api.Test)24 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)15 PMap (com.graphhopper.util.PMap)12 GraphHopper (com.graphhopper.GraphHopper)10 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)6 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 File (java.io.File)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 Gpx (com.graphhopper.jackson.Gpx)3 EdgeMatch (com.graphhopper.matching.EdgeMatch)3 MapMatching (com.graphhopper.matching.MapMatching)3 MatchResult (com.graphhopper.matching.MatchResult)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3