Skip to content

Commit 141461a

Browse files
authored
Merge branch 'dev' into sidewalk-traversal-options
2 parents b078b9a + c5e8479 commit 141461a

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/main/java/com/conveyal/r5/rastercost/CostField.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
import java.util.List;
1414

1515
/**
16-
* Subclasses or plugin functions will provide costs for hills, sun, noise, pollution etc.
16+
* This models a field of traversal costs, in the sense of a cost that varies over geographic space having different
17+
* effects on different edges. Subclasses serve as plugins that provide costs for hills, sun, noise, pollution etc.
18+
*
19+
* CostFields could in principle apply costs to any mode of travel, and might yield different costs for different modes,
20+
* but currently they are not mode-aware. No existing implementations apply to cars, so for now CostFields are simply
21+
* ignored for car routing. Ideally CostFields would know which modes they applied to, and the list of CostFields would
22+
* be filtered before the street search happens. The logic currently in the StreetRouter constructor could be factored
23+
* into a mode-aware factory method that would yield the correct TraversalTimeCalculator. StreetRouter is explicitly
24+
* single-use with a single StreetMode. That mode could be specified up front and the TraversalTimeCalculator
25+
* chosen accordingly (avoiding the MultistageTraversalTimeCalculator construct entirely when no CostFields apply).
1726
*
1827
* Interface-wise, a CostField is like a TraversalTimeCalculator with no turn costs, which transforms an existing
1928
* traversal time rather than starting from scratch. So TraversalTimeCalculator is like a special case of CostField

src/main/java/com/conveyal/r5/streets/MultistageTraversalTimeCalculator.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ public MultistageTraversalTimeCalculator (TraversalTimeCalculator base, List<Cos
4040
public int traversalTimeSeconds (EdgeStore.Edge currentEdge, StreetMode streetMode, ProfileRequest req) {
4141
final int baseTraversalTimeSeconds = base.traversalTimeSeconds(currentEdge, streetMode, req);
4242
int t = baseTraversalTimeSeconds;
43-
for (CostField costField : costFields) {
44-
t += costField.additionalTraversalTimeSeconds(currentEdge, baseTraversalTimeSeconds);
45-
}
46-
if (t < 1) {
47-
LOG.warn("Cost was negative or zero. Clamping to 1 second.");
48-
t = 1;
43+
// Currently no CostField implementations apply to CAR. See Javadoc on CostField if costs need to vary by mode.
44+
if (!streetMode.equals(StreetMode.CAR)) {
45+
for (CostField costField : costFields) {
46+
t += costField.additionalTraversalTimeSeconds(currentEdge, baseTraversalTimeSeconds);
47+
}
48+
if (t < 1) {
49+
LOG.warn("Cost was negative or zero. Clamping to 1 second.");
50+
t = 1;
51+
}
4952
}
5053
return t;
5154
}

0 commit comments

Comments
 (0)