Skip to content

Backward-only loops make problems with edge-based routing. #1525

Closed

Description

@easbar

When we add a loop edge that only has the bwd but not the fwd bit set we are getting problems with edge-based routing. The loop edge will not be found by forward searches (using DefaultEdgeFilter.outEdges) so if there is a path that requires a loop (e.g. because of a restricted direct turn at the loop node) it will not be found or another (a sub-optimal) route will be found. With a bidirectional algorithm we would discover the loop in the backward search, but right now there will be a runtime exception in AbstractWeighting. Also the forward search would have to 'wait' at the loop for the backward search which can harm performance. Its probably questionable if a bwd-only loop is ever a real problem, but it is possible in principle. I think the current import does not produce it. It would be needed if we wanted to get the reverse geometry of a loop.
See tests here: https://gist.github.com/easbar/06e7a9c71888fe147887e1d83dde9fe1
or better here: e484314
Also see discussion in #1247.

Activity

  1. karussell commented on Jan 21, 2019

    @karussell
    Member

    This will fail even more likely with the Isochrone API if we use the adapted DefaultEdgeFilter #1247 (it is currently the remaining problem before we can merge it):

    public final boolean accept(EdgeIteratorState iter) {
       if(iter.getBaseNode() == iter.getAdjNode()) return iter.isForward(encoder) || iter.isBackward(encoder);
       return fwd && iter.isForward(encoder) || bwd && iter.isBackward(encoder);
    }

    Resulting in:

    ! java.lang.IllegalStateException: Calculating time should not require to read speed from edge in wrong direction. Reverse:true, fwd:true, bwd:false
    ! at com.graphhopper.routing.weighting.AbstractWeighting.calcMillis(AbstractWeighting.java:46)
    ! at com.graphhopper.routing.weighting.FastestWeighting.calcMillis(FastestWeighting.java:83)
    ! at com.graphhopper.isochrone.algorithm.Isochrone.searchInternal(Isochrone.java:203)
    ! at com.graphhopper.isochrone.algorithm.Isochrone.searchGPS(Isochrone.java:107)
    ! at com.graphhopper.resources.IsochroneResource.doGet(IsochroneResource.java:95)
    ....
    

    So either we reject such loops for the isochrone or we better fix this that the edge returns the one-way loop in the correct direction where we do not attempt to read the speed in the wrong direction.

  2. karussell commented on Jan 21, 2019

    @karussell
    Member

    The best thing would be if such loops would be returned as two edge states: one edge state in forward direction and one in backward direction. This would be similar to a small example graph A->B-C-A with the one-way A->B: accessing the edge A-B from A returns A->B and accessing it from B we return a different B<-A.

    But it is unclear how to fetch the two different edge states with an edgeId and a nodeId. The solution here could be to use the edge key: graph.getEdgeIteratorState(edgeKey). Probably we have to deprecate getEdgeIteratorState(edge,adjNode) as this is meant to return the unique edge state but fails in those cases.

    This would be probably the cleanest solution and IMO would also avoid this special handling in the DefaultEdgeFilter. But it might collide with the current way (in GTFS) of how we attach data to nodes: via loops.

    The simplest solution is likely to convert one pillar node into a tower node for such loops with the downside that every data import needs a special handling for one-way loops. Should we do this for now and merge #1247 and keep this here open?

    I think the current import does not produce it.

    Currently it can produce it because we potentially reverse flags before storing the flags. This will change with #1447 where we return the flags always how they are stored and do not artificially reverse them

  3. added 4 commits that reference this issue on Jan 23, 2019
    c2f6f4c
    36f2c84
    32aaf08
    b4925c5
  4. added a commit that references this issue on Jan 31, 2019
    dce2543
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions