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"));
}
}
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()));
}
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);
}
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);
}
}
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();
}
}
Aggregations