Change dynamically direction of edge


I have, for example, three edges in my dummy graph:
A to B (both directions)
B to C (only forward)
C to D (only backward).

Now i want to change the direction of some edges dynamically, e.g. force edge (B to C) to navigate backward and prohibit forward navigation.
How can i do this? Where should i extend graphhopper to accomplish this task?

I have implemented a custom weighting class, but currently i cannot determine the direction how my edge is traversed.
In calcWeight(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId):
If (B to C) is traversed from B to C i want return a bad weight.
If (B to C) is traversed from C to B i want return a good weight.

Any ideas?:slight_smile:

(I do not want to recalculate the routing cache and i use CH and No-CH).

If you want a static solution you set the flags accordingly:

edgeState.setFlags(encoder.setAccess(edgeState.getFlags(), false, true));

If you just want to have it in the Weighting (i.e. per request) then you need to know that the flags of edgeState are already in the correct direction e.g. either
edgeState = iter.setBaseNode(B)
edgeState = iter.setBaseNode©
except if reverse=true, then the edgeState has flags that have the reverse state. reverse can be only true for the backward search of a bidirectional algorithm.

Thansk for your reply.

What is the “iter”-instance?

Sorry, this is incorrect it should be better like:

edgeExplorer = graph.createEdgeExplorer(edgeFilter);
edgeIterator = edgeExplorer.setBaseNode(node);
while( {
   // now the edgeIterator has a certain 'state', i.e use as EdgeIteratorState
   // to put an edgeIteratorState into a list for later usage you need to 'remember' the current state and detach it from the iterator via:
   edgeIteratorState = edgeIterator.detach(false);
   // detach is usually a rather costly operation and should be done only if necessary

I use this suggestion and it works:)
Thank you.