@@ -93,23 +93,13 @@ public void buildGraph() {
93
93
timetableRepository .index ();
94
94
95
95
/* The linker will use streets if they are available, or straight-line distance otherwise. */
96
- NearbyStopFinder nearbyStopFinder = createNearbyStopFinder (
97
- defaultMaxTransferDuration ,
98
- Set .of ()
99
- );
96
+ NearbyStopFinder nearbyStopFinder = createNearbyStopFinder (defaultMaxTransferDuration );
100
97
HashMap <StreetMode , NearbyStopFinder > defaultNearbyStopFinders = new HashMap <>();
101
98
/* These are used for calculating transfers only between carsAllowedStops. */
102
99
HashMap <StreetMode , NearbyStopFinder > carsAllowedStopNearbyStopFinders = new HashMap <>();
103
100
104
101
List <TransitStopVertex > stops = graph .getVerticesOfType (TransitStopVertex .class );
105
- Set <TransitStopVertex > carsAllowedStops = timetableRepository
106
- .getStopLocationsUsedForCarsAllowedTrips ()
107
- .stream ()
108
- .map (StopLocation ::getId )
109
- .map (graph ::getStopVertexForStopId )
110
- // filter out null values if no TransitStopVertex is found for ID
111
- .filter (TransitStopVertex .class ::isInstance )
112
- .collect (Collectors .toSet ());
102
+ Set <StopLocation > carsAllowedStops = timetableRepository .getStopLocationsUsedForCarsAllowedTrips ();
113
103
114
104
LOG .info ("Creating transfers based on requests:" );
115
105
transferRequests .forEach (transferProfile -> LOG .info (transferProfile .toString ()));
@@ -147,8 +137,7 @@ public void buildGraph() {
147
137
flexTransferRequests ,
148
138
defaultNearbyStopFinders ,
149
139
carsAllowedStopNearbyStopFinders ,
150
- nearbyStopFinder ,
151
- carsAllowedStops
140
+ nearbyStopFinder
152
141
);
153
142
154
143
stops
@@ -169,14 +158,29 @@ public void buildGraph() {
169
158
// Calculate default transfers.
170
159
for (RouteRequest transferProfile : defaultTransferRequests ) {
171
160
StreetMode mode = transferProfile .journey ().transfer ().mode ();
172
- findNearbyStops (
173
- defaultNearbyStopFinders .get (mode ),
174
- ts0 ,
175
- transferProfile ,
176
- stop ,
177
- distinctTransfers ,
178
- mode
179
- );
161
+ for (NearbyStop sd : defaultNearbyStopFinders
162
+ .get (mode )
163
+ .findNearbyStops (ts0 , transferProfile , transferProfile .journey ().transfer (), false )) {
164
+ // Skip the origin stop, loop transfers are not needed.
165
+ if (sd .stop == stop ) {
166
+ continue ;
167
+ }
168
+ if (sd .stop .transfersNotAllowed ()) {
169
+ continue ;
170
+ }
171
+ TransferKey transferKey = new TransferKey (stop , sd .stop , sd .edges );
172
+ PathTransfer pathTransfer = distinctTransfers .get (transferKey );
173
+ if (pathTransfer == null ) {
174
+ // If the PathTransfer can't be found, it is created.
175
+ distinctTransfers .put (
176
+ transferKey ,
177
+ new PathTransfer (stop , sd .stop , sd .distance , sd .edges , EnumSet .of (mode ))
178
+ );
179
+ } else {
180
+ // If the PathTransfer is found, a new PathTransfer with the added mode is created.
181
+ distinctTransfers .put (transferKey , pathTransfer .withAddedMode (mode ));
182
+ }
183
+ }
180
184
}
181
185
// Calculate flex transfers if flex routing is enabled.
182
186
for (RouteRequest transferProfile : flexTransferRequests ) {
@@ -210,17 +214,36 @@ public void buildGraph() {
210
214
}
211
215
}
212
216
// Calculate transfers between stops that can use trips with cars if configured.
213
- if (carsAllowedStops .contains (ts0 )) {
217
+ if (carsAllowedStops .contains (stop )) {
214
218
for (RouteRequest transferProfile : carsAllowedStopTransferRequests ) {
215
219
StreetMode mode = transferProfile .journey ().transfer ().mode ();
216
- findNearbyStops (
217
- carsAllowedStopNearbyStopFinders .get (mode ),
218
- ts0 ,
219
- transferProfile ,
220
- stop ,
221
- distinctTransfers ,
222
- mode
223
- );
220
+ for (NearbyStop sd : carsAllowedStopNearbyStopFinders
221
+ .get (mode )
222
+ .findNearbyStops (ts0 , transferProfile , transferProfile .journey ().transfer (), false )) {
223
+ // Skip the origin stop, loop transfers are not needed.
224
+ if (sd .stop == stop ) {
225
+ continue ;
226
+ }
227
+ if (sd .stop .transfersNotAllowed ()) {
228
+ continue ;
229
+ }
230
+ // Only calculate transfers between carsAllowedStops.
231
+ if (!carsAllowedStops .contains (sd .stop )) {
232
+ continue ;
233
+ }
234
+ TransferKey transferKey = new TransferKey (stop , sd .stop , sd .edges );
235
+ PathTransfer pathTransfer = distinctTransfers .get (transferKey );
236
+ if (pathTransfer == null ) {
237
+ // If the PathTransfer can't be found, it is created.
238
+ distinctTransfers .put (
239
+ transferKey ,
240
+ new PathTransfer (stop , sd .stop , sd .distance , sd .edges , EnumSet .of (mode ))
241
+ );
242
+ } else {
243
+ // If the PathTransfer is found, a new PathTransfer with the added mode is created.
244
+ distinctTransfers .put (transferKey , pathTransfer .withAddedMode (mode ));
245
+ }
246
+ }
224
247
}
225
248
}
226
249
@@ -270,10 +293,7 @@ public void buildGraph() {
270
293
* whether the graph has a street network and if ConsiderPatternsForDirectTransfers feature is
271
294
* enabled.
272
295
*/
273
- private NearbyStopFinder createNearbyStopFinder (
274
- Duration radiusByDuration ,
275
- Set <Vertex > findOnlyVertices
276
- ) {
296
+ private NearbyStopFinder createNearbyStopFinder (Duration radiusByDuration ) {
277
297
var transitService = new DefaultTransitService (timetableRepository );
278
298
NearbyStopFinder finder ;
279
299
if (!graph .hasStreets ) {
@@ -283,7 +303,7 @@ private NearbyStopFinder createNearbyStopFinder(
283
303
finder = new StraightLineNearbyStopFinder (transitService , radiusByDuration );
284
304
} else {
285
305
LOG .info ("Creating direct transfer edges between stops using the street network from OSM..." );
286
- finder = new StreetNearbyStopFinder (radiusByDuration , 0 , null , Set .of (), findOnlyVertices );
306
+ finder = new StreetNearbyStopFinder (radiusByDuration , 0 , null , Set .of ());
287
307
}
288
308
289
309
if (OTPFeature .ConsiderPatternsForDirectTransfers .isOn ()) {
@@ -299,8 +319,7 @@ private void parseTransferParameters(
299
319
List <RouteRequest > flexTransferRequests ,
300
320
HashMap <StreetMode , NearbyStopFinder > defaultNearbyStopFinders ,
301
321
HashMap <StreetMode , NearbyStopFinder > carsAllowedStopNearbyStopFinders ,
302
- NearbyStopFinder nearbyStopFinder ,
303
- Set <TransitStopVertex > carsAllowedStops
322
+ NearbyStopFinder nearbyStopFinder
304
323
) {
305
324
for (RouteRequest transferProfile : transferRequests ) {
306
325
StreetMode mode = transferProfile .journey ().transfer ().mode ();
@@ -313,10 +332,7 @@ private void parseTransferParameters(
313
332
// Set mode-specific maxTransferDuration, if it is set in the build config.
314
333
Duration maxTransferDuration = transferParameters .maxTransferDuration ();
315
334
if (maxTransferDuration != Duration .ZERO ) {
316
- defaultNearbyStopFinders .put (
317
- mode ,
318
- createNearbyStopFinder (maxTransferDuration , Set .of ())
319
- );
335
+ defaultNearbyStopFinders .put (mode , createNearbyStopFinder (maxTransferDuration ));
320
336
} else {
321
337
defaultNearbyStopFinders .put (mode , nearbyStopFinder );
322
338
}
@@ -327,10 +343,7 @@ private void parseTransferParameters(
327
343
carsAllowedStopTransferRequests .add (transferProfile );
328
344
carsAllowedStopNearbyStopFinders .put (
329
345
mode ,
330
- createNearbyStopFinder (
331
- carsAllowedStopMaxTransferDuration ,
332
- Collections .<Vertex >unmodifiableSet (carsAllowedStops )
333
- )
346
+ createNearbyStopFinder (carsAllowedStopMaxTransferDuration )
334
347
);
335
348
}
336
349
} else {
@@ -350,41 +363,5 @@ private void parseTransferParameters(
350
363
}
351
364
}
352
365
353
- private void findNearbyStops (
354
- NearbyStopFinder nearbyStopFinder ,
355
- TransitStopVertex ts0 ,
356
- RouteRequest transferProfile ,
357
- RegularStop stop ,
358
- Map <TransferKey , PathTransfer > distinctTransfers ,
359
- StreetMode mode
360
- ) {
361
- for (NearbyStop sd : nearbyStopFinder .findNearbyStops (
362
- ts0 ,
363
- transferProfile ,
364
- transferProfile .journey ().transfer (),
365
- false
366
- )) {
367
- // Skip the origin stop, loop transfers are not needed.
368
- if (sd .stop == stop ) {
369
- continue ;
370
- }
371
- if (sd .stop .transfersNotAllowed ()) {
372
- continue ;
373
- }
374
- TransferKey transferKey = new TransferKey (stop , sd .stop , sd .edges );
375
- PathTransfer pathTransfer = distinctTransfers .get (transferKey );
376
- if (pathTransfer == null ) {
377
- // If the PathTransfer can't be found, it is created.
378
- distinctTransfers .put (
379
- transferKey ,
380
- new PathTransfer (stop , sd .stop , sd .distance , sd .edges , EnumSet .of (mode ))
381
- );
382
- } else {
383
- // If the PathTransfer is found, a new PathTransfer with the added mode is created.
384
- distinctTransfers .put (transferKey , pathTransfer .withAddedMode (mode ));
385
- }
386
- }
387
- }
388
-
389
366
private record TransferKey (StopLocation source , StopLocation target , List <Edge > edges ) {}
390
367
}
0 commit comments