Skip to content

Commit da748e6

Browse files
committed
Set the default u-turn time to zero
1 parent c54a883 commit da748e6

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 10.0 [not yet released]
22

3+
- the default u-turn time is now 0, the default u-turn weight is still infinite
34
- turn restriction support for restrictions with overlapping and/or multiple via-edges/ways, #3030
45
- constructor of BaseGraph.Builder uses byte instead of integer count.
56
- KeyValue is now KValue as it holds the value only. Note, the two parameter constructor uses one value for the forward and one for the backward direction (and no longer "key, value")

core/src/main/java/com/graphhopper/routing/weighting/DefaultTurnCostProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ public double calcTurnWeight(int edgeFrom, int nodeVia, int edgeTo) {
7575

7676
@Override
7777
public long calcTurnMillis(int inEdge, int viaNode, int outEdge) {
78-
return (long) (1000 * calcTurnWeight(inEdge, viaNode, outEdge));
78+
// Making a proper assumption about the turn time is very hard. Assuming zero is the
79+
// simplest way to deal with this. This also means the u-turn time is zero. Provided that
80+
// the u-turn weight is large enough, u-turns only occur in special situations like curbsides
81+
// pointing to the end of dead-end streets where it is unclear if a finite u-turn time would
82+
// be a good choice.
83+
return 0;
7984
}
8085

8186
@Override

core/src/test/java/com/graphhopper/routing/weighting/custom/CustomWeightingTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ public void calcWeightAndTime_withTurnCosts() {
409409
EdgeIteratorState edge = graph.edge(1, 2).set(avSpeedEnc, 60, 60).setDistance(100);
410410
setTurnRestriction(graph, 0, 1, 2);
411411
assertTrue(Double.isInfinite(GHUtility.calcWeightWithTurnWeight(weighting, edge, false, 0)));
412-
assertEquals(Long.MAX_VALUE, GHUtility.calcMillisWithTurnMillis(weighting, edge, false, 0));
412+
// the time only reflects the time for the edge, the turn time is 0
413+
assertEquals(6000, GHUtility.calcMillisWithTurnMillis(weighting, edge, false, 0));
413414
}
414415

415416
@Test
@@ -419,7 +420,7 @@ public void calcWeightAndTime_uTurnCosts() {
419420
Weighting weighting = CustomModelParser.createWeighting(encodingManager, new DefaultTurnCostProvider(turnRestrictionEnc, graph.getTurnCostStorage(), 40), customModel);
420421
EdgeIteratorState edge = graph.edge(0, 1).set(avSpeedEnc, 60, 60).setDistance(100);
421422
assertEquals(6 + 40, GHUtility.calcWeightWithTurnWeight(weighting, edge, false, 0), 1.e-6);
422-
assertEquals((6 + 40) * 1000, GHUtility.calcMillisWithTurnMillis(weighting, edge, false, 0), 1.e-6);
423+
assertEquals(6 * 1000, GHUtility.calcMillisWithTurnMillis(weighting, edge, false, 0), 1.e-6);
423424
}
424425

425426
@Test

0 commit comments

Comments
 (0)