Skip to content

Commit cf068db

Browse files
committed
fix(linking): rebuild linkageCostTables for appropriate mode
1 parent 4dbffb3 commit cf068db

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
1818
import static com.conveyal.r5.streets.StreetRouter.State.RoutingVariable;
19+
import static com.conveyal.r5.transit.TransitLayer.WALK_DISTANCE_LIMIT_METERS;
1920

2021
import java.io.Serializable;
2122
import java.util.ArrayList;
@@ -57,6 +58,12 @@ public class LinkedPointSet implements Serializable {
5758
static final int BICYCLE_DISTANCE_LINKING_LIMIT_METERS = 2000;
5859

5960
static final int CAR_TIME_LINKING_LIMIT_SECONDS = 20 * 60;
61+
/**
62+
* Limit to use when building linkageCostTables, re-calculated for different streetModes as needed, using the
63+
* constants specified above. The value should be larger than any per-leg street mode limits that can be requested
64+
* in the UI.
65+
*/
66+
int linkingDistanceLimitMeters = WALK_DISTANCE_LIMIT_METERS;
6067

6168
// Fair to assume that people walk from nearest OSM way to their ultimate destination? Should we just use the
6269
// walk speed from the analysis request?
@@ -121,7 +128,7 @@ public LinkedPointSet (PointSet pointSet, StreetLayer streetLayer, StreetMode st
121128

122129
// The regions within which we want to link points to edges, then connect transit stops to points.
123130
// Null means relink and rebuild everything, but this will be constrained below if a base linkage was supplied.
124-
Geometry treeRebuildZone = null;
131+
Geometry linkageCostRebuildZone = null;
125132

126133
if (baseLinkage != null && (
127134
baseLinkage.pointSet != pointSet ||
@@ -161,7 +168,18 @@ public LinkedPointSet (PointSet pointSet, StreetLayer streetLayer, StreetMode st
161168
// transit stops, we still need to re-link points and rebuild stop trees (both the trees to the vertices
162169
// and the trees to the points, because some existing stop-to-vertex trees might not include new splitter
163170
// vertices).
164-
treeRebuildZone = streetLayer.scenarioEdgesBoundingGeometry(TransitLayer.WALK_DISTANCE_LIMIT_METERS);
171+
172+
if (streetMode != StreetMode.WALK) {
173+
// limit already set for WALK.
174+
} else if (streetMode == StreetMode.BICYCLE) {
175+
linkingDistanceLimitMeters = BICYCLE_DISTANCE_LINKING_LIMIT_METERS;
176+
} else if (streetMode == StreetMode.CAR) {
177+
linkingDistanceLimitMeters = CAR_TIME_LINKING_LIMIT_SECONDS * MAX_CAR_SPEED_METERS_PER_SECOND;
178+
} else {
179+
throw new UnsupportedOperationException("Unrecognized streetMode");
180+
}
181+
182+
linkageCostRebuildZone = streetLayer.scenarioEdgesBoundingGeometry(linkingDistanceLimitMeters);
165183
}
166184

167185
// If dealing with a scenario, pad out the stop trees list from the base linkage to match the new stop count.
@@ -174,7 +192,7 @@ public LinkedPointSet (PointSet pointSet, StreetLayer streetLayer, StreetMode st
174192

175193
// Second, make a table of linkage costs (distance or time) from each transit stop to the points in this
176194
// PointSet.
177-
this.makeStopToPointLinkageCostTables(treeRebuildZone);
195+
this.makeStopToPointLinkageCostTables(linkageCostRebuildZone);
178196

179197
}
180198

0 commit comments

Comments
 (0)