New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edge flags refactoring #1447
Edge flags refactoring #1447
Changes from 1 commit
fb4045a
c43558f
495490b
98509d4
1c917c7
caa8971
39f9b92
45f2de7
037704b
c3fdddf
cffad50
f0999d9
1b5b0f3
13326df
9ffcb8a
be50349
ab92136
d982db6
0590592
e8e738f
9f30377
95258df
9485e7e
8e70b4e
d6b9441
582aa8c
4411c16
122d7ac
54e70de
4feaa32
8655df4
26b1e21
bab2d3e
0dc5b3c
b869aba
529a31f
e81433e
dc02c8f
85b2c45
cb9d90f
8605fb3
9aa6b0d
5820cc3
2f1e70c
c78624b
8150979
c0ced26
b211a79
52a143f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,13 @@ | |
|
||
import com.carrotsearch.hppc.IntHashSet; | ||
import com.carrotsearch.hppc.IntSet; | ||
import com.graphhopper.routing.profiles.BooleanEncodedValue; | ||
import com.graphhopper.routing.util.DefaultEdgeFilter; | ||
import com.graphhopper.routing.util.FlagEncoder; | ||
import com.graphhopper.routing.weighting.TurnWeighting; | ||
import com.graphhopper.storage.CHGraph; | ||
import com.graphhopper.storage.GraphHopperStorage; | ||
import com.graphhopper.storage.IntsRef; | ||
import com.graphhopper.util.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -189,21 +191,22 @@ private void findAndHandleShortcuts(int node) { | |
} | ||
|
||
private void countPreviousEdges(int node) { | ||
BooleanEncodedValue accessEnc = encoder.getAccessEnc(); | ||
CHEdgeIterator iter = allEdgeExplorer.setBaseNode(node); | ||
while (iter.next()) { | ||
if (isContracted(iter.getAdjNode())) | ||
continue; | ||
if (iter.isForward(encoder)) { | ||
if (iter.get(accessEnc)) { | ||
numPrevEdges++; | ||
} | ||
if (iter.isBackward(encoder)) { | ||
if (iter.getReverse(accessEnc)) { | ||
numPrevEdges++; | ||
} | ||
if (!iter.isShortcut()) { | ||
if (iter.isForward(encoder)) { | ||
if (iter.get(accessEnc)) { | ||
numPrevOrigEdges++; | ||
} | ||
if (iter.isBackward(encoder)) { | ||
if (iter.getReverse(accessEnc)) { | ||
numPrevOrigEdges++; | ||
} | ||
} else { | ||
|
@@ -295,9 +298,12 @@ private CHEntry doAddShortcut(CHEntry edgeFrom, CHEntry edgeTo) { | |
LOGGER.trace("Adding shortcut from {} to {}, weight: {}, firstOrigEdge: {}, lastOrigEdge: {}", | ||
from, adjNode, edgeTo.weight, edgeFrom.getParent().incEdge, edgeTo.incEdge); | ||
CHEdgeIteratorState shortcut = prepareGraph.shortcut(from, adjNode); | ||
long direction = PrepareEncoder.getScFwdDir(); | ||
int direction = PrepareEncoder.getScFwdDir(); | ||
// we need to set flags first because they overwrite weight etc | ||
shortcut.setFlags(direction); | ||
// TODO NOW creating a new intsref every time here is probably not efficient ? | ||
IntsRef intsRef = new IntsRef(1); | ||
intsRef.ints[0] = direction; | ||
shortcut.setFlags(intsRef); | ||
shortcut.setSkippedEdges(edgeFrom.edge, edgeTo.edge) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. As you can see in the node based contractor (addShortcuts) I'm doing the same, but I've moved the creation out of the loop so that it can be reused. Reusing is especially important if this is a hot method. IMO this is the main reason the preparation is slower compared to master. I tried to let the Graph handle this caching and called shortcut.getFlags (creating a cached IntsRef) but as we currently do not allow to directly call getFlags for shortcuts this fails. The cleanest thing would be to create a shortcutWeightEnc and shortcutAccessEnc like we have e.g. averageSpeedEnc or accessEnc. Still in case of a new shortcut it would not be possible for the PrepareGraph to cache this (as it should be stateless), unlike when it would be a EdgeIterator or EdgeExplorer (where we assume stateful). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe you have a better idea in this regard? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some possibilities:
|
||
// this is a bit of a hack, we misuse incEdge of edgeFrom's parent to store the first orig edge | ||
.setFirstAndLastOrigEdges(edgeFrom.getParent().incEdge, edgeTo.incEdge) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as an info: the dependency flagEncoder->EncodedValue is one that we should avoid and always prefer EncodedManager->EncodedValue if possible and simple. In this case it seems to be harder so it might be ok (that's why I created the method as a helper).