Skip to content

Allow restricting start/target edge for edge-based routing. #1647

Closed

Description

@easbar

Even for edge-based algorithms (supporting turn costs & restrictions) we are calculating routes between nodes (not edges) of the routing graph, i.e. calcPath(fromNodeIndex, toNodeIndex), not calcPath(fromEdgeIndex, toEdgeIndex). To do this we simply use all adjacent outgoing edges at the start node as well as all incoming edges at the target node.

However, what we cannot do at the moment is restricting the route calculation such that only certain edges at the start/target nodes are considered. For example this would be needed to be able to start a route in a certain direction (say start driving in northern instead of southern direction).

The feature that comes closest to this requirement is the heading parameter. The way this is implemented we increase the cost of edges that are adjacent to the start/target nodes and do not face in a specified direction. Because of their higher cost it will thus be less likely they are included in the shortest path.

Unfortunately, the heading parameter has several restrictions:

  1. the heading penalty can only be applied to virtual edges, i.e. it does not work for tower nodes
  2. since the heading penalty is given in time units it is not compatible with all weightings (Implementing heading for shortest path too #485)
  3. heading is not supported for speed mode / CH (Throw exception if using heading for CH graph #483)
  4. the heading tolerance is fixed to a hard-coded value at the moment (Tolerance of heading is fixed to 100 degrees. #1646)

On the other hand enforcing the start/target edge with edge-based routing is a very simple thing, especially for bidirectional algorithms. As I explained, when the route calculation starts we consider all edges adjacent to the start/target node. To enforce a single direction all we need to do is skipping all edges except the one(s) we want at the first step. This is how it can be done (using DijkstraBidirectionRef):

public Path calcPathRestricted(int source, int target, int sourceOutEdge, int targetInEdge) {
    AbstractBidirAlgo algo = new DijkstraBidirectionRef(graph, weighting, TraversalMode.EDGE_BASED);
    algo.createAndInitPath();
    algo.initFrom(source, 0);
    algo.initTo(targe, 0);

    // filter out all edges except the one we want for the first step
    algo.setEdgeFilter(new SingleEdgeFilter(sourceOutEdge));
    algo.fillEdgesFrom();

    algo.setEdgeFilter(new SingleEdgeFilter(targetInEdge));
    algo.fillEdgesTo();

    // no filtering from now (unless there should be some other filter used for the whole time of course) 
    algo.setEdgeFilter(null);
    algo.runAlgo();
    return algo.extractPath();
}

private static class SingleEdgeFilter implements EdgeFilter {
    private int validEdge;
    SingleEdgeFilter(int validEdge) {
      this.validEdge = validEdge;
    }

    @Override
    public boolean accept(EdgeIteratorState edgeState) {
        return edgeState.getEdge() == validEdge;
    }
}

To make this feature compatible with the web interface there should also be a way to determine the sourceOutEdge and targetInEdge based on the direction the corresponding roads are facing, i.e. it should be possible to define the desired direction using something like the heading (in degrees). Maybe we could actually use the heading parameter for this if edge_based is true ?

Related: #680.

Activity

  1. easbar commented on Jun 27, 2019

    @easbar
    MemberAuthor

    The thing I am not sure about is whether we should try to fix the issues I mentioned we are having with heading (here the approach is manipulating QueryGraph to enforce the direction) or if we should implement this the 'easy' way I have suggested above (change the algorithm instead of the graph). Compared to heading the approach I have suggested only allows strictly enforcing an edge, but not increasing the weight for (but still allowing) an edge. This can probably be done in a similar way, but then we would probably run into a similar problem as 2).

    With the current heading approach I think 4) is easy to fix, 3) I do not really understand, and I do not think there will be a good solution for 1) with edge-based routing.

    Generally, my feeling is that restricting the start/target direction of a path calculation should be something the routing algorithm deals with (not the graph).

  2. karussell commented on Jun 28, 2019

    @karussell
    Member

    Maybe we could actually use the heading parameter for this if edge_based is true ?

    Sounds good.

    This can probably be done in a similar way, but then we would probably run into a similar problem as 2).

    Not important IMO - you know my opinion for shortest weighting ;)

    heading is not supported for speed mode / CH (#483)

    The problem with CH might be that the specific edge can be hidden in a shortcut. So even if we skip edge_id in origFirst/Last we cannot avoid that at some point the algo decides it goes back through the forbidden edge without having control over the minimum costs for this "U-turn" and leading to strange routes. At least this was the problem for node based CH.

    Generally, my feeling is that restricting the start/target direction of a path calculation should be something the routing algorithm deals with (not the graph).

    Yeah, with your explanation this makes more sense.

  3. easbar commented on Jun 28, 2019

    @easbar
    MemberAuthor

    The problem with CH might be that the specific edge can be hidden in a shortcut

    Hmm, but we are applying the heading only for virtual nodes, so all edges that are adjacent to such a node are virtual (no shortcuts) ? Do you have an example of a route that fails with heading+CH somewhere ?

  4. karussell commented on Jun 30, 2019

    @karussell
    Member

    Let me first try to explain this in a artificial example. Let us assume the graph with the start query x and destination A:

      
    A-B-x-C-D
      |__E__|
    

    If heading is x->C and there is a shortcut D->C->B->A over x (or at any random later position) that produces a solution with a U-turn (or in real graphs at any later point) instead of the correct solution over E. Furthermore these solutions could also violate the specified (or default) u-turn cost for the heading.

    I think I observed these wrong routes in practise and will of course try to find a real world example if that example is too ugly ;)

  5. easbar commented on Jul 1, 2019

    @easbar
    MemberAuthor

    Ok I get it now, thanks!
    I added your example here: e8cdc6f

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