Search in sources :

Example 16 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class MapMatchingTest method testDistantPoints.

/**
 * This test is to check behavior over large separated routes: it should
 * work if the user sets the maxVisitedNodes large enough. Input path:
 * https://graphhopper.com/maps/?point=51.23%2C12.18&point=51.45%2C12.59&layer=Lyrk
 * <p>
 * Update: Seems to me that this test only tests a long route, not one with
 * distant input points. createRandomGPXEntries currently creates very close input points.
 * The length of the route doesn't seem to matter.
 */
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testDistantPoints(PMap hints) {
    // OK with 1000 visited nodes:
    MapMatching mapMatching = new MapMatching(graphHopper, hints);
    ResponsePath route = graphHopper.route(new GHRequest(new GHPoint(51.23, 12.18), new GHPoint(51.45, 12.59)).setProfile("my_profile")).getBest();
    List<Observation> inputGPXEntries = createRandomGPXEntriesAlongRoute(route);
    MatchResult mr = mapMatching.match(inputGPXEntries);
    assertEquals(route.getDistance(), mr.getMatchLength(), 2);
    // GraphHopper travel times aren't exactly additive
    assertThat(Math.abs(route.getTime() - mr.getMatchMillis()), is(lessThan(1000L)));
    // not OK when we only allow a small number of visited nodes:
    PMap opts = new PMap(hints).putObject(Parameters.Routing.MAX_VISITED_NODES, 1);
    mapMatching = new MapMatching(graphHopper, opts);
    try {
        mr = mapMatching.match(inputGPXEntries);
        fail("Expected sequence to be broken due to maxVisitedNodes being too small");
    } catch (RuntimeException e) {
        assertTrue(e.getMessage().startsWith("Sequence is broken for submitted track"));
    }
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) ResponsePath(com.graphhopper.ResponsePath) GHRequest(com.graphhopper.GHRequest) Observation(com.graphhopper.matching.Observation) PMap(com.graphhopper.util.PMap) GHPoint(com.graphhopper.util.shapes.GHPoint) MatchResult(com.graphhopper.matching.MatchResult) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 17 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class MapMatchingTest method testUTurns.

/**
 * This test is to check that U-turns are avoided when it's just measurement
 * error, though do occur when a point goes up a road further than the
 * measurement error. GPX input:
 * https://graphhopper.com/maps/?point=51.343618%2C12.360772&point=51.34401%2C12.361776&point=51.343977%2C12.362886&point=51.344734%2C12.36236&point=51.345233%2C12.362055&layer=Lyrk
 */
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testUTurns(PMap hints) throws IOException {
    hints = new PMap(hints).putObject(Parameters.Routing.HEADING_PENALTY, 50);
    MapMatching mapMatching = new MapMatching(graphHopper, hints);
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/tour4-with-uturn.gpx"), Gpx.class);
    // with large measurement error, we expect no U-turn
    mapMatching.setMeasurementErrorSigma(50);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    assertEquals(Arrays.asList("Gustav-Adolf-Straße", "Funkenburgstraße"), fetchStreets(mr.getEdgeMatches()));
    // with small measurement error, we expect the U-turn
    mapMatching.setMeasurementErrorSigma(10);
    mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    assertEquals(Arrays.asList("Gustav-Adolf-Straße", "Funkenburgstraße"), fetchStreets(mr.getEdgeMatches()));
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) PMap(com.graphhopper.util.PMap) MatchResult(com.graphhopper.matching.MatchResult) Gpx(com.graphhopper.jackson.Gpx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 18 with PMap

use of com.graphhopper.util.PMap 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)

Example 19 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class MapMatching2Test method testIssue70.

@Test
public void testIssue70() throws IOException {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile("../map-matching/files/issue-70.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-70.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    assertEquals(Arrays.asList("Милана Видака", "Бранка Радичевића", "Здравка Челара"), fetchStreets(mr.getEdgeMatches()));
    for (EdgeMatch edgeMatch : mr.getEdgeMatches()) {
        validateEdgeMatch(edgeMatch);
    }
}
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)

Example 20 with PMap

use of com.graphhopper.util.PMap in project graphhopper by graphhopper.

the class LMProfileSelectorTest method assertLMProfileSelectionError.

private String assertLMProfileSelectionError(String expectedError, List<Profile> profiles, List<LMProfile> lmProfiles, String vehicle, String weighting, Boolean edgeBased, Integer uTurnCosts) {
    PMap hintsMap = createHintsMap(vehicle, weighting, edgeBased, uTurnCosts);
    try {
        new ProfileResolver(encodingManager, profiles, Collections.<CHProfile>emptyList(), lmProfiles).selectProfileLM(hintsMap);
        fail("There should have been an error");
        return "";
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains(expectedError), "There should have been an error message containing:\n'" + expectedError + "'\nbut was:\n'" + e.getMessage() + "'");
        return e.getMessage();
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) ProfileResolver(com.graphhopper.routing.ProfileResolver) PMap(com.graphhopper.util.PMap)

Aggregations

PMap (com.graphhopper.util.PMap)50 Test (org.junit.jupiter.api.Test)27 LMProfile (com.graphhopper.config.LMProfile)12 Profile (com.graphhopper.config.Profile)12 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)12 CHProfile (com.graphhopper.config.CHProfile)10 ArrayList (java.util.ArrayList)10 GraphHopper (com.graphhopper.GraphHopper)6 MapMatching (com.graphhopper.matching.MapMatching)5 MatchResult (com.graphhopper.matching.MatchResult)5 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)5 CHRoutingAlgorithmFactory (com.graphhopper.routing.ch.CHRoutingAlgorithmFactory)5 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)5 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)5 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 Gpx (com.graphhopper.jackson.Gpx)4 ReaderWay (com.graphhopper.reader.ReaderWay)4 ProfileResolver (com.graphhopper.routing.ProfileResolver)4 Weighting (com.graphhopper.routing.weighting.Weighting)4 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)4