Repository navigation
Description
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:
- the heading penalty can only be applied to virtual edges, i.e. it does not work for tower nodes
- since the heading penalty is given in time units it is not compatible with all weightings (Implementing heading for shortest path too #485)
- heading is not supported for speed mode / CH (Throw exception if using heading for CH graph #483)
- the heading tolerance is fixed to a hard-coded value at the moment (Tolerance of
headingis 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
easbar commentedon Jun 27, 2019
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 manipulatingQueryGraphto enforce the direction) or if we should implement this the 'easy' way I have suggested above (change the algorithm instead of the graph). Compared toheadingthe 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
headingapproach 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).
karussell commentedon Jun 28, 2019
Sounds good.
Not important IMO - you know my opinion for shortest weighting ;)
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.
Yeah, with your explanation this makes more sense.
easbar commentedon Jun 28, 2019
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 ?
karussell commentedon Jun 30, 2019
Let me first try to explain this in a artificial example. Let us assume the graph with the start query x and destination A:
If heading is
x->Cand there is a shortcutD->C->B->Aoverx(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 overE. 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 ;)
easbar commentedon Jul 1, 2019
Ok I get it now, thanks!
I added your example here: e8cdc6f