Skip to content

Commit b94bcbb

Browse files
committed
Use keys instead of edges for turn weight in edge-based witness search
1 parent 51034f4 commit b94bcbb

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

core/src/main/java/com/graphhopper/routing/ch/BridgePathFinder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.PriorityQueue;
2727

2828
import static com.graphhopper.util.EdgeIterator.NO_EDGE;
29-
import static com.graphhopper.util.GHUtility.getEdgeFromEdgeKey;
3029

3130
/**
3231
* Used to find 'bridge-paths' during edge-based CH preparation. Bridge-paths are paths that start and end at neighbor
@@ -71,7 +70,7 @@ public IntObjectMap<BridePathEntry> find(int startInEdgeKey, int startNode, int
7170
if (iter.getAdjNode() == centerNode) {
7271
// We arrived at the center node, so we keep expanding the search
7372
double weight = currEntry.weight +
74-
graph.getTurnWeight(getEdgeFromEdgeKey(currEntry.incEdgeKey), currEntry.adjNode, getEdgeFromEdgeKey(iter.getOrigEdgeKeyFirst())) +
73+
graph.getTurnWeight(currEntry.incEdgeKey, currEntry.adjNode, iter.getOrigEdgeKeyFirst()) +
7574
iter.getWeight();
7675
if (Double.isInfinite(weight))
7776
continue;
@@ -95,14 +94,14 @@ public IntObjectMap<BridePathEntry> find(int startInEdgeKey, int startNode, int
9594
// there is a target edge, so we add a bridge path entry for it. We do not continue the search from the
9695
// neighbor node anymore
9796
double weight = currEntry.weight +
98-
graph.getTurnWeight(getEdgeFromEdgeKey(currEntry.incEdgeKey), currEntry.adjNode, getEdgeFromEdgeKey(iter.getOrigEdgeKeyFirst())) +
97+
graph.getTurnWeight(currEntry.incEdgeKey, currEntry.adjNode, iter.getOrigEdgeKeyFirst()) +
9998
iter.getWeight();
10099
if (Double.isInfinite(weight))
101100
continue;
102101
PrepareGraphOrigEdgeIterator origOutIter = origOutExplorer.setBaseNode(iter.getAdjNode());
103102
while (origOutIter.next()) {
104103
double totalWeight = weight + graph.getTurnWeight(
105-
getEdgeFromEdgeKey(iter.getOrigEdgeKeyLast()), iter.getAdjNode(), getEdgeFromEdgeKey(origOutIter.getOrigEdgeKeyFirst()));
104+
iter.getOrigEdgeKeyLast(), iter.getAdjNode(), origOutIter.getOrigEdgeKeyFirst());
106105
if (Double.isInfinite(totalWeight))
107106
continue;
108107
BridePathEntry resEntry = result.get(origOutIter.getOrigEdgeKeyFirst());

core/src/main/java/com/graphhopper/routing/ch/CHPreparationGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ public PrepareGraphOrigEdgeExplorer createInOrigEdgeExplorer() {
254254
return origGraph.createInOrigEdgeExplorer();
255255
}
256256

257-
public double getTurnWeight(int inEdge, int viaNode, int outEdge) {
258-
return turnCostFunction.getTurnWeight(inEdge, viaNode, outEdge);
257+
public double getTurnWeight(int inEdgeKey, int viaNode, int outEdgeKey) {
258+
return turnCostFunction.getTurnWeight(GHUtility.getEdgeFromEdgeKey(inEdgeKey), viaNode, GHUtility.getEdgeFromEdgeKey(outEdgeKey));
259259
}
260260

261261
public IntContainer disconnect(int node) {

core/src/main/java/com/graphhopper/routing/ch/EdgeBasedNodeContractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private void findAndHandlePrepareShortcuts(int node, PrepareShortcutHandler shor
217217
long addedShortcutKey = BitUtil.LITTLE.combineIntsToLong(root.firstEdgeKey, bridgePath.value.chEntry.incEdgeKey);
218218
if (!addedShortcuts.add(addedShortcutKey))
219219
continue;
220-
double initialTurnCost = prepareGraph.getTurnWeight(getEdgeFromEdgeKey(origInKey), sourceNode, getEdgeFromEdgeKey(root.firstEdgeKey));
220+
double initialTurnCost = prepareGraph.getTurnWeight(origInKey, sourceNode, root.firstEdgeKey);
221221
bridgePath.value.chEntry.weight -= initialTurnCost;
222222
LOGGER.trace("Adding shortcuts for target entry {}", bridgePath.value.chEntry);
223223
// todo: re-implement loop-avoidance heuristic as it existed in GH 1.0? it did not work the

core/src/main/java/com/graphhopper/routing/ch/EdgeBasedWitnessPathSearcher.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Arrays;
2525
import java.util.Locale;
2626

27-
import static com.graphhopper.util.GHUtility.getEdgeFromEdgeKey;
2827
import static com.graphhopper.util.Helper.nf;
2928

3029
/**
@@ -129,7 +128,7 @@ public double runSearch(int targetNode, int targetEdgeKey, double acceptedWeight
129128
final int edgeKey = GHUtility.reverseEdgeKey(inIter.getOrigEdgeKeyLast());
130129
if (weights[edgeKey] == Double.POSITIVE_INFINITY)
131130
continue;
132-
double weight = weights[edgeKey] + calcTurnWeight(getEdgeFromEdgeKey(edgeKey), targetNode, getEdgeFromEdgeKey(targetEdgeKey));
131+
double weight = weights[edgeKey] + calcTurnWeight(edgeKey, targetNode, targetEdgeKey);
133132
if (weight < acceptedWeight || (weight == acceptedWeight && (parents[edgeKey] < 0 || !isPathToCenter(parents[edgeKey]))))
134133
return weight;
135134
}
@@ -152,7 +151,7 @@ public double runSearch(int targetNode, int targetEdgeKey, double acceptedWeight
152151
// being recognized as witnesses when there are double zero weight loops at the source node
153152
if (currNode == sourceNode && iter.getAdjNode() == sourceNode && iter.getWeight() < MAX_ZERO_WEIGHT_LOOP)
154153
continue;
155-
final double weight = weights[currKey] + calcTurnWeight(getEdgeFromEdgeKey(currKey), currNode, getEdgeFromEdgeKey(iter.getOrigEdgeKeyFirst())) + iter.getWeight();
154+
final double weight = weights[currKey] + calcTurnWeight(currKey, currNode, iter.getOrigEdgeKeyFirst()) + iter.getWeight();
156155
if (Double.isInfinite(weight))
157156
continue;
158157
final int key = iter.getOrigEdgeKeyLast();
@@ -164,7 +163,7 @@ public double runSearch(int targetNode, int targetEdgeKey, double acceptedWeight
164163
changedEdges.add(key);
165164
dijkstraHeap.insert(weight, key);
166165
if (iter.getAdjNode() == targetNode && (!isPathToCenter(currKey) || parents[currKey] < 0))
167-
foundWeight = Math.min(foundWeight, weight + calcTurnWeight(getEdgeFromEdgeKey(key), targetNode, getEdgeFromEdgeKey(targetEdgeKey)));
166+
foundWeight = Math.min(foundWeight, weight + calcTurnWeight(key, targetNode, targetEdgeKey));
168167
} else if (weight < weights[key]
169168
// if weights are equal make sure we prefer witness paths over bridge paths
170169
|| (weight == weights[key] && !isPathToCenter(currKey))) {
@@ -174,7 +173,7 @@ public double runSearch(int targetNode, int targetEdgeKey, double acceptedWeight
174173
setAdjNodeAndPathToCenter(key, iter.getAdjNode(), isPathToCenter);
175174
dijkstraHeap.update(weight, key);
176175
if (iter.getAdjNode() == targetNode && (!isPathToCenter(currKey) || parents[currKey] < 0))
177-
foundWeight = Math.min(foundWeight, weight + calcTurnWeight(getEdgeFromEdgeKey(key), targetNode, getEdgeFromEdgeKey(targetEdgeKey)));
176+
foundWeight = Math.min(foundWeight, weight + calcTurnWeight(key, targetNode, targetEdgeKey));
178177
}
179178
}
180179
if (foundWeight <= acceptedWeight)
@@ -258,8 +257,8 @@ private void resetEntry(int key) {
258257
setAdjNodeAndPathToCenter(key, NO_NODE, false);
259258
}
260259

261-
private double calcTurnWeight(int inEdge, int viaNode, int outEdge) {
262-
return prepareGraph.getTurnWeight(inEdge, viaNode, outEdge);
260+
private double calcTurnWeight(int inEdgeKey, int viaNode, int outEdgeKey) {
261+
return prepareGraph.getTurnWeight(inEdgeKey, viaNode, outEdgeKey);
263262
}
264263

265264
static class Stats {

0 commit comments

Comments
 (0)