1
1
package com .conveyal .r5 .analyst .network ;
2
2
3
3
import com .conveyal .r5 .analyst .FreeFormPointSet ;
4
- import com .conveyal .r5 .analyst .Grid ;
5
4
import com .conveyal .r5 .analyst .PointSet ;
6
5
import com .conveyal .r5 .analyst .WebMercatorExtents ;
7
6
import com .conveyal .r5 .analyst .cluster .AnalysisWorkerTask ;
8
- import com .conveyal .r5 .analyst .cluster .TravelTimeSurfaceTask ;
7
+ import com .conveyal .r5 .analyst .cluster .RegionalTask ;
9
8
import com .conveyal .r5 .analyst .decay .StepDecayFunction ;
10
9
import com .conveyal .r5 .api .util .LegMode ;
11
10
import com .conveyal .r5 .api .util .TransitModes ;
20
19
import static com .conveyal .r5 .analyst .network .GridGtfsGenerator .WEEKEND_DATE ;
21
20
22
21
/**
23
- * This creates a task for use in tests. It uses a builder pattern but for a non-immutable task object.
24
- * It provides convenience methods to set all the necessary fields. This builder may be reused to produce
25
- * several tasks in a row with different settings, but only use the most recently produced one at any time.
26
- * See build() for further explanation.
22
+ * This creates a task for use in tests. It uses a builder pattern but modifies a non-immutable task object. It
23
+ * provides convenience methods to set all the necessary fields. This builder may be reused to produce several tasks in
24
+ * a row with different settings, but only use the most recently produced one at any time. See build() for further
25
+ * explanation. We want to use a limited number of destinations at exact points instead of Mercator gridded
26
+ * destinations, which would not be exactly aligned with the desert grid. Therefore we create regional tasks rather
27
+ * than single-point TravelTimeSurfaceTasks because single-point tasks always have gridded destinations (they always
28
+ * return gridded travel times which must be exactly aligned with any accessibility destinations).
27
29
*/
28
- public class GridSinglePointTaskBuilder {
30
+ public class GridRegionalTaskBuilder {
29
31
30
32
public static final int DEFAULT_MONTE_CARLO_DRAWS = 4800 ; // 40 per minute over a two hour window.
31
33
private final GridLayout gridLayout ;
32
- private final AnalysisWorkerTask task ;
33
34
34
- public GridSinglePointTaskBuilder (GridLayout gridLayout ) {
35
+ private final RegionalTask task ;
36
+
37
+ public GridRegionalTaskBuilder (GridLayout gridLayout ) {
35
38
this .gridLayout = gridLayout ;
36
39
// We will accumulate settings into this task.
37
- task = new TravelTimeSurfaceTask ();
40
+ task = new RegionalTask ();
38
41
task .date = WEEKDAY_DATE ;
39
42
// Set defaults that can be overridden by calling builder methods.
40
43
task .accessModes = EnumSet .of (LegMode .WALK );
@@ -52,10 +55,11 @@ public GridSinglePointTaskBuilder (GridLayout gridLayout) {
52
55
task .monteCarloDraws = DEFAULT_MONTE_CARLO_DRAWS ;
53
56
// By default, traverse one block in a round predictable number of seconds.
54
57
task .walkSpeed = gridLayout .streetGridSpacingMeters / gridLayout .walkBlockTraversalTimeSeconds ;
58
+ // Unlike single point tasks, travel time recording must be enabled manually on regional tasks.
59
+ task .recordTimes = true ;
55
60
// Record more detailed information to allow comparison to theoretical travel time distributions.
56
61
task .recordTravelTimeHistograms = true ;
57
- // Set the destination grid extents on the task, otherwise if no freeform PointSet is specified, the task will fail
58
- // checks on the grid dimensions and zoom level.
62
+ // Set the grid extents on the task, otherwise the task will fail checks on the grid dimensions and zoom level.
59
63
WebMercatorExtents extents = WebMercatorExtents .forWgsEnvelope (gridLayout .gridEnvelope (), DEFAULT_ZOOM );
60
64
task .zoom = extents .zoom ;
61
65
task .north = extents .north ;
@@ -64,38 +68,38 @@ public GridSinglePointTaskBuilder (GridLayout gridLayout) {
64
68
task .height = extents .height ;
65
69
}
66
70
67
- public GridSinglePointTaskBuilder setOrigin (int gridX , int gridY ) {
71
+ public GridRegionalTaskBuilder setOrigin (int gridX , int gridY ) {
68
72
Coordinate origin = gridLayout .getIntersectionLatLon (gridX , gridY );
69
73
task .fromLat = origin .y ;
70
74
task .fromLon = origin .x ;
71
75
return this ;
72
76
}
73
77
74
- public GridSinglePointTaskBuilder weekdayMorningPeak () {
78
+ public GridRegionalTaskBuilder weekdayMorningPeak () {
75
79
task .date = WEEKDAY_DATE ;
76
80
morningPeak ();
77
81
return this ;
78
82
}
79
83
80
- public GridSinglePointTaskBuilder weekendMorningPeak () {
84
+ public GridRegionalTaskBuilder weekendMorningPeak () {
81
85
task .date = WEEKEND_DATE ;
82
86
morningPeak ();
83
87
return this ;
84
88
}
85
89
86
- public GridSinglePointTaskBuilder morningPeak () {
90
+ public GridRegionalTaskBuilder morningPeak () {
87
91
task .fromTime = LocalTime .of (7 , 00 ).toSecondOfDay ();
88
92
task .toTime = LocalTime .of (9 , 00 ).toSecondOfDay ();
89
93
return this ;
90
94
}
91
95
92
- public GridSinglePointTaskBuilder departureTimeWindow (int startHour , int startMinute , int durationMinutes ) {
96
+ public GridRegionalTaskBuilder departureTimeWindow (int startHour , int startMinute , int durationMinutes ) {
93
97
task .fromTime = LocalTime .of (startHour , startMinute ).toSecondOfDay ();
94
98
task .toTime = LocalTime .of (startHour , startMinute + durationMinutes ).toSecondOfDay ();
95
99
return this ;
96
100
}
97
101
98
- public GridSinglePointTaskBuilder maxRides (int rides ) {
102
+ public GridRegionalTaskBuilder maxRides (int rides ) {
99
103
task .maxRides = rides ;
100
104
return this ;
101
105
}
@@ -105,7 +109,7 @@ public GridSinglePointTaskBuilder maxRides(int rides) {
105
109
* Increasing the number of draws will yield a better approximation of the true travel time distribution
106
110
* (while making the tests run slower).
107
111
*/
108
- public GridSinglePointTaskBuilder monteCarloDraws (int draws ) {
112
+ public GridRegionalTaskBuilder monteCarloDraws (int draws ) {
109
113
task .monteCarloDraws = draws ;
110
114
return this ;
111
115
}
@@ -120,7 +124,7 @@ public GridSinglePointTaskBuilder monteCarloDraws (int draws) {
120
124
* web Mercator grid pixels. Using a single measurement point also greatly reduces the amount of travel time
121
125
* histograms that must be computed and retained, improving the memory and run time cost of tests.
122
126
*/
123
- public GridSinglePointTaskBuilder singleFreeformDestination (int x , int y ) {
127
+ public GridRegionalTaskBuilder singleFreeformDestination (int x , int y ) {
124
128
FreeFormPointSet ps = new FreeFormPointSet (gridLayout .getIntersectionLatLon (x , y ));
125
129
// Downstream code expects to see the same number of keys and PointSet objects so initialize both.
126
130
task .destinationPointSetKeys = new String [] { "POINT_SET" };
0 commit comments