Repository navigation
Closed
Description
Problematic test case that gives different answer for route Q to P when requesting "Q, P, R" vs. "Q, P" only:
@Test
public void edge_splitting_bug() {
GraphHopperOSM hopper = new GraphHopperOSM();
hopper.setEncodingManager(EncodingManager.create("car"));
hopper.setGraphHopperLocation(GH_LOCATION);
hopper.setOSMFile("../core/files/lauf-200115.osm.pbf");
hopper.setProfiles(new ProfileConfig("profile").setVehicle("car").setWeighting("fastest"));
hopper.importOrLoad();
GraphHopperStorage graph = hopper.getGraphHopperStorage();
LocationIndex locationIndex = hopper.getLocationIndex();
FlagEncoder encoder = hopper.getEncodingManager().fetchEdgeEncoders().get(0);
final FastestWeighting weighting = new FastestWeighting(encoder);
final BooleanEncodedValue accessEnc = weighting.getFlagEncoder().getAccessEnc();
EdgeFilter edgeFilter = new EdgeFilter() {
@Override
public boolean accept(EdgeIteratorState edgeState) {
return edgeState.get(accessEnc) && !Double.isInfinite(weighting.calcEdgeWeight(edgeState, false))
|| edgeState.getReverse(accessEnc) && !Double.isInfinite(weighting.calcEdgeWeight(edgeState, true));
}
};
GHPoint p = new GHPoint(49.529355099741494, 11.296203940756207);
GHPoint q = new GHPoint(49.523147, 11.293001);
GHPoint r = new GHPoint(49.53027363148555, 11.293370881574472);
// works
List<GHPoint> points = Arrays.asList(p, q/*, r*/);
// does not work
// List<GHPoint> points = Arrays.asList(p, q, r);
List<QueryResult> queryResults = new ArrayList<>(points.size());
for (GHPoint point : points) {
queryResults.add(locationIndex.findClosest(point.lat, point.lon, edgeFilter));
}
QueryGraph queryGraph = QueryGraph.lookup(graph, queryResults);
Dijkstra dijkstra = new Dijkstra(queryGraph, queryGraph.wrapWeighting(weighting), TraversalMode.NODE_BASED);
Path path = dijkstra.calcPath(queryResults.get(0).getClosestNode(), queryResults.get(1).getClosestNode());
System.out.println(path);
assertEquals(168.369, path.getWeight(), 0.1);
assertEquals(168369, path.getTime(), 100);
assertEquals(1053.846, path.getDistance(), 0.1);
}Here is the situation on a map:
Maybe a problem due to the area cutting. When zooming into the edge near the destination it seems to be a loop:


Activity
easbar commentedon Apr 20, 2020
This map shows another strange property: Querying the location index with some point far away like
lat=0,lon=0does not yield an erroryields a validSnap, while for maps that were not extracted with Osmosis we seem to get an invalidSnap.Maybe the problems go away when we extract the map like this: #2134 (comment)?
easbar commentedon Dec 19, 2020
I think I ran into this or a similar issue again. In OSMReader we calculate the
towerNodeDistanceusing the entirepointList:graphhopper/reader-osm/src/main/java/com/graphhopper/reader/osm/OSMReader.java
Line 675 in bde99a8
But later we only use the inner (pillar) points to set the way geometry and we silently assume that the first/last points of
pointListare equal to the coordinates of the base/adj nodes:graphhopper/reader-osm/src/main/java/com/graphhopper/reader/osm/OSMReader.java
Lines 703 to 704 in bde99a8
However, with the extract I got from Osmosis this assumption was violated: The first point in the pointList did not match the base node's coordinates. Therefore in my case
towerNodeDistance = distCalc.calculateDistance(pointList) = edge.getDistance()was different todistCalc.calculateDistance(edge.fetchWayGeometry(FetchMode.ALL)). This in turn lead to a situation where the sum of the distances of two virtual edges was (very) different to the 'distance' of the edge that was split by the virtual node.I'm not sure yet if this is a data issue (osmosis corrupts the file) or a bug on our side. But in any case maybe we should add a consistency check to make sure that
pointList.get(0) == basePointandpointList.get(pointList.size()-1) == adjPoint.easbar commentedon Dec 19, 2020
The other thing I find strange here is that we first calculate the
towerNodeDistanceusing all points, then use the result to set the edge'sdistancefield, but before we store the geometry we simplify it. Should we not rather simplify the geometry first and then calculate the edge distance? Otherwise we store a distance that was calculated based on some pillar nodes that we do not keep which seems inconsistent. --> opened #2222 for this.Fun fact: It's been like this for more than seven years now: cb342a2
easbar commentedon Dec 19, 2020
Here I added a check that compares
edge.getDistance()withdistCalc.calcDistance(edge.fetchWayGeometry(FetchMode.ALL)): 37768ff.In
GraphHopperTestthis makes four tests fail. For example intestOneWaySubnetwork_issue1807that uses the ESSEN map we get:and in three SRTM tests that use
monaco.osm.gzwe get:easbar commentedon Dec 19, 2020
Regarding the initial issue in the first post here (
edge_splitting_bug): The red marker (point R) introduces a virtual node along the loop edge seen in the close-up. This means when point R is included we get a different distance, because also hereedge.getDistance() != calcDistance(edge.fetchWayGeometry(FetchMode.ALL)). With the distance check I introduced in my previous comment we also see this explicitly when we run the import forlauf-200115.osm.pbf:easbar commentedon Dec 21, 2020
I think I figured this out. The problem is that after extracting a bounding box using Osmosis there can be ways that reference nodes that no longer exist in the OSM file. And this leads to wrong edge distances. See #2221
Potential fix, but not sure yet, apparently #1984 persists
Handle missing nodes in OSMReader, prevent false edge distances (#2221)
easbar commentedon Dec 29, 2020
Fixed via #2221